Skip to content

Commit

Permalink
added Array<unsigned int>, Array<long long> and Array<char>
Browse files Browse the repository at this point in the history
  • Loading branch information
sshiraiwa committed Jan 9, 2024
1 parent a009ffb commit 896d38b
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 94 deletions.
35 changes: 34 additions & 1 deletion mfem/_par/array.i
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,43 @@ namespace mfem{
%template(doubleSwap) Swap<double>;
%template(intSwap) Swap<int>;
}

/*
Instantiation of Array templates.
We instantiate some common use cases. Array.cpp instantiate these specialization.
template class Array<char>;
template class Array<int>;
template class Array<long long>;
template class Array<double>;
template class Array2D<int>;
template class Array2D<double>;
*/

%import "../common/array_instantiation_macro.i"
INSTANTIATE_ARRAY_INT
INSTANTIATE_ARRAY_DOUBLE
IGNORE_ARRAY_METHODS(bool)
INSTANTIATE_ARRAY_NUMPYARRAY(int8, char, NPY_BYTE) // 8bit
INSTANTIATE_ARRAY_NUMPYARRAY(int64, long long, NPY_LONGLONG) // 64bit

/*
For other classes, we need to ignore some methods
To ignore methos defined in Array.cpp, we use
IGNORE_ARRAY_METHODS_PREMITIVE
In more genral object, we need to futher ignore methods which uses comparision (> or == operators).
IGNORE_ARRAY_METHODS
*/

IGNORE_ARRAY_METHODS_PREMITIVE(bool)
INSTANTIATE_ARRAY_BOOL
IGNORE_ARRAY_METHODS_PREMITIVE(unsigned int)
INSTANTIATE_ARRAY_NUMPYARRAY(uint, unsigned int, NPY_UINT) // 32bit

/*
for these Array2D, we instantiate it. But we dont extend it since, Array2D<T> does not
expose the interanl pointer to array1d.
*/
%template(intArray2D) mfem::Array2D<int>;
%template(doubleArray2D) mfem::Array2D<double>;

37 changes: 35 additions & 2 deletions mfem/_ser/array.i
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ XXXPTR_SIZE_IN(bool *data_, int asize, bool)
%pythonappend mfem::Array::Array %{
if len(args) == 1 and isinstance(args[0], list):
if (len(args[0]) == 2 and hasattr(args[0][0], 'disown') and
not hasattr(args[0][1], 'disown')):
not hasattr(args[0][1], 'disown')):
## first element is SwigObject, like <Swig Object of type 'int *'>
## We do not own data in this case.
pass
Expand Down Expand Up @@ -147,8 +147,41 @@ namespace mfem{
%template(intSwap) Swap<int>;
}

/*
Instantiation of Array templates.
We instantiate some common use cases. Array.cpp instantiate these specialization.
template class Array<char>;
template class Array<int>;
template class Array<long long>;
template class Array<double>;
template class Array2D<int>;
template class Array2D<double>;
*/

%import "../common/array_instantiation_macro.i"
INSTANTIATE_ARRAY_INT
INSTANTIATE_ARRAY_DOUBLE
IGNORE_ARRAY_METHODS(bool)
INSTANTIATE_ARRAY_NUMPYARRAY(int8, char, NPY_BYTE) // for 8bit data
INSTANTIATE_ARRAY_NUMPYARRAY(int64, long long, NPY_LONGLONG) // 64bit

/*
For other classes, we need to ignore some methods
To ignore methos defined in Array.cpp, we use
IGNORE_ARRAY_METHODS_PREMITIVE
In more genral object, we need to futher ignore methods which uses comparision (> or == operators).
IGNORE_ARRAY_METHODS
*/

IGNORE_ARRAY_METHODS_PREMITIVE(bool)
INSTANTIATE_ARRAY_BOOL
IGNORE_ARRAY_METHODS_PREMITIVE(unsigned int)
INSTANTIATE_ARRAY_NUMPYARRAY(uint, unsigned int, NPY_UINT) // 32bit

/*
for these Array2D, we instantiate it. But we dont extend it since, Array2D<T> does not
expose the interanl pointer to array1d.
*/
%template(intArray2D) mfem::Array2D<int>;
%template(doubleArray2D) mfem::Array2D<double>;
1 change: 1 addition & 0 deletions mfem/_ser/gslib.i
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import_array();
%include "exception.i"
%include "../common/typemap_macros.i"
%include "../common/exception.i"
%import array.i
%import vector.i
%import mesh.i
%import gridfunc.i
Expand Down
Loading

0 comments on commit 896d38b

Please sign in to comment.