Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add long long to user parameters #74

Merged
merged 2 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions doc/SetCodeSpecificParameter.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Set Code or User Specific Parameter
## yt\_set\_UserParameter*
```cpp
int yt_set_UserParameterInt ( const char *key, const int n, const int *input );
int yt_set_UserParameterLong ( const char *key, const int n, const long *input );
int yt_set_UserParameterUint ( const char *key, const int n, const uint *input );
int yt_set_UserParameterUlong ( const char *key, const int n, const ulong *input );
int yt_set_UserParameterFloat ( const char *key, const int n, const float *input );
int yt_set_UserParameterDouble( const char *key, const int n, const double *input );
int yt_set_UserParameterString( const char *key, const char *input );
int yt_set_UserParameterInt ( const char *key, const int n, const int *input );
int yt_set_UserParameterLong ( const char *key, const int n, const long *input );
int yt_set_UserParameterLongLong ( const char *key, const int n, const long long *input );
int yt_set_UserParameterUint ( const char *key, const int n, const uint *input );
int yt_set_UserParameterUlong ( const char *key, const int n, const ulong *input );
int yt_set_UserParameterFloat ( const char *key, const int n, const float *input );
int yt_set_UserParameterDouble ( const char *key, const int n, const double *input );
int yt_set_UserParameterString ( const char *key, const char *input );
```
- Usage: Add code or user specific parameters that is used in your input yt [`frontend`](./SetYTParameter.md#yt_param_yt) `XXXDataset` class, since `libyt` will borrow field information (`class XXXFieldInfo`) from it. `libyt` will add them to `libytDataset` class as new attributes.
- Return: `YT_SUCCESS` or `YT_FAIL`
Expand Down
15 changes: 8 additions & 7 deletions include/libyt.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ int yt_set_Parameters ( yt_param_yt *param_yt );
int yt_get_FieldsPtr ( yt_field **field_list );
int yt_get_ParticlesPtr( yt_particle **particle_list );
int yt_get_GridsPtr ( yt_grid **grids_local );
int yt_set_UserParameterInt ( const char *key, const int n, const int *input );
int yt_set_UserParameterLong ( const char *key, const int n, const long *input );
int yt_set_UserParameterUint ( const char *key, const int n, const uint *input );
int yt_set_UserParameterUlong ( const char *key, const int n, const ulong *input );
int yt_set_UserParameterFloat ( const char *key, const int n, const float *input );
int yt_set_UserParameterDouble( const char *key, const int n, const double *input );
int yt_set_UserParameterString( const char *key, const char *input );
int yt_set_UserParameterInt ( const char *key, const int n, const int *input );
int yt_set_UserParameterLong ( const char *key, const int n, const long *input );
int yt_set_UserParameterLongLong( const char *key, const int n, const long long *input );
int yt_set_UserParameterUint ( const char *key, const int n, const uint *input );
int yt_set_UserParameterUlong ( const char *key, const int n, const ulong *input );
int yt_set_UserParameterFloat ( const char *key, const int n, const float *input );
int yt_set_UserParameterDouble ( const char *key, const int n, const double *input );
int yt_set_UserParameterString ( const char *key, const char *input );
int yt_commit();
int yt_free();
int yt_run_FunctionArguments( const char *function_name, int argc, ... );
Expand Down
41 changes: 26 additions & 15 deletions src/add_dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ int add_dict_scalar( PyObject *dict, const char *key, const T value )
typeid(T) == typeid(uint) || typeid(T) == typeid(ulong) )
py_obj = PyLong_FromLong( (long)value );

else if ( typeid(T) == typeid(long long) )
py_obj = PyLong_FromLongLong( (long long)value);

else
YT_ABORT( "Unsupported data type (only support float, double, int, long, unit, ulong)!\n" );
YT_ABORT( "Unsupported data type (only support float, double, int, long, long long, uint, ulong)!\n" );


// insert "value" into "dict" with "key"
Expand Down Expand Up @@ -97,8 +100,14 @@ int add_dict_vector3( PyObject *dict, const char *key, const T *vector )
element[v] = PyLong_FromLong( (long)vector[v] );
}

else if ( typeid(T) == typeid(long long) )
{
for (int v=0; v<VecSize; v++)
element[v] = PyLong_FromLongLong( (long long)vector[v] );
}

else
YT_ABORT( "Unsupported data type (only support float, double, int, long, unit, ulong)!\n" );
YT_ABORT( "Unsupported data type (only support float, double, int, long, long long, uint, ulong)!\n" );


// create a tuple object
Expand Down Expand Up @@ -161,19 +170,21 @@ int add_dict_string( PyObject *dict, const char *key, const char *string )


// explicit template instantiation
template int add_dict_scalar <float > ( PyObject *dict, const char *key, const float value );
template int add_dict_scalar <double> ( PyObject *dict, const char *key, const double value );
template int add_dict_scalar <int > ( PyObject *dict, const char *key, const int value );
template int add_dict_scalar <long > ( PyObject *dict, const char *key, const long value );
template int add_dict_scalar <uint > ( PyObject *dict, const char *key, const uint value );
template int add_dict_scalar <ulong > ( PyObject *dict, const char *key, const ulong value );

template int add_dict_vector3 <float > ( PyObject *dict, const char *key, const float *vector );
template int add_dict_vector3 <double> ( PyObject *dict, const char *key, const double *vector );
template int add_dict_vector3 <int > ( PyObject *dict, const char *key, const int *vector );
template int add_dict_vector3 <long > ( PyObject *dict, const char *key, const long *vector );
template int add_dict_vector3 <uint > ( PyObject *dict, const char *key, const uint *vector );
template int add_dict_vector3 <ulong > ( PyObject *dict, const char *key, const ulong *vector );
template int add_dict_scalar <float > ( PyObject *dict, const char *key, const float value );
template int add_dict_scalar <double > ( PyObject *dict, const char *key, const double value );
template int add_dict_scalar <int > ( PyObject *dict, const char *key, const int value );
template int add_dict_scalar <long > ( PyObject *dict, const char *key, const long value );
template int add_dict_scalar <long long > ( PyObject *dict, const char *key, const long long value );
template int add_dict_scalar <uint > ( PyObject *dict, const char *key, const uint value );
template int add_dict_scalar <ulong > ( PyObject *dict, const char *key, const ulong value );

template int add_dict_vector3 <float > ( PyObject *dict, const char *key, const float *vector );
template int add_dict_vector3 <double > ( PyObject *dict, const char *key, const double *vector );
template int add_dict_vector3 <int > ( PyObject *dict, const char *key, const int *vector );
template int add_dict_vector3 <long > ( PyObject *dict, const char *key, const long *vector );
template int add_dict_vector3 <long long> ( PyObject *dict, const char *key, const long long *vector );
template int add_dict_vector3 <uint > ( PyObject *dict, const char *key, const uint *vector );
template int add_dict_vector3 <ulong > ( PyObject *dict, const char *key, const ulong *vector );

//-------------------------------------------------------------------------------------------------------
// Function : add_dict_field_list
Expand Down
20 changes: 11 additions & 9 deletions src/yt_set_UserParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ static const int MaxParamNameWidth = 15;
// Return : YT_SUCCESS or YT_FAIL
//-------------------------------------------------------------------------------------------------------

int yt_set_UserParameterInt ( const char *key, const int n, const int *input ) { return add_nonstring( key, n, input ); }
int yt_set_UserParameterLong ( const char *key, const int n, const long *input ) { return add_nonstring( key, n, input ); }
int yt_set_UserParameterUint ( const char *key, const int n, const uint *input ) { return add_nonstring( key, n, input ); }
int yt_set_UserParameterUlong ( const char *key, const int n, const ulong *input ) { return add_nonstring( key, n, input ); }
int yt_set_UserParameterFloat ( const char *key, const int n, const float *input ) { return add_nonstring( key, n, input ); }
int yt_set_UserParameterDouble( const char *key, const int n, const double *input ) { return add_nonstring( key, n, input ); }
int yt_set_UserParameterString( const char *key, const char *input ) { return add_string ( key, input ); }
int yt_set_UserParameterInt ( const char *key, const int n, const int *input ) { return add_nonstring( key, n, input ); }
int yt_set_UserParameterLong ( const char *key, const int n, const long *input ) { return add_nonstring( key, n, input ); }
int yt_set_UserParameterLongLong( const char *key, const int n, const long long *input ) { return add_nonstring( key, n, input ); }
int yt_set_UserParameterUint ( const char *key, const int n, const uint *input ) { return add_nonstring( key, n, input ); }
int yt_set_UserParameterUlong ( const char *key, const int n, const ulong *input ) { return add_nonstring( key, n, input ); }
int yt_set_UserParameterFloat ( const char *key, const int n, const float *input ) { return add_nonstring( key, n, input ); }
int yt_set_UserParameterDouble ( const char *key, const int n, const double *input ) { return add_nonstring( key, n, input ); }
int yt_set_UserParameterString ( const char *key, const char *input ) { return add_string ( key, input ); }



Expand All @@ -56,7 +57,8 @@ static int add_nonstring( const char *key, const int n, const T *input )
// export data to libyt.param_user
if ( typeid(T) == typeid(float) || typeid(T) == typeid(double) ||
typeid(T) == typeid( int) || typeid(T) == typeid( long) ||
typeid(T) == typeid( uint) || typeid(T) == typeid( ulong) )
typeid(T) == typeid( uint) || typeid(T) == typeid( ulong) ||
typeid(T) == typeid(long long) )
{
// scalar and 3-element array
if ( n == 1 ) { if ( add_dict_scalar ( g_py_param_user, key, *input ) == YT_FAIL ) return YT_FAIL; }
Expand All @@ -67,7 +69,7 @@ static int add_nonstring( const char *key, const int n, const T *input )
}

else
YT_ABORT( "Unsupported data type (only support char*, float*, double*, int*, long*, unit*, ulong*)!\n" );
YT_ABORT( "Unsupported data type (only support char*, float*, double*, int*, long*, long long*, uint*, ulong*)!\n" );



Expand Down