From 5e81cd51d7754f25a01584e51bb653befa295621 Mon Sep 17 00:00:00 2001 From: Syun'ichi Shiraiwa Date: Sat, 5 Oct 2024 11:17:23 -0400 Subject: [PATCH] Fixed the name of wrapped Array2D object names --- mfem/_par/array.i | 6 ++--- mfem/_ser/array.i | 8 ++---- mfem/common/array_instantiation_macro.i | 3 ++- mfem/common/array_setitem_typemap.i | 36 ------------------------- test/test_coefficient.py | 29 ++++++++++---------- test/test_intrules.py | 6 ++--- test/test_vector.py | 2 +- 7 files changed, 26 insertions(+), 64 deletions(-) delete mode 100644 mfem/common/array_setitem_typemap.i diff --git a/mfem/_par/array.i b/mfem/_par/array.i index 19330454..633aea48 100644 --- a/mfem/_par/array.i +++ b/mfem/_par/array.i @@ -224,7 +224,7 @@ IGNORE_ARRAY_METHODS(mfem::DenseMatrix *) IGNORE_ARRAY_METHODS(mfem::SparseMatrix *) IGNORE_ARRAY_METHODS(mfem::HypreParMatrix *) -%template(densematArray2D) mfem::Array2D; -%template(sparsematArray2D) mfem::Array2D; -%template(hypreparmatArray2D) mfem::Array2D; +%template(DenseMatrixArray2D) mfem::Array2D; +%template(SparseMatrixArray2D) mfem::Array2D; +%template(HypreParMatrixArray2D) mfem::Array2D; diff --git a/mfem/_ser/array.i b/mfem/_ser/array.i index 51d42845..64bf6f4c 100644 --- a/mfem/_ser/array.i +++ b/mfem/_ser/array.i @@ -235,9 +235,5 @@ INSTANTIATE_ARRAY2(Array *, Array, intArray, 1) IGNORE_ARRAY_METHODS(mfem::DenseMatrix *) IGNORE_ARRAY_METHODS(mfem::SparseMatrix *) -%template(densematArray2D) mfem::Array2D; -%template(sparsematArray2D) mfem::Array2D; -//%template(hypreparmatArray2D) mfem::Array2D; - - - +%template(DenseMatrixArray2D) mfem::Array2D; +%template(SparseMatrixArray2D) mfem::Array2D; diff --git a/mfem/common/array_instantiation_macro.i b/mfem/common/array_instantiation_macro.i index c684e8dd..7d4d4627 100644 --- a/mfem/common/array_instantiation_macro.i +++ b/mfem/common/array_instantiation_macro.i @@ -1,6 +1,7 @@ %define INSTANTIATE_ARRAY2(XXX, YYY, ZZZ, USEPTR) #if USEPTR == 1 -%template(##ZZZ##Ptr##Array) mfem::Array; + //%template(##ZZZ##Ptr##Array) mfem::Array; +%template(##ZZZ##Array) mfem::Array; #else %template(##ZZZ##Array) mfem::Array; #endif diff --git a/mfem/common/array_setitem_typemap.i b/mfem/common/array_setitem_typemap.i deleted file mode 100644 index 5ae2bb98..00000000 --- a/mfem/common/array_setitem_typemap.i +++ /dev/null @@ -1,36 +0,0 @@ -// -// this typemap is used together with %extend, which -// adds a class member taking int *pymfem_size -// -%define ARRAY_SETITEM(T) - %typemap(in) (int i, const T v) { - // generated by ARRAY_LISTTUPLE_INPUT(XXX, YYY) - if (!PyList_Check($input)) { - if (!PyTuple_Check($input)) { - PyErr_SetString(PyExc_ValueError, "Expecting a list/tuple"); - return NULL; - } else { - is_tuple = true; - } - } - size = (is_tuple) ? PyTuple_Size($input) : PyList_Size($input); - $1 = (void *) & size; -} - -%typemap(argout) (void *List_or_Tuple, XXX *_unused ) { - for (int i = 0; i < size$argnum; i++) { - PyObject *s = (is_tuple$argnum) ? PyTuple_GetItem($input, i) : PyList_GetItem($input,i); - (* result)[i] = (XXX)YYY(s); - } -} - -%typemap(typecheck) (void *List_or_Tuple, XXX *_unused ) { - $1 = 0; - if (PyList_Check($input)){ - $1 = 1; - } - if (PyTuple_Check($input)){ - $1 = 1; - } -} -%enddef diff --git a/test/test_coefficient.py b/test/test_coefficient.py index 5dae8105..65204227 100644 --- a/test/test_coefficient.py +++ b/test/test_coefficient.py @@ -20,47 +20,48 @@ def test(): dim = 3 max_attr = 5 - sigma_attr_coefs = mfem.MatrixCoefficientPtrArray(max_attr) + sigma_attr_coefs = mfem.MatrixCoefficientArray(max_attr) sigma_attr = mfem.intArray(max_attr) + tensors = [mfem.DenseMatrix(np.ones((3,3))*i) for i in range(max_attr)] tensor_coefs = [mfem.MatrixConstantCoefficient(mat) for mat in tensors] - + sigma_array = mfem.MatrixCoefficientArray(tensor_coefs) + sigma_attr = mfem.intArray([1,2,3,4,5]) + sigmaCoef = mfem.PWMatrixCoefficient(dim, sigma_attr, sigma_array, False) + for ti, tensor in enumerate(tensors): # add matrix coefficient to list - print(ti) xx = mfem.MatrixConstantCoefficient(tensor) sigma_attr_coefs[ti] = xx sigma_attr[ti] = ti+1 - # Create PW Matrix Coefficient sigmaCoef = mfem.PWMatrixCoefficient(dim, sigma_attr, sigma_attr_coefs, False) - sigmaCoef = mfem.PWMatrixCoefficient(dim, sigma_attr, tensor_coefs, False) - tensor_coefs = mfem.MatrixCoefficientPtrArray([mfem.MatrixConstantCoefficient(mat) for mat in tensors]) + sigmaCoef = mfem.PWMatrixCoefficient(dim, sigma_attr, tensor_coefs, False) + tensor_coefs = mfem.MatrixCoefficientArray([mfem.MatrixConstantCoefficient(mat) for mat in tensors]) sigmaCoef = mfem.PWMatrixCoefficient(dim, sigma_attr, tensor_coefs, False) data = tensor_coefs.GetData() - tensor_coefs2 = mfem.MatrixCoefficientPtrArray(data, 5, False) + tensor_coefs2 = mfem.MatrixCoefficientArray(data, 5, False) sigmaCoef = mfem.PWMatrixCoefficient(dim, sigma_attr, tensor_coefs2, False) print("exiting") - - - if __name__ == '__main__': import tracemalloc - + tracemalloc.start() - for i in range(10): + print(tracemalloc.get_traced_memory()) + + for i in range(3000): test() - print(tracemalloc.get_traced_memory()) + print(tracemalloc.get_traced_memory()) snapshot = tracemalloc.take_snapshot() - top_stats = snapshot.statistics('lineno') + top_stats = snapshot.statistics('lineno') for stat in top_stats[:10]: print(stat) diff --git a/test/test_intrules.py b/test/test_intrules.py index 542d027e..a1692fc2 100644 --- a/test/test_intrules.py +++ b/test/test_intrules.py @@ -52,13 +52,13 @@ def run_test(): irs = [mfem.IntRules.Get(i, 2) for i in range(mfem.Geometry.NumGeom)] - rulearray = mfem.IntegrationRulePtrArray(irs) + rulearray = mfem.IntegrationRuleArray(irs) ir2 = rulearray[2] points3 = [(ir2[i].x, ir2[i].y) for i in range(ir2.GetNPoints())] assert (points3 == points), "IntegrationPointArray coords does not agree (check 2)." - # check slice of IntegrationRulePtrArray + # check slice of IntegrationRuleArray rulearray2 = rulearray[:5] assert not rulearray2.OwnsData(), "subarray should not own data" ir2 = rulearray2[2] @@ -67,7 +67,7 @@ def run_test(): # create it from a pointer array data = rulearray2.GetData() # this returns - rulearray3 = mfem.IntegrationRulePtrArray((data, 5)) + rulearray3 = mfem.IntegrationRuleArray((data, 5)) ir2 = rulearray3[2] points3 = [(ir2[i].x, ir2[i].y) for i in range(ir2.GetNPoints())] assert (points3 == points), "IntegrationPointArray coords does not agree (check 3)." diff --git a/test/test_vector.py b/test/test_vector.py index 3fc69f98..99ab1c3f 100644 --- a/test/test_vector.py +++ b/test/test_vector.py @@ -29,7 +29,7 @@ def run_test(): a.Print_HYPRE("vector_hypre.dat") - x = mfem.VectorPtrArray([a]*3) + x = mfem.VectorArray([a]*3) x[2].Print() if __name__=='__main__':