From e45d89641d43ca77b0f054474e500ac40586884d Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Fri, 16 Feb 2024 12:59:40 +0530 Subject: [PATCH 01/28] fix(tests): nose deprecation followed this: https://docs.pytest.org/en/stable/deprecations.html#support-for-tests-written-for-nose --- pysph/base/tests/test_device_helper.py | 40 +++++++++++++------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/pysph/base/tests/test_device_helper.py b/pysph/base/tests/test_device_helper.py index d0e230e69..b2ee24f91 100644 --- a/pysph/base/tests/test_device_helper.py +++ b/pysph/base/tests/test_device_helper.py @@ -27,13 +27,13 @@ def check_import(backend): class TestDeviceHelper(object): - def setup(self): + def setup_method(self): self.pa = get_particle_array(name='f', x=[0.0, 1.0], m=1.0, rho=2.0) @check_all_backends def test_simple(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -51,7 +51,7 @@ def test_simple(self, backend): @check_all_backends def test_push_correctly_sets_values_with_args(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -74,7 +74,7 @@ def test_push_correctly_sets_values_with_args(self, backend): @check_all_backends def test_push_correctly_sets_values_with_no_args(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -97,7 +97,7 @@ def test_push_correctly_sets_values_with_no_args(self, backend): @check_all_backends def test_pull_correctly_sets_values_with_args(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -120,7 +120,7 @@ def test_pull_correctly_sets_values_with_args(self, backend): @check_all_backends def test_pull_correctly_sets_values_with_no_args(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -143,7 +143,7 @@ def test_pull_correctly_sets_values_with_no_args(self, backend): @check_all_backends def test_max_provides_maximum(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given/When pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -154,7 +154,7 @@ def test_max_provides_maximum(self, backend): @check_all_backends def test_that_adding_removing_prop_to_array_updates_gpu(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -177,7 +177,7 @@ def test_that_adding_removing_prop_to_array_updates_gpu(self, backend): @check_all_backends def test_resize_works(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -211,7 +211,7 @@ def test_resize_works(self, backend): @check_all_backends def test_get_number_of_particles(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -231,7 +231,7 @@ def test_get_number_of_particles(self, backend): @check_all_backends def test_align(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa pa.add_property('force', stride=3) @@ -259,7 +259,7 @@ def test_align(self, backend): @check_all_backends def test_align_particles(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -279,7 +279,7 @@ def test_align_particles(self, backend): @check_all_backends def test_remove_particles(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -300,7 +300,7 @@ def test_remove_particles(self, backend): @check_all_backends def test_remove_tagged_particles(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -319,7 +319,7 @@ def test_remove_tagged_particles(self, backend): @check_all_backends def test_add_particles(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -336,7 +336,7 @@ def test_add_particles(self, backend): @check_all_backends def test_extend(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -352,7 +352,7 @@ def test_extend(self, backend): @check_all_backends def test_append_parray(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa1 = self.pa pa2 = get_particle_array(name='s', x=[0.0, 1.0], m=1.0, rho=2.0) @@ -368,7 +368,7 @@ def test_append_parray(self, backend): @check_all_backends def test_empty_clone(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = get_particle_array(name='f', x=[0.0, 1.0, 2.0, 3.0], m=1.0, rho=2.0) @@ -385,7 +385,7 @@ def test_empty_clone(self, backend): @check_all_backends def test_extract_particles(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = get_particle_array(name='f', x=[0.0, 1.0, 2.0, 3.0], m=1.0, rho=2.0) @@ -405,7 +405,7 @@ def test_extract_particles(self, backend): def test_update_minmax_cl(self): backend = 'opencl' check_import(backend) - self.setup() + self.setup_method() # Given x = [0.0, -1.0, 2.0, 3.0] From 7149b86162e67bc8887fa0d45063c388672355c1 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:22:58 +0530 Subject: [PATCH 02/28] ci(gha): update cache action --- .github/workflows/tests.yml | 2 +- .github/workflows/zoltan-tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 74fefe20c..e060e9429 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -52,7 +52,7 @@ jobs: id: month run: echo "month==$(date +'%m')" >> $GITHUB_OUTPUT - name: Deal with auto-generated code cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.pysph diff --git a/.github/workflows/zoltan-tests.yml b/.github/workflows/zoltan-tests.yml index c947706a8..361a7adb4 100644 --- a/.github/workflows/zoltan-tests.yml +++ b/.github/workflows/zoltan-tests.yml @@ -55,7 +55,7 @@ jobs: id: month run: echo "month==$(date +'%m')" >> $GITHUB_OUTPUT - name: Deal with auto-generated code cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.pysph From 8f852073053291a401cd47d5f849bc7457386216 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:40:28 +0530 Subject: [PATCH 03/28] Revert "fix(tests): pin python<3.0" This reverts commit 2acb4ae48455806e59da51d2483938d69886df1d. --- .github/workflows/tests.yml | 2 +- .github/workflows/zoltan-tests.yml | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- setup.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e060e9429..853420fc2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,7 +39,7 @@ jobs: - name: Install dependencies run: | conda info - conda install -c conda-forge numpy 'cython<3.0' h5py + conda install -c conda-forge numpy cython h5py python -m pip install --upgrade pip setuptools wheel python -m pip install https://github.com/pypr/cyarray/zipball/master python -m pip install https://github.com/pypr/compyle/zipball/master diff --git a/.github/workflows/zoltan-tests.yml b/.github/workflows/zoltan-tests.yml index 361a7adb4..7fe2d7b25 100644 --- a/.github/workflows/zoltan-tests.yml +++ b/.github/workflows/zoltan-tests.yml @@ -40,7 +40,7 @@ jobs: - name: Install dependencies run: | conda info - conda install -c conda-forge numpy 'cython<3.0' + conda install -c conda-forge numpy cython python -m pip install --upgrade pip setuptools wheel python -m pip install mpi4py python -m pip install https://github.com/pypr/cyarray/zipball/master diff --git a/pyproject.toml b/pyproject.toml index 5aa017acc..ece6eb950 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [build-system] requires = [ "Beaker", - "Cython<3.0", + "Cython>=0.20", "compyle>=0.8", "cyarray", "mako", diff --git a/requirements.txt b/requirements.txt index 5426b1f9b..ccb71adfc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ numpy setuptools>=42.0.0 -Cython<3.0 +Cython>=0.20 cyarray compyle>=0.8 mako diff --git a/setup.py b/setup.py index ae13fc67f..9c528fc44 100644 --- a/setup.py +++ b/setup.py @@ -681,7 +681,7 @@ def setup_package(): # The requirements. install_requires = [ - 'numpy', 'mako', 'cyarray', 'compyle>=0.8', 'Cython<3.0', + 'numpy', 'mako', 'cyarray', 'compyle>=0.8', 'Cython>=0.20', 'setuptools>=42.0.0', 'pytools', 'Beaker' ] tests_require = ['pytest>=3.0', 'h5py', 'vtk'] From 83087644c3d6064464b90de61316d32dd8b3a73c Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:48:07 +0530 Subject: [PATCH 04/28] fix(point.pyx): cython numpy.int_t invalid type --- pysph/base/point.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pysph/base/point.pyx b/pysph/base/point.pyx index 8d8431c25..46dc9c0e8 100644 --- a/pysph/base/point.pyx +++ b/pysph/base/point.pyx @@ -234,8 +234,8 @@ cdef class IntPoint: return IntPoint_new(self.data.x, self.data.y, self.data.z) cpdef numpy.ndarray asarray(self): - cdef numpy.ndarray[ndim=1,dtype=numpy.int_t] arr = numpy.empty(3, - dtype=numpy.int) + cdef numpy.ndarray[ndim=1,dtype=int] arr = numpy.empty(3, + dtype=int) arr[0] = self.data.x arr[1] = self.data.y arr[2] = self.data.z From bcf2e8395d7cf9a203a812d222475926dc5a55e4 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sat, 17 Aug 2024 17:23:59 +0530 Subject: [PATCH 05/28] fix(perf): by adding noexcept --- pysph/base/box_sort_nnps.pyx | 2 +- pysph/base/cell_indexing_nnps.pxd | 16 ++++++++-------- pysph/base/cell_indexing_nnps.pyx | 16 ++++++++-------- pysph/base/linalg3.pxd | 10 +++++----- pysph/base/linalg3.pyx | 26 +++++++++++++------------- pysph/base/linked_list_nnps.pxd | 4 ++-- pysph/base/linked_list_nnps.pyx | 4 ++-- pysph/base/nnps_base.pxd | 24 ++++++++++++------------ pysph/base/nnps_base.pyx | 12 ++++++------ pysph/base/octree.pxd | 12 ++++++------ pysph/base/octree.pyx | 24 ++++++++++++------------ pysph/base/octree_nnps.pxd | 4 ++-- pysph/base/octree_nnps.pyx | 4 ++-- pysph/base/spatial_hash_nnps.pxd | 22 +++++++++++----------- pysph/base/spatial_hash_nnps.pyx | 16 ++++++++-------- pysph/base/stratified_hash_nnps.pxd | 20 ++++++++++---------- pysph/base/stratified_hash_nnps.pyx | 12 ++++++------ pysph/base/stratified_sfc_nnps.pxd | 12 ++++++------ pysph/base/stratified_sfc_nnps.pyx | 10 +++++----- pysph/base/z_order_nnps.pxd | 12 ++++++------ pysph/base/z_order_nnps.pyx | 14 +++++++------- 21 files changed, 138 insertions(+), 138 deletions(-) diff --git a/pysph/base/box_sort_nnps.pyx b/pysph/base/box_sort_nnps.pyx index ca1bfb259..65637d4b2 100644 --- a/pysph/base/box_sort_nnps.pyx +++ b/pysph/base/box_sort_nnps.pyx @@ -42,7 +42,7 @@ cdef class BoxSortNNPS(LinkedListNNPS): @cython.boundscheck(False) @cython.wraparound(False) cdef inline long _get_valid_cell_index(self, int cid_x, int cid_y, int cid_z, - int* ncells_per_dim, int dim, int n_cells) nogil: + int* ncells_per_dim, int dim, int n_cells) noexcept nogil: """Return the flattened index for a valid cell""" cdef long ncx = ncells_per_dim[0] cdef long ncy = ncells_per_dim[1] diff --git a/pysph/base/cell_indexing_nnps.pxd b/pysph/base/cell_indexing_nnps.pxd index bd68925d2..2ea50cf5e 100644 --- a/pysph/base/cell_indexing_nnps.pxd +++ b/pysph/base/cell_indexing_nnps.pxd @@ -33,22 +33,22 @@ cdef class CellIndexingNNPS(NNPS): ########################################################################## cdef inline u_int _get_key(self, u_int n, u_int i, u_int j, - u_int k, int pa_index) nogil + u_int k, int pa_index) noexcept nogil - cdef inline int _get_id(self, u_int key, int pa_index) nogil + cdef inline int _get_id(self, u_int key, int pa_index) noexcept nogil - cdef inline int _get_x(self, u_int key, int pa_index) nogil + cdef inline int _get_x(self, u_int key, int pa_index) noexcept nogil - cdef inline int _get_y(self, u_int key, int pa_index) nogil + cdef inline int _get_y(self, u_int key, int pa_index) noexcept nogil - cdef inline int _get_z(self, u_int key, int pa_index) nogil + cdef inline int _get_z(self, u_int key, int pa_index) noexcept nogil cdef inline int _neighbor_boxes(self, int i, int j, int k, - int* x, int* y, int* z) nogil + int* x, int* y, int* z) noexcept nogil cpdef set_context(self, int src_index, int dst_index) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil cpdef get_nearest_particles_no_cache(self, int src_index, int dst_index, size_t d_idx, UIntArray nbrs, bint prealloc) @@ -56,7 +56,7 @@ cdef class CellIndexingNNPS(NNPS): cpdef get_spatially_ordered_indices(self, int pa_index, LongArray indices) cdef void fill_array(self, NNPSParticleArrayWrapper pa_wrapper, int pa_index, - UIntArray indices, u_int* current_keys, key_to_idx_t* current_indices) nogil + UIntArray indices, u_int* current_keys, key_to_idx_t* current_indices) noexcept nogil cpdef _refresh(self) diff --git a/pysph/base/cell_indexing_nnps.pyx b/pysph/base/cell_indexing_nnps.pyx index bd6bf7f81..718edf959 100644 --- a/pysph/base/cell_indexing_nnps.pyx +++ b/pysph/base/cell_indexing_nnps.pyx @@ -109,7 +109,7 @@ cdef class CellIndexingNNPS(NNPS): self.dst = self.pa_wrappers[dst_index] self.src = self.pa_wrappers[src_index] - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -231,7 +231,7 @@ cdef class CellIndexingNNPS(NNPS): cdef void fill_array(self, NNPSParticleArrayWrapper pa_wrapper, int pa_index, - UIntArray indices, u_int* current_keys, key_to_idx_t* current_indices) nogil: + UIntArray indices, u_int* current_keys, key_to_idx_t* current_indices) noexcept nogil: cdef double* x_ptr = pa_wrapper.x.data cdef double* y_ptr = pa_wrapper.y.data cdef double* z_ptr = pa_wrapper.z.data @@ -295,30 +295,30 @@ cdef class CellIndexingNNPS(NNPS): #### Private protocol ################################################ cdef inline u_int _get_key(self, u_int n, u_int i, u_int j, - u_int k, int pa_index) nogil: + u_int k, int pa_index) noexcept nogil: return n + \ (1 << self.I[pa_index])*i + \ (1 << (self.I[pa_index] + self.J))*j + \ (1 << (self.I[pa_index] + self.J + self.K))*k @cython.cdivision(True) - cdef inline int _get_id(self, u_int key, int pa_index) nogil: + cdef inline int _get_id(self, u_int key, int pa_index) noexcept nogil: return key % (1 << self.I[pa_index]) @cython.cdivision(True) - cdef inline int _get_x(self, u_int key, int pa_index) nogil: + cdef inline int _get_x(self, u_int key, int pa_index) noexcept nogil: return (key >> self.I[pa_index]) % (1 << self.J) @cython.cdivision(True) - cdef inline int _get_y(self, u_int key, int pa_index) nogil: + cdef inline int _get_y(self, u_int key, int pa_index) noexcept nogil: return (key >> (self.I[pa_index] + self.J)) % (1 << self.K) @cython.cdivision(True) - cdef inline int _get_z(self, u_int key, int pa_index) nogil: + cdef inline int _get_z(self, u_int key, int pa_index) noexcept nogil: return key >> (self.I[pa_index] + self.J + self.K) cdef inline int _neighbor_boxes(self, int i, int j, int k, - int* x, int* y, int* z) nogil: + int* x, int* y, int* z) noexcept nogil: cdef int length = 0 cdef int p, q, r for p from -1<=p<2: diff --git a/pysph/base/linalg3.pxd b/pysph/base/linalg3.pxd index 66427d455..86d4cd8f2 100644 --- a/pysph/base/linalg3.pxd +++ b/pysph/base/linalg3.pxd @@ -3,11 +3,11 @@ """Routines for eigen decomposition of symmetric 3x3 matrices. """ -cdef double det(double a[3][3]) nogil -cdef void get_eigenvalues(double a[3][3], double *result) nogil -cdef void eigen_decomposition(double A[3][3], double V[3][3], double *d) nogil -cdef void transform(double A[3][3], double P[3][3], double res[3][3]) nogil -cdef void transform_diag(double *A, double P[3][3], double res[3][3]) nogil +cdef double det(double a[3][3]) noexcept nogil +cdef void get_eigenvalues(double a[3][3], double *result) noexcept nogil +cdef void eigen_decomposition(double A[3][3], double V[3][3], double *d) noexcept nogil +cdef void transform(double A[3][3], double P[3][3], double res[3][3]) noexcept nogil +cdef void transform_diag(double *A, double P[3][3], double res[3][3]) noexcept nogil cdef void transform_diag_inv(double *A, double P[3][3], double res[3][3]) nogil cdef void get_eigenvalvec(double A[3][3], double *R, double *e) diff --git a/pysph/base/linalg3.pyx b/pysph/base/linalg3.pyx index 5c4391f32..b8ba16378 100644 --- a/pysph/base/linalg3.pyx +++ b/pysph/base/linalg3.pyx @@ -20,17 +20,17 @@ cdef enum: cdef double EPS = numpy.finfo(float).eps -cdef inline double MAX(double a, double b) nogil: +cdef inline double MAX(double a, double b) noexcept nogil: return a if a>b else b -cdef inline double SQR(double a) nogil: +cdef inline double SQR(double a) noexcept nogil: return a*a -cdef inline double hypot2(double x, double y) nogil: +cdef inline double hypot2(double x, double y) noexcept nogil: return sqrt(x*x+y*y) -cdef double det(double a[3][3]) nogil: +cdef double det(double a[3][3]) noexcept nogil: '''Determinant of symmetrix matrix ''' return (a[0][0]*a[1][1]*a[2][2] + 2*a[1][2]*a[0][2]*a[0][1] - @@ -46,7 +46,7 @@ cpdef double py_det(double[:,:] m): # d:11,22,33; s:23,13,12 # d:00,11,22; s:12,02,01 -cdef void get_eigenvalues(double a[3][3], double *result) nogil: +cdef void get_eigenvalues(double a[3][3], double *result) noexcept nogil: '''Compute the eigenvalues of symmetric matrix a and return in result array. ''' @@ -143,7 +143,7 @@ cdef void get_eigenvec_from_val(double A[n][n], double *R, double *e): R[j*3+i] = res[j] -cdef bint _nearly_diagonal(double A[n][n]) nogil: +cdef bint _nearly_diagonal(double A[n][n]) noexcept nogil: return ( (SQR(A[0][0]) + SQR(A[1][1]) + SQR(A[2][2])) > 1e8*(SQR(A[0][1]) + SQR(A[0][2]) + SQR(A[1][2])) @@ -194,7 +194,7 @@ def py_get_eigenvalvec(double[:,:] A): ############################################################################## -cdef void transform(double A[3][3], double P[3][3], double res[3][3]) nogil: +cdef void transform(double A[3][3], double P[3][3], double res[3][3]) noexcept nogil: '''Compute the transformation P.T*A*P and add it into res. ''' cdef int i, j, k, l @@ -205,7 +205,7 @@ cdef void transform(double A[3][3], double P[3][3], double res[3][3]) nogil: res[i][j] += P[k][i]*A[k][l]*P[l][j] # P.T*A*P cdef void transform_diag(double *A, double P[3][3], - double res[3][3]) nogil: + double res[3][3]) noexcept nogil: '''Compute the transformation P.T*A*P and add it into res. A is diagonal and contains the diagonal entries alone. @@ -217,7 +217,7 @@ cdef void transform_diag(double *A, double P[3][3], res[i][j] += P[k][i]*A[k]*P[k][j] # P.T*A*P cdef void transform_diag_inv(double *A, double P[3][3], - double res[3][3]) nogil: + double res[3][3]) noexcept nogil: '''Compute the transformation P*A*P.T and set it into res. A is diagonal and contains just the diagonal entries. ''' @@ -257,7 +257,7 @@ def py_transform_diag_inv(double[:] A, double[:,:] P): return res -cdef double * tred2(double V[n][n], double *d, double *e) nogil: +cdef double * tred2(double V[n][n], double *d, double *e) noexcept nogil: '''Symmetric Householder reduction to tridiagonal form This is derived from the Algol procedures tred2 by @@ -376,7 +376,7 @@ cdef double * tred2(double V[n][n], double *d, double *e) nogil: return d -cdef void tql2(double V[n][n], double *d, double *e) nogil: +cdef void tql2(double V[n][n], double *d, double *e) noexcept nogil: '''Symmetric tridiagonal QL algo for eigendecomposition This is derived from the Algol procedures tql2, by @@ -492,14 +492,14 @@ cdef void tql2(double V[n][n], double *d, double *e) nogil: V[j][k] = p -cdef void zero_matrix_case(double V[n][n], double *d) nogil: +cdef void zero_matrix_case(double V[n][n], double *d) noexcept nogil: cdef int i, j for i in range(3): d[i] = 0.0 for j in range(3): V[i][j] = (i==j) -cdef void eigen_decomposition(double A[n][n], double V[n][n], double *d) nogil: +cdef void eigen_decomposition(double A[n][n], double V[n][n], double *d) noexcept nogil: '''Get eigenvalues and eigenvectors of matrix A. V is output eigenvectors and d are the eigenvalues. ''' diff --git a/pysph/base/linked_list_nnps.pxd b/pysph/base/linked_list_nnps.pxd index b6211a8e1..b78c994fc 100644 --- a/pysph/base/linked_list_nnps.pxd +++ b/pysph/base/linked_list_nnps.pxd @@ -24,5 +24,5 @@ cdef class LinkedListNNPS(NNPS): cpdef long _get_number_of_cells(self) except -1 cdef long _get_flattened_cell_index(self, cPoint pnt, double cell_size) cdef long _get_valid_cell_index(self, int cid_x, int cid_y, int cid_z, - int* ncells_per_dim, int dim, int n_cells) nogil - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + int* ncells_per_dim, int dim, int n_cells) noexcept nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil diff --git a/pysph/base/linked_list_nnps.pyx b/pysph/base/linked_list_nnps.pyx index 7ef842e57..87a099ff0 100644 --- a/pysph/base/linked_list_nnps.pyx +++ b/pysph/base/linked_list_nnps.pyx @@ -87,7 +87,7 @@ cdef class LinkedListNNPS(NNPS): #### Public protocol ################################################ - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -326,7 +326,7 @@ cdef class LinkedListNNPS(NNPS): @cython.boundscheck(False) @cython.wraparound(False) cdef long _get_valid_cell_index(self, int cid_x, int cid_y, int cid_z, - int* ncells_per_dim, int dim, int n_cells) nogil: + int* ncells_per_dim, int dim, int n_cells) noexcept nogil: return get_valid_cell_index( cid_x, cid_y, cid_z, ncells_per_dim, dim, n_cells ) diff --git a/pysph/base/nnps_base.pxd b/pysph/base/nnps_base.pxd index 6371dd030..b7317d036 100644 --- a/pysph/base/nnps_base.pxd +++ b/pysph/base/nnps_base.pxd @@ -30,11 +30,11 @@ cdef extern from 'limits.h': ctypedef unsigned int ZOLTAN_ID_TYPE ctypedef unsigned int* ZOLTAN_ID_PTR -cdef inline double norm2(double x, double y, double z) nogil: +cdef inline double norm2(double x, double y, double z) noexcept nogil: return x*x + y*y + z*z @cython.cdivision(True) -cdef inline int real_to_int(double real_val, double step) nogil: +cdef inline int real_to_int(double real_val, double step) noexcept nogil: """ Return the bin index to which the given position belongs. Parameters @@ -54,7 +54,7 @@ cdef inline int real_to_int(double real_val, double step) nogil: return ret_val cdef inline void find_cell_id_raw(double x, double y, double z, double - cell_size, int *ix, int *iy, int *iz) nogil: + cell_size, int *ix, int *iy, int *iz) noexcept nogil: """ Find the cell index for the corresponding point Parameters @@ -80,7 +80,7 @@ cdef inline void find_cell_id_raw(double x, double y, double z, double @cython.boundscheck(False) @cython.wraparound(False) cdef inline long flatten_raw(int x, int y, int z, int* ncells_per_dim, - int dim) nogil: + int dim) noexcept nogil: """Return a flattened index for a cell The flattening is determined using the row-order indexing commonly @@ -96,7 +96,7 @@ cdef inline long flatten_raw(int x, int y, int z, int* ncells_per_dim, @cython.boundscheck(False) @cython.wraparound(False) -cdef inline long flatten(cIntPoint cid, IntArray ncells_per_dim, int dim) nogil: +cdef inline long flatten(cIntPoint cid, IntArray ncells_per_dim, int dim) noexcept nogil: """Return a flattened index for a cell The flattening is determined using the row-order indexing commonly @@ -109,7 +109,7 @@ cdef inline long flatten(cIntPoint cid, IntArray ncells_per_dim, int dim) nogil: @cython.boundscheck(False) @cython.wraparound(False) cdef inline long get_valid_cell_index(int cid_x, int cid_y, int cid_z, - int* ncells_per_dim, int dim, int n_cells) nogil: + int* ncells_per_dim, int dim, int n_cells) noexcept nogil: """Return the flattened index for a valid cell""" cdef long ncx = ncells_per_dim[0] cdef long ncy = ncells_per_dim[1] @@ -268,13 +268,13 @@ cdef class NeighborCache: cdef public list _neighbor_arrays cdef int _last_avg_nbr_size - cdef void get_neighbors_raw(self, size_t d_idx, UIntArray nbrs) nogil + cdef void get_neighbors_raw(self, size_t d_idx, UIntArray nbrs) noexcept nogil cpdef get_neighbors(self, int src_index, size_t d_idx, UIntArray nbrs) cpdef find_all_neighbors(self) cpdef update(self) cdef void _update_last_avg_nbr_size(self) - cdef void _find_neighbors(self, long d_idx) nogil + cdef void _find_neighbors(self, long d_idx) noexcept nogil cdef class NNPSBase: ########################################################################## @@ -305,7 +305,7 @@ cdef class NNPSBase: cpdef get_nearest_particles_no_cache(self, int src_index, int dst_index, size_t d_idx, UIntArray nbrs, bint prealloc) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil cpdef get_nearest_particles(self, int src_index, int dst_index, size_t d_idx, UIntArray nbrs) @@ -336,15 +336,15 @@ cdef class NNPS(NNPSBase): cpdef _bin(self, int pa_index, UIntArray indices) cdef void _sort_neighbors(self, unsigned int* nbrs, size_t length, - unsigned int *gids) nogil + unsigned int *gids) noexcept nogil # compute the min and max for the particle coordinates cdef _compute_bounds(self) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil cdef void get_nearest_neighbors(self, size_t d_idx, - UIntArray nbrs) nogil + UIntArray nbrs) noexcept nogil # Neighbor query function. Returns the list of neighbors for a # requested particle. The returned list is assumed to be of type diff --git a/pysph/base/nnps_base.pyx b/pysph/base/nnps_base.pyx index 0e147e90b..2ad864fa2 100644 --- a/pysph/base/nnps_base.pyx +++ b/pysph/base/nnps_base.pyx @@ -58,7 +58,7 @@ cdef int Ghost = ParticleTAGS.Ghost ctypedef pair[unsigned int, unsigned int] id_gid_pair_t -cdef inline bint _compare_gids(id_gid_pair_t x, id_gid_pair_t y) nogil: +cdef inline bint _compare_gids(id_gid_pair_t x, id_gid_pair_t y) noexcept nogil: return y.second > x.second def py_flatten(IntPoint cid, IntArray ncells_per_dim, int dim): @@ -1193,7 +1193,7 @@ cdef class NeighborCache: #### Public protocol ################################################ - cdef void get_neighbors_raw(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void get_neighbors_raw(self, size_t d_idx, UIntArray nbrs) noexcept nogil: if self._cached.data[d_idx] == 0: self._find_neighbors(d_idx) cdef size_t start, end, tid @@ -1253,7 +1253,7 @@ cdef class NeighborCache: if total > 0 and np > 0: self._last_avg_nbr_size = int(total/np) + 1 - cdef void _find_neighbors(self, long d_idx) nogil: + cdef void _find_neighbors(self, long d_idx) noexcept nogil: cdef int thread_id = threadid() self._pid_to_tid.data[d_idx] = thread_id self._start_stop.data[d_idx*2] = \ @@ -1402,7 +1402,7 @@ cdef class NNPSBase: self.find_nearest_neighbors(d_idx, nbrs) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: # Implement this in the subclass to actually do something useful. pass @@ -1518,7 +1518,7 @@ cdef class NNPS(NNPSBase): for cache in self.cache: cache.update() - cdef void get_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void get_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: if self.use_cache: self.current_cache.get_neighbors_raw(d_idx, nbrs) else: @@ -1584,7 +1584,7 @@ cdef class NNPS(NNPSBase): self.xmax.set_data(np.asarray([xmax, ymax, zmax])) cdef void _sort_neighbors(self, unsigned int* nbrs, size_t length, - unsigned int *gids) nogil: + unsigned int *gids) noexcept nogil: if length == 0: return cdef id_gid_pair_t _entry diff --git a/pysph/base/octree.pxd b/pysph/base/octree.pxd index 1fb6b8c70..d37934990 100644 --- a/pysph/base/octree.pxd +++ b/pysph/base/octree.pxd @@ -84,26 +84,26 @@ cdef class Octree: # Member functions ########################################################################## - cdef inline double _get_eps(self, double length, double* xmin) nogil + cdef inline double _get_eps(self, double length, double* xmin) noexcept nogil cdef inline void _calculate_domain(self, NNPSParticleArrayWrapper pa) cdef inline cOctreeNode* _new_node(self, double* xmin, double length, double hmax = *, int level = *, cOctreeNode* parent = *, - int num_particles = *, bint is_leaf = *) nogil + int num_particles = *, bint is_leaf = *) noexcept nogil cdef inline void _delete_tree(self, cOctreeNode* node) cdef int _c_build_tree(self, NNPSParticleArrayWrapper pa, vector[u_int]* indices, double* xmin, double length, - cOctreeNode* node, int level) nogil + cOctreeNode* node, int level) noexcept nogil cdef int _c_build_tree_level1(self, NNPSParticleArrayWrapper pa, - double* xmin, double length, cOctreeNode* node, int num_threads) nogil + double* xmin, double length, cOctreeNode* node, int num_threads) noexcept nogil cdef int _c_build_tree_bfs(self, NNPSParticleArrayWrapper pa, u_int* p_indices, vector[cOctreeNode *]* level_nodes, - int level, int num_threads) nogil + int level, int num_threads) noexcept nogil cdef void _plot_tree(self, OctreeNode node, ax) @@ -139,7 +139,7 @@ cdef class CompressedOctree(Octree): cdef int _c_build_tree(self, NNPSParticleArrayWrapper pa, vector[u_int]* indices, double* xmin, double length, - cOctreeNode* node, int level) nogil + cOctreeNode* node, int level) noexcept nogil cdef int c_build_tree(self, NNPSParticleArrayWrapper pa_wrapper, bint test_parallel = *) diff --git a/pysph/base/octree.pyx b/pysph/base/octree.pyx index 5960a49fe..0d6249ef8 100644 --- a/pysph/base/octree.pyx +++ b/pysph/base/octree.pyx @@ -25,10 +25,10 @@ cdef extern from *: #define START_OMP_SINGLE_PRAGMA() _Pragma("omp single") { #define START_OMP_BARRIER_PRAGMA() _Pragma("omp barrier") { """ - void START_OMP_PARALLEL_PRAGMA() nogil - void END_OMP_PRAGMA() nogil - void START_OMP_SINGLE_PRAGMA() nogil - void START_OMP_BARRIER_PRAGMA() nogil + void START_OMP_PARALLEL_PRAGMA() noexcept nogil + void END_OMP_PRAGMA() noexcept nogil + void START_OMP_SINGLE_PRAGMA() noexcept nogil + void START_OMP_BARRIER_PRAGMA() noexcept nogil ######################################################################## @@ -205,7 +205,7 @@ cdef class Octree: #### Private protocol ################################################ @cython.cdivision(True) - cdef inline double _get_eps(self, double length, double* xmin) nogil: + cdef inline double _get_eps(self, double length, double* xmin) noexcept nogil: return (self.machine_eps/length)*fmax(length, fmax(fmax(fabs(xmin[0]), fabs(xmin[1])), fabs(xmin[2]))) @@ -240,7 +240,7 @@ cdef class Octree: cdef inline cOctreeNode* _new_node(self, double* xmin, double length, double hmax = 0, int level = 0, cOctreeNode* parent = NULL, - int num_particles = 0, bint is_leaf = False) nogil: + int num_particles = 0, bint is_leaf = False) noexcept nogil: """Create a new cOctreeNode""" cdef cOctreeNode* node = malloc(sizeof(cOctreeNode)) @@ -282,7 +282,7 @@ cdef class Octree: @cython.cdivision(True) cdef int _c_build_tree(self, NNPSParticleArrayWrapper pa, vector[u_int]* indices, double* xmin, double length, - cOctreeNode* node, int level) nogil: + cOctreeNode* node, int level) noexcept nogil: cdef double* src_x_ptr = pa.x.data cdef double* src_y_ptr = pa.y.data cdef double* src_z_ptr = pa.z.data @@ -367,7 +367,7 @@ cdef class Octree: @cython.cdivision(True) @cython.boundscheck(False) cdef int _c_build_tree_level1(self, NNPSParticleArrayWrapper pa, double* xmin, double length, - cOctreeNode* node, int num_threads) nogil: + cOctreeNode* node, int num_threads) noexcept nogil: cdef double* src_x_ptr = pa.x.data cdef double* src_y_ptr = pa.y.data @@ -483,7 +483,7 @@ cdef class Octree: @cython.boundscheck(False) cdef int _c_build_tree_bfs(self, NNPSParticleArrayWrapper pa, u_int* p_indices, vector[cOctreeNode *]* level_nodes, - int level, int num_threads) nogil: + int level, int num_threads) noexcept nogil: cdef double* src_x_ptr = pa.x.data cdef double* src_y_ptr = pa.y.data cdef double* src_z_ptr = pa.z.data @@ -838,7 +838,7 @@ cdef class CompressedOctree(Octree): @cython.cdivision(True) cdef int _c_build_tree(self, NNPSParticleArrayWrapper pa, vector[u_int]* indices, double* xmin, double length, - cOctreeNode* node, int level) nogil: + cOctreeNode* node, int level) noexcept nogil: cdef double* src_x_ptr = pa.x.data cdef double* src_y_ptr = pa.y.data @@ -948,7 +948,7 @@ cdef class CompressedOctree(Octree): @cython.cdivision(True) @cython.boundscheck(False) cdef int _c_build_tree_level1(self, NNPSParticleArrayWrapper pa, double* xmin, double length, - cOctreeNode* node, int num_threads) nogil: + cOctreeNode* node, int num_threads) noexcept nogil: cdef double* src_x_ptr = pa.x.data cdef double* src_y_ptr = pa.y.data @@ -1118,7 +1118,7 @@ cdef class CompressedOctree(Octree): @cython.cdivision(True) @cython.boundscheck(False) cdef int _c_build_tree_bfs(self, NNPSParticleArrayWrapper pa, u_int* p_indices, - vector[cOctreeNode *]* level_nodes, int level, int num_threads) nogil: + vector[cOctreeNode *]* level_nodes, int level, int num_threads) noexcept nogil: cdef double* src_x_ptr = pa.x.data cdef double* src_y_ptr = pa.y.data diff --git a/pysph/base/octree_nnps.pxd b/pysph/base/octree_nnps.pxd index d7ef496ec..e5ee774b4 100644 --- a/pysph/base/octree_nnps.pxd +++ b/pysph/base/octree_nnps.pxd @@ -35,13 +35,13 @@ cdef class OctreeNNPS(NNPS): cpdef get_depth(self, int pa_index) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil cpdef set_context(self, int src_index, int dst_index) cdef void _get_neighbors(self, double q_x, double q_y, double q_z, double q_h, double* src_x_ptr, double* src_y_ptr, double* src_z_ptr, double* src_h_ptr, - UIntArray nbrs, cOctreeNode* node) nogil + UIntArray nbrs, cOctreeNode* node) noexcept nogil cpdef get_spatially_ordered_indices(self, int pa_index, LongArray indices) diff --git a/pysph/base/octree_nnps.pyx b/pysph/base/octree_nnps.pyx index 14c98a990..0a25f69fb 100644 --- a/pysph/base/octree_nnps.pyx +++ b/pysph/base/octree_nnps.pyx @@ -65,7 +65,7 @@ cdef class OctreeNNPS(NNPS): self.dst = self.pa_wrappers[dst_index] self.src = self.pa_wrappers[src_index] - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -104,7 +104,7 @@ cdef class OctreeNNPS(NNPS): @cython.cdivision(True) cdef void _get_neighbors(self, double q_x, double q_y, double q_z, double q_h, double* src_x_ptr, double* src_y_ptr, double* src_z_ptr, double* src_h_ptr, - UIntArray nbrs, cOctreeNode* node) nogil: + UIntArray nbrs, cOctreeNode* node) noexcept nogil: """Find neighbors recursively""" cdef double x_centre = node.xmin[0] + node.length/2 cdef double y_centre = node.xmin[1] + node.length/2 diff --git a/pysph/base/spatial_hash_nnps.pxd b/pysph/base/spatial_hash_nnps.pxd index c37d95e26..0362f1a34 100644 --- a/pysph/base/spatial_hash_nnps.pxd +++ b/pysph/base/spatial_hash_nnps.pxd @@ -9,12 +9,12 @@ cdef extern from "spatial_hash.h": cdef cppclass HashEntry: double h_max - vector[unsigned int] *get_indices() nogil + vector[unsigned int] *get_indices() noexcept nogil cdef cppclass HashTable: HashTable(long long int) nogil except + - void add(int, int, int, int, double) nogil - HashEntry* get(int, int, int) nogil + void add(int, int, int, int, double) noexcept nogil + HashEntry* get(int, int, int) noexcept nogil # NNPS using Spatial Hashing algorithm cdef class SpatialHashNNPS(NNPS): @@ -35,13 +35,13 @@ cdef class SpatialHashNNPS(NNPS): cpdef set_context(self, int src_index, int dst_index) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil cdef inline void _add_to_hashtable(self, int hash_id, unsigned int pid, double h, - int i, int j, int k) nogil + int i, int j, int k) noexcept nogil cdef inline int _neighbor_boxes(self, int i, int j, int k, - int* x, int* y, int* z) nogil + int* x, int* y, int* z) noexcept nogil cpdef _refresh(self) @@ -70,17 +70,17 @@ cdef class ExtendedSpatialHashNNPS(NNPS): cpdef set_context(self, int src_index, int dst_index) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil - cdef inline int _h_mask_approx(self, int* x, int* y, int* z) nogil + cdef inline int _h_mask_approx(self, int* x, int* y, int* z) noexcept nogil - cdef inline int _h_mask_exact(self, int* x, int* y, int* z) nogil + cdef inline int _h_mask_exact(self, int* x, int* y, int* z) noexcept nogil cdef int _neighbor_boxes(self, int i, int j, int k, - int* x, int* y, int* z, double h) nogil + int* x, int* y, int* z, double h) noexcept nogil cdef inline void _add_to_hashtable(self, int hash_id, unsigned int pid, double h, - int i, int j, int k) nogil + int i, int j, int k) noexcept nogil cpdef _refresh(self) diff --git a/pysph/base/spatial_hash_nnps.pyx b/pysph/base/spatial_hash_nnps.pyx index 9878dda3f..487baa8f4 100644 --- a/pysph/base/spatial_hash_nnps.pyx +++ b/pysph/base/spatial_hash_nnps.pyx @@ -79,7 +79,7 @@ cdef class SpatialHashNNPS(NNPS): self.dst = self.pa_wrappers[dst_index] self.src = self.pa_wrappers[src_index] - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -156,11 +156,11 @@ cdef class SpatialHashNNPS(NNPS): #### Private protocol ################################################ cdef inline void _add_to_hashtable(self, int hash_id, unsigned int pid, double h, - int i, int j, int k) nogil: + int i, int j, int k) noexcept nogil: self.hashtable[hash_id].add(i,j,k,pid,h) cdef inline int _neighbor_boxes(self, int i, int j, int k, - int* x, int* y, int* z) nogil: + int* x, int* y, int* z) noexcept nogil: cdef int length = 0 cdef int p, q, r for p from -1<=p<2: @@ -285,7 +285,7 @@ cdef class ExtendedSpatialHashNNPS(NNPS): self.dst = self.pa_wrappers[dst_index] self.src = self.pa_wrappers[src_index] - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -369,10 +369,10 @@ cdef class ExtendedSpatialHashNNPS(NNPS): #### Private protocol ################################################ cdef inline void _add_to_hashtable(self, int hash_id, unsigned int pid, double h, - int i, int j, int k) nogil: + int i, int j, int k) noexcept nogil: self.hashtable[hash_id].add(i,j,k,pid,h) - cdef inline int _h_mask_approx(self, int* x, int* y, int* z) nogil: + cdef inline int _h_mask_approx(self, int* x, int* y, int* z) noexcept nogil: cdef int length = 0 cdef int s, t, u @@ -388,7 +388,7 @@ cdef class ExtendedSpatialHashNNPS(NNPS): return length - cdef inline int _h_mask_exact(self, int* x, int* y, int* z) nogil: + cdef inline int _h_mask_exact(self, int* x, int* y, int* z) noexcept nogil: cdef int length = 0 cdef int s, t, u @@ -405,7 +405,7 @@ cdef class ExtendedSpatialHashNNPS(NNPS): @cython.cdivision(True) cdef int _neighbor_boxes(self, int i, int j, int k, - int* x, int* y, int* z, double h) nogil: + int* x, int* y, int* z, double h) noexcept nogil: cdef int length = 0 cdef int p diff --git a/pysph/base/stratified_hash_nnps.pxd b/pysph/base/stratified_hash_nnps.pxd index a0772c259..38babdce6 100644 --- a/pysph/base/stratified_hash_nnps.pxd +++ b/pysph/base/stratified_hash_nnps.pxd @@ -19,15 +19,15 @@ cdef extern from "spatial_hash.h": cdef cppclass HashEntry: double h_max - vector[unsigned int] *get_indices() nogil + vector[unsigned int] *get_indices() noexcept nogil cdef cppclass HashTable: long long int table_size HashTable(long long int) nogil except + - void add(int, int, int, int, double) nogil - HashEntry* get(int, int, int) nogil - int number_of_particles() nogil + void add(int, int, int, int, double) noexcept nogil + HashEntry* get(int, int, int) noexcept nogil + int number_of_particles() noexcept nogil cdef class StratifiedHashNNPS(NNPS): ############################################################################ @@ -59,19 +59,19 @@ cdef class StratifiedHashNNPS(NNPS): cpdef double get_binning_size(self, int interval) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil - cdef inline int _h_mask_exact(self, int* x, int* y, int* z, int H) nogil + cdef inline int _h_mask_exact(self, int* x, int* y, int* z, int H) noexcept nogil cdef inline int _neighbor_boxes(self, int i, int j, int k, - int* x, int* y, int* z, int H) nogil + int* x, int* y, int* z, int H) noexcept nogil - cdef inline int _get_hash_id(self, double h) nogil + cdef inline int _get_hash_id(self, double h) noexcept nogil cdef inline void _set_h_max(self, double* current_cells, double* src_h_ptr, - int num_particles) nogil + int num_particles) noexcept nogil - cdef inline double _get_h_max(self, double* current_cells, int hash_id) nogil + cdef inline double _get_h_max(self, double* current_cells, int hash_id) noexcept nogil cpdef _refresh(self) diff --git a/pysph/base/stratified_hash_nnps.pyx b/pysph/base/stratified_hash_nnps.pyx index 72bf66918..5f76a044d 100644 --- a/pysph/base/stratified_hash_nnps.pyx +++ b/pysph/base/stratified_hash_nnps.pyx @@ -111,7 +111,7 @@ cdef class StratifiedHashNNPS(NNPS): self.src = self.pa_wrappers[src_index] @cython.cdivision(True) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -214,15 +214,15 @@ cdef class StratifiedHashNNPS(NNPS): #### Private protocol ################################################ @cython.cdivision(True) - cdef inline int _get_hash_id(self, double h) nogil: + cdef inline int _get_hash_id(self, double h) noexcept nogil: return floor((self.radius_scale*h - self.hmin)/self.interval_size) - cdef inline double _get_h_max(self, double* current_cells, int hash_id) nogil: + cdef inline double _get_h_max(self, double* current_cells, int hash_id) noexcept nogil: return self.radius_scale*current_cells[hash_id] @cython.cdivision(True) cdef inline int _h_mask_exact(self, int* x, int* y, int* z, - int H) nogil: + int H) noexcept nogil: cdef int length = 0 cdef int s, t, u @@ -237,7 +237,7 @@ cdef class StratifiedHashNNPS(NNPS): return length cdef inline int _neighbor_boxes(self, int i, int j, int k, - int* x, int* y, int* z, int H) nogil: + int* x, int* y, int* z, int H) noexcept nogil: cdef int length = 0 cdef int p @@ -265,7 +265,7 @@ cdef class StratifiedHashNNPS(NNPS): return length cdef inline void _set_h_max(self, double* current_cells, double* src_h_ptr, - int num_particles) nogil: + int num_particles) noexcept nogil: cdef double h cdef int i, idx for i from 0<=i min(self.num_levels, ceil(log2((self.cell_size + EPS)/ self.radius_scale / h))) @@ -329,7 +329,7 @@ cdef class StratifiedSFCNNPS(NNPS): cdef inline int _get_H(self, double h_q, double h_j): return ceil(h_q / h_j) - cdef inline int get_idx(self, uint64_t key, uint64_t max_key, int* key_to_idx) nogil: + cdef inline int get_idx(self, uint64_t key, uint64_t max_key, int* key_to_idx) noexcept nogil: return -1 if key >= max_key else key_to_idx[key] cdef int _neighbor_boxes_func(self, int i, int j, int k, int H, @@ -346,7 +346,7 @@ cdef class StratifiedSFCNNPS(NNPS): cdef int _neighbor_boxes_asym(self, int i, int j, int k, int H, int* current_key_to_idx_level, uint64_t max_key, double current_cell_size, double* current_hmax_level, - vector[int]* nbr_boxes) nogil: + vector[int]* nbr_boxes) noexcept nogil: cdef int length = 0 cdef uint64_t key @@ -380,7 +380,7 @@ cdef class StratifiedSFCNNPS(NNPS): cdef int _neighbor_boxes_sym(self, int i, int j, int k, int H, int* current_key_to_idx_level, uint64_t max_key, double current_cell_size, double* current_hmax_level, - vector[int]* nbr_boxes) nogil: + vector[int]* nbr_boxes) noexcept nogil: cdef int length = 0 cdef uint64_t key diff --git a/pysph/base/z_order_nnps.pxd b/pysph/base/z_order_nnps.pxd index 95ff92826..ac15aaa4a 100644 --- a/pysph/base/z_order_nnps.pxd +++ b/pysph/base/z_order_nnps.pxd @@ -63,11 +63,11 @@ cdef class ZOrderNNPS(NNPS): cdef inline int _neighbor_boxes(self, int i, int j, int k, int* current_key_to_idx, int num_particles, - int* found_indices) nogil + int* found_indices) noexcept nogil cpdef set_context(self, int src_index, int dst_index) - cdef inline int get_idx(self, uint64_t key, int* key_to_idx) nogil + cdef inline int get_idx(self, uint64_t key, int* key_to_idx) noexcept nogil cpdef np.ndarray get_nbr_boxes(self, pa_index, cid) @@ -77,7 +77,7 @@ cdef class ZOrderNNPS(NNPS): cpdef np.ndarray get_keys(self, pa_index) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil cpdef get_nearest_particles_no_cache(self, int src_index, int dst_index, size_t d_idx, UIntArray nbrs, bint prealloc) @@ -105,7 +105,7 @@ cdef class ExtendedZOrderNNPS(ZOrderNNPS): # Member functions ########################################################################## - cdef inline int _h_mask_exact(self, int* x, int* y, int* z) nogil + cdef inline int _h_mask_exact(self, int* x, int* y, int* z) noexcept nogil cdef int _neighbor_boxes_func(self, int i, int j, int k, int* current_key_to_idx, uint32_t* current_cids, @@ -115,12 +115,12 @@ cdef class ExtendedZOrderNNPS(ZOrderNNPS): cdef int _neighbor_boxes_asym(self, int i, int j, int k, int* current_key_to_idx, uint32_t* current_cids, double* current_hmax, int num_particles, - int* found_indices, double h) nogil + int* found_indices, double h) noexcept nogil cdef int _neighbor_boxes_sym(self, int i, int j, int k, int* current_key_to_idx, uint32_t* current_cids, double* current_hmax, int num_particles, - int* found_indices, double h) nogil + int* found_indices, double h) noexcept nogil cdef void _fill_nbr_boxes(self) diff --git a/pysph/base/z_order_nnps.pyx b/pysph/base/z_order_nnps.pyx index e7a75fef1..afb170920 100644 --- a/pysph/base/z_order_nnps.pyx +++ b/pysph/base/z_order_nnps.pyx @@ -21,7 +21,7 @@ cdef extern from "" namespace "std" nogil: ############################################################################# -cdef inline int cmp_func(const void* a, const void* b) nogil: +cdef inline int cmp_func(const void* a, const void* b) noexcept nogil: return (a)[0] - (b)[0] cdef class ZOrderNNPS(NNPS): @@ -128,7 +128,7 @@ cdef class ZOrderNNPS(NNPS): self.dst = self.pa_wrappers[dst_index] self.src = self.pa_wrappers[src_index] - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -479,12 +479,12 @@ cdef class ZOrderNNPS(NNPS): else: current_lengths[cid] += 1 - cdef inline int get_idx(self, uint64_t key, int* key_to_idx) nogil: + cdef inline int get_idx(self, uint64_t key, int* key_to_idx) noexcept nogil: return -1 if key >= self.max_key else key_to_idx[key] cdef inline int _neighbor_boxes(self, int i, int j, int k, int* current_key_to_idx, int num_particles, - int* found_indices) nogil: + int* found_indices) noexcept nogil: cdef int length = 0 cdef int p, q, r cdef uint64_t key @@ -609,7 +609,7 @@ cdef class ExtendedZOrderNNPS(ZOrderNNPS): free(self.hmax[i]) free(self.hmax) - cdef inline int _h_mask_exact(self, int* x, int* y, int* z) nogil: + cdef inline int _h_mask_exact(self, int* x, int* y, int* z) noexcept nogil: cdef int length = 0 cdef int s, t, u @@ -640,7 +640,7 @@ cdef class ExtendedZOrderNNPS(ZOrderNNPS): cdef int _neighbor_boxes_asym(self, int i, int j, int k, int* current_key_to_idx, uint32_t* current_cids, double* current_hmax, int num_particles, - int* found_indices, double h) nogil: + int* found_indices, double h) noexcept nogil: cdef int length = 0 cdef uint64_t key @@ -674,7 +674,7 @@ cdef class ExtendedZOrderNNPS(ZOrderNNPS): cdef int _neighbor_boxes_sym(self, int i, int j, int k, int* current_key_to_idx, uint32_t* current_cids, double* current_hmax, int num_particles, - int* found_indices, double h) nogil: + int* found_indices, double h) noexcept nogil: cdef int length = 0 cdef uint64_t key From 126efe37b1e1972cf234e1dc10ee64f76a8c95da Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sun, 18 Aug 2024 15:58:51 +0530 Subject: [PATCH 06/28] chore(c_kernel): methods are marked noexcept nogil --- pysph/base/c_kernels.pyx | 120 +++++++++++++++++----------------- pysph/base/c_kernels.pyx.mako | 5 +- 2 files changed, 63 insertions(+), 62 deletions(-) diff --git a/pysph/base/c_kernels.pyx b/pysph/base/c_kernels.pyx index e69e06d40..7a43a7f97 100644 --- a/pysph/base/c_kernels.pyx +++ b/pysph/base/c_kernels.pyx @@ -15,7 +15,7 @@ cdef class CubicSpline: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -56,13 +56,13 @@ cdef class CubicSpline: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 2. / 3 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -81,7 +81,7 @@ cdef class CubicSpline: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -117,7 +117,7 @@ cdef class CubicSpline: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -148,7 +148,7 @@ cdef class CubicSpline: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class CubicSplineWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -192,7 +192,7 @@ cdef class WendlandQuintic: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -221,13 +221,13 @@ cdef class WendlandQuintic: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 0.5 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -247,7 +247,7 @@ cdef class WendlandQuintic: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -278,7 +278,7 @@ cdef class WendlandQuintic: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -306,7 +306,7 @@ cdef class WendlandQuintic: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class WendlandQuinticWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -350,7 +350,7 @@ cdef class Gaussian: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -377,7 +377,7 @@ cdef class Gaussian: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: # The inflection point is at q=1/sqrt(2) # the deltap values for some standard kernels # have been tabulated in sec 3.2 of @@ -387,7 +387,7 @@ cdef class Gaussian: cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -407,7 +407,7 @@ cdef class Gaussian: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -436,7 +436,7 @@ cdef class Gaussian: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -461,7 +461,7 @@ cdef class Gaussian: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class GaussianWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -505,7 +505,7 @@ cdef class QuinticSpline: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -551,7 +551,7 @@ cdef class QuinticSpline: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: # The inflection points for the polynomial are obtained as # http://www.wolframalpha.com/input/?i=%28%283-x%29%5E5+-+6*%282-x%29%5E5+%2B+15*%281-x%29%5E5%29%27%27 # the only permissible value is taken @@ -560,7 +560,7 @@ cdef class QuinticSpline: cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -580,7 +580,7 @@ cdef class QuinticSpline: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -633,7 +633,7 @@ cdef class QuinticSpline: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -675,7 +675,7 @@ cdef class QuinticSpline: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class QuinticSplineWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -719,7 +719,7 @@ cdef class SuperGaussian: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -748,7 +748,7 @@ cdef class SuperGaussian: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: # Found inflection point using sympy. if self.dim == 1: return 0.584540507426389 @@ -760,7 +760,7 @@ cdef class SuperGaussian: cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -779,7 +779,7 @@ cdef class SuperGaussian: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double d cdef double fac cdef double h1 @@ -810,7 +810,7 @@ cdef class SuperGaussian: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -837,7 +837,7 @@ cdef class SuperGaussian: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class SuperGaussianWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -881,7 +881,7 @@ cdef class WendlandQuinticC4: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -911,13 +911,13 @@ cdef class WendlandQuinticC4: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 0.47114274 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -937,7 +937,7 @@ cdef class WendlandQuinticC4: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -970,7 +970,7 @@ cdef class WendlandQuinticC4: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -999,7 +999,7 @@ cdef class WendlandQuinticC4: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class WendlandQuinticC4Wrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -1043,7 +1043,7 @@ cdef class WendlandQuinticC6: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1073,13 +1073,13 @@ cdef class WendlandQuinticC6: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 0.4305720757 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -1098,7 +1098,7 @@ cdef class WendlandQuinticC6: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -1131,7 +1131,7 @@ cdef class WendlandQuinticC6: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1160,7 +1160,7 @@ cdef class WendlandQuinticC6: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class WendlandQuinticC6Wrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -1204,7 +1204,7 @@ cdef class WendlandQuinticC2_1D: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1233,13 +1233,13 @@ cdef class WendlandQuinticC2_1D: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 2.0/3 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -1259,7 +1259,7 @@ cdef class WendlandQuinticC2_1D: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -1290,7 +1290,7 @@ cdef class WendlandQuinticC2_1D: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1318,7 +1318,7 @@ cdef class WendlandQuinticC2_1D: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class WendlandQuinticC2_1DWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -1362,7 +1362,7 @@ cdef class WendlandQuinticC4_1D: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1391,13 +1391,13 @@ cdef class WendlandQuinticC4_1D: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 0.55195628 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -1417,7 +1417,7 @@ cdef class WendlandQuinticC4_1D: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -1448,7 +1448,7 @@ cdef class WendlandQuinticC4_1D: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1476,7 +1476,7 @@ cdef class WendlandQuinticC4_1D: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class WendlandQuinticC4_1DWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -1520,7 +1520,7 @@ cdef class WendlandQuinticC6_1D: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1550,13 +1550,13 @@ cdef class WendlandQuinticC6_1D: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 0.47996698 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -1575,7 +1575,7 @@ cdef class WendlandQuinticC6_1D: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -1608,7 +1608,7 @@ cdef class WendlandQuinticC6_1D: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1637,7 +1637,7 @@ cdef class WendlandQuinticC6_1D: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class WendlandQuinticC6_1DWrapper: """Reasonably high-performance convenience wrapper for Kernels. diff --git a/pysph/base/c_kernels.pyx.mako b/pysph/base/c_kernels.pyx.mako index c505ee7d7..626a47c74 100644 --- a/pysph/base/c_kernels.pyx.mako +++ b/pysph/base/c_kernels.pyx.mako @@ -1,7 +1,7 @@ # cython: embedsignature=True, language_level=3 # distutils: language=c++ <% -from compyle.api import CythonGenerator +from compyle.api import CythonGenerator, get_config from kernels import ( CubicSpline, WendlandQuintic, Gaussian, QuinticSpline, SuperGaussian, WendlandQuinticC4, WendlandQuinticC6, WendlandQuinticC2_1D, @@ -12,6 +12,7 @@ CLASSES = ( WendlandQuinticC4, WendlandQuinticC6, WendlandQuinticC2_1D, WendlandQuinticC4_1D, WendlandQuinticC6_1D ) +get_config().use_openmp = True; generator = CythonGenerator(python_methods=True) %> @@ -23,7 +24,7 @@ import numpy as np generator.parse(cls()) classname = cls.__name__ %> -${generator.get_code()} +${generator.get_code()} cdef class ${classname}Wrapper: """Reasonably high-performance convenience wrapper for Kernels. From eb842ab55a78c37c5671d2c74cdf46cdd4a8d1a6 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:29:14 +0530 Subject: [PATCH 07/28] ci(macos): use omp enabled homebrew-llvm-clang Ref - https://github.com/Rdatatable/data.table/wiki/Installation/370c4629742886190c08de5e199a8ca8d3d86b24 - https://github.com/actions/runner-images/blob/5c04ad10e394b07619bd68a62b3cd7665e7a3cb3/images/macos/macos-14-arm64-Readme.md --- .github/workflows/tests.yml | 14 ++++++++++++++ .github/workflows/zoltan-tests.yml | 2 +- setup.py | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 853420fc2..fe6d62caf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,6 +36,20 @@ jobs: conda install -c conda-forge pocl pyopencl python -c 'import pyopencl as cl' if: ${{ runner.os != 'Windows' }} + - name: Setup compyle config on MacOS to use openmp enabled clang from homebrew + run: | + brew install libomp + mkdir -p ~/.compyle + touch ~/.compyle/config.py + echo "import os" >> ~/.compyle/config.py + echo "os.environ['CC'] = '$(brew --prefix llvm@15)/bin/clang'" >> ~/.compyle/config.py + echo "os.environ['CXX'] = '$(brew --prefix llvm@15)/bin/clang++'" >> ~/.compyle/config.py + export CPPFLAGS="-I$(brew --prefix libomp)/include -I$(brew --prefix llvm@15)/include -Xclang -fopenmp" + export LDFLAGS="-L$(brew --prefix libomp)/lib -L$(brew --prefix llvm@15)/lib -lomp" + python -c "import os; OMP_CFLAGS=os.environ.get('CPPFLAGS').split(' '); print(f'{OMP_CFLAGS=}')" >> ~/.compyle/config.py + python -c "import os; OMP_LINK=os.environ.get('LDFLAGS').split(' '); print(f'{OMP_LINK=}')" >> ~/.compyle/config.py + cat ~/.compyle/config.py + if: ${{ runner.os == 'macOS' }} - name: Install dependencies run: | conda info diff --git a/.github/workflows/zoltan-tests.yml b/.github/workflows/zoltan-tests.yml index 7fe2d7b25..2209c800f 100644 --- a/.github/workflows/zoltan-tests.yml +++ b/.github/workflows/zoltan-tests.yml @@ -44,8 +44,8 @@ jobs: python -m pip install --upgrade pip setuptools wheel python -m pip install mpi4py python -m pip install https://github.com/pypr/cyarray/zipball/master - python -m pip install --no-build-isolation https://github.com/pypr/pyzoltan/zipball/master python -m pip install https://github.com/pypr/compyle/zipball/master + python -m pip install --no-build-isolation https://github.com/pypr/pyzoltan/zipball/master python -m pip install -r requirements.txt python -m pip install -r requirements-test.txt python setup.py develop diff --git a/setup.py b/setup.py index 9c528fc44..a65401eb8 100644 --- a/setup.py +++ b/setup.py @@ -127,7 +127,7 @@ def _get_openmp_flags(): return ['/openmp'], [] elif sys.platform == 'darwin': if (os.environ.get('CC') is not None and - os.environ.get('CXX') is not None): + os.environ.get('CXX') is not None): return ['-fopenmp'], ['-fopenmp'] else: return ['-Xpreprocessor', '-fopenmp'], ['-lomp'] From 8718a90e21876043e97a24df000e62ccc2b5282a Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sat, 21 Sep 2024 21:14:13 +0530 Subject: [PATCH 08/28] fix(test_reduce_array): np.alltrue() is deprecated --- pysph/base/tests/test_reduce_array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pysph/base/tests/test_reduce_array.py b/pysph/base/tests/test_reduce_array.py index 134a09173..32b3159f4 100644 --- a/pysph/base/tests/test_reduce_array.py +++ b/pysph/base/tests/test_reduce_array.py @@ -37,7 +37,7 @@ def test_dummy_reduce_array_does_nothing(self): x = np.array([1.0, 2.0]) expect = x result = dummy_reduce_array(x, 'min') - self.assertTrue(np.alltrue(result == expect)) + self.assertTrue(np.all(result == expect)) if __name__ == '__main__': From 9d12c56c34b6592d2e318772c99112f5111cc948 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sat, 21 Sep 2024 23:14:27 +0530 Subject: [PATCH 09/28] fix(geometry.py): use factorial from math instead of np.math --- pysph/tools/geometry.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pysph/tools/geometry.py b/pysph/tools/geometry.py index b99792b46..b40bdadb6 100644 --- a/pysph/tools/geometry.py +++ b/pysph/tools/geometry.py @@ -1,4 +1,7 @@ from __future__ import division + +import math + import numpy as np import copy from pysph.base.nnps import LinkedListNNPS @@ -52,7 +55,7 @@ def matrix_exp(matrix): n = 1 condition = True while condition: - adding = matrix_power(matrix, n) / (1.0 * np.math.factorial(n)) + adding = matrix_power(matrix, n) / (1.0 * math.factorial(n)) result += adding residue = np.sqrt(np.sum(np.square(adding)) / np.sum(np.square(result))) From 20096c3f6f4e1fe62eaaf7712e3431faec81e45d Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sat, 21 Sep 2024 17:30:01 +0530 Subject: [PATCH 10/28] ci: don't cancel tests if one fails --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fe6d62caf..9c6aa4ae4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,6 +13,7 @@ on: jobs: tests: strategy: + fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] python-version: [3.11] From 7bd81b72ba87819a0ed2c405160e71e120fd9538 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sun, 22 Sep 2024 04:30:17 +0530 Subject: [PATCH 11/28] chore(setup.py): eliminate deprecation warnings --- setup.py | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/setup.py b/setup.py index a65401eb8..ffd82ef16 100644 --- a/setup.py +++ b/setup.py @@ -127,7 +127,7 @@ def _get_openmp_flags(): return ['/openmp'], [] elif sys.platform == 'darwin': if (os.environ.get('CC') is not None and - os.environ.get('CXX') is not None): + os.environ.get('CXX') is not None): return ['-fopenmp'], ['-fopenmp'] else: return ['-Xpreprocessor', '-fopenmp'], ['-lomp'] @@ -152,6 +152,7 @@ def get_openmp_flags(): import shutil import tempfile test_code = dedent(""" + # cython: language_level=3, distutils: language=c++ from cython.parallel import parallel, prange, threadid cimport openmp def n_threads(): @@ -340,7 +341,6 @@ def get_basic_extensions(): sources=["pysph/base/particle_array.pyx"], include_dirs=include_dirs, extra_compile_args=extra_compile_args, - language="c++", define_macros=MACROS, ), @@ -349,7 +349,6 @@ def get_basic_extensions(): sources=["pysph/base/point.pyx"], extra_compile_args=extra_compile_args, include_dirs=include_dirs, - language="c++", define_macros=MACROS, ), @@ -364,7 +363,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -379,7 +377,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -393,7 +390,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -407,7 +403,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -421,7 +416,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -436,7 +430,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -450,7 +443,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -464,7 +456,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -478,7 +469,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -492,7 +482,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -502,7 +491,6 @@ def get_basic_extensions(): sources=["pysph/base/c_kernels.pyx"], include_dirs=include_dirs, extra_compile_args=extra_compile_args, - language="c++", define_macros=MACROS, ), @@ -512,7 +500,6 @@ def get_basic_extensions(): sources=["pysph/base/linalg3.pyx"], include_dirs=include_dirs, extra_compile_args=extra_compile_args, - language="c++", define_macros=MACROS, ), @@ -522,7 +509,6 @@ def get_basic_extensions(): sources=["pysph/tools/mesh_tools.pyx"], include_dirs=include_dirs, extra_compile_args=extra_compile_args, - language="c++", define_macros=MACROS, ), @@ -541,7 +527,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -555,7 +540,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), Extension( @@ -568,7 +552,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), Extension( @@ -581,7 +564,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, )) ) @@ -635,7 +617,6 @@ def get_parallel_extensions(): extra_link_args=mpi_link_args, extra_compile_args=mpi_compile_args + extra_compile_args, cython_compile_time_env=cython_compile_time_env, - language="c++", define_macros=MACROS, ), ] @@ -723,7 +704,6 @@ def setup_package(): ext_modules = cythonize( ext_modules, compile_time_env=compile_env, include_path=list(include_path), - language="c++", compiler_directives=COMPILER_DIRECTIVES, ) From 0f9b4b998a8514f20ec909cd9552702b729d74ae Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sun, 22 Sep 2024 01:48:26 +0530 Subject: [PATCH 12/28] chore: no problem if cython removes `IF` Ref https://github.com/cython/cython/issues/4310 --- pysph/base/nnps.py | 1 - pysph/base/nnps_base.pxd | 2 -- pysph/base/nnps_base.pyx | 23 ++++++----------------- pysph/base/no_omp_threads.pxd | 2 ++ pysph/base/no_omp_threads.pyx | 6 ++++++ pysph/base/octree.pyx | 7 +++++++ pysph/base/omp_threads.pxd | 2 ++ pysph/base/omp_threads.pyx | 13 +++++++++++++ setup.py | 28 +++++++++++++++++++++++++--- 9 files changed, 61 insertions(+), 23 deletions(-) create mode 100644 pysph/base/no_omp_threads.pxd create mode 100644 pysph/base/no_omp_threads.pyx create mode 100644 pysph/base/omp_threads.pxd create mode 100644 pysph/base/omp_threads.pyx diff --git a/pysph/base/nnps.py b/pysph/base/nnps.py index aea2687f6..8e0d2efed 100644 --- a/pysph/base/nnps.py +++ b/pysph/base/nnps.py @@ -1,6 +1,5 @@ from pysph.base.nnps_base import get_number_of_threads, py_flatten, \ py_unflatten, py_get_valid_cell_index - from pysph.base.nnps_base import NNPSParticleArrayWrapper, CPUDomainManager, \ DomainManager, Cell, NeighborCache, NNPSBase, NNPS from pysph.base.linked_list_nnps import LinkedListNNPS diff --git a/pysph/base/nnps_base.pxd b/pysph/base/nnps_base.pxd index b7317d036..1999797cb 100644 --- a/pysph/base/nnps_base.pxd +++ b/pysph/base/nnps_base.pxd @@ -136,8 +136,6 @@ cdef cIntPoint find_cell_id(cPoint pnt, double cell_size) cpdef UIntArray arange_uint(int start, int stop=*) -cpdef int get_number_of_threads() - # Basic particle array wrapper used for NNPS cdef class NNPSParticleArrayWrapper: cdef public DoubleArray x,y,z,h diff --git a/pysph/base/nnps_base.pyx b/pysph/base/nnps_base.pyx index 2ad864fa2..5e1411cf1 100644 --- a/pysph/base/nnps_base.pyx +++ b/pysph/base/nnps_base.pyx @@ -30,23 +30,6 @@ from compyle.array import get_backend, Array from compyle.parallel import Elementwise from compyle.types import annotate - -IF OPENMP: - cimport openmp - cpdef int get_number_of_threads(): - cdef int i, n - with nogil, parallel(): - for i in prange(1): - n = openmp.omp_get_num_threads() - return n - cpdef set_number_of_threads(int n): - openmp.omp_set_num_threads(n) -ELSE: - cpdef int get_number_of_threads(): - return 1 - cpdef set_number_of_threads(int n): - print("OpenMP not available, cannot set number of threads.") - # Particle Tag information from cyarray.carray cimport BaseArray, aligned_malloc, aligned_free from .utils import ParticleTAGS @@ -57,6 +40,12 @@ cdef int Ghost = ParticleTAGS.Ghost ctypedef pair[unsigned int, unsigned int] id_gid_pair_t +try: + from .omp_threads import get_number_of_threads + from .omp_threads import set_number_of_threads +except ImportError: + from .no_omp_threads import get_number_of_threads + from .no_omp_threads import set_number_of_threads cdef inline bint _compare_gids(id_gid_pair_t x, id_gid_pair_t y) noexcept nogil: return y.second > x.second diff --git a/pysph/base/no_omp_threads.pxd b/pysph/base/no_omp_threads.pxd new file mode 100644 index 000000000..831db0e5b --- /dev/null +++ b/pysph/base/no_omp_threads.pxd @@ -0,0 +1,2 @@ +cpdef int get_number_of_threads() +cpdef set_number_of_threads(int) \ No newline at end of file diff --git a/pysph/base/no_omp_threads.pyx b/pysph/base/no_omp_threads.pyx new file mode 100644 index 000000000..00f9eb185 --- /dev/null +++ b/pysph/base/no_omp_threads.pyx @@ -0,0 +1,6 @@ +cpdef int get_number_of_threads(): + return 1 + +cpdef set_number_of_threads(int n): + print("OpenMP not available, cannot set number of threads.") + diff --git a/pysph/base/octree.pyx b/pysph/base/octree.pyx index 0d6249ef8..4ba932e7e 100644 --- a/pysph/base/octree.pyx +++ b/pysph/base/octree.pyx @@ -30,6 +30,13 @@ cdef extern from *: void START_OMP_SINGLE_PRAGMA() noexcept nogil void START_OMP_BARRIER_PRAGMA() noexcept nogil +try: + from .omp_threads import get_number_of_threads + from .omp_threads import set_number_of_threads +except ImportError: + from .no_omp_threads import get_number_of_threads + from .no_omp_threads import set_number_of_threads + ######################################################################## cdef class OctreeNode: diff --git a/pysph/base/omp_threads.pxd b/pysph/base/omp_threads.pxd new file mode 100644 index 000000000..831db0e5b --- /dev/null +++ b/pysph/base/omp_threads.pxd @@ -0,0 +1,2 @@ +cpdef int get_number_of_threads() +cpdef set_number_of_threads(int) \ No newline at end of file diff --git a/pysph/base/omp_threads.pyx b/pysph/base/omp_threads.pyx new file mode 100644 index 000000000..3c3bc9394 --- /dev/null +++ b/pysph/base/omp_threads.pyx @@ -0,0 +1,13 @@ +from cython.parallel import parallel, prange +cimport openmp + + +cpdef int get_number_of_threads(): + cdef int i, n + with nogil, parallel(): + for i in prange(1): + n = openmp.omp_get_num_threads() + return n + +cpdef set_number_of_threads(int n): + openmp.omp_set_num_threads(n) \ No newline at end of file diff --git a/setup.py b/setup.py index ffd82ef16..f24b81446 100644 --- a/setup.py +++ b/setup.py @@ -335,7 +335,30 @@ def get_basic_extensions(): include_dirs += base_includes openmp_compile_args, openmp_link_args, openmp_env = get_openmp_flags() - ext_modules = [ + ext_modules = [] + if openmp_env: + ext_modules.append( + Extension( + name="pysph.base.omp_threads", + sources=["pysph/base/omp_threads.pyx"], + include_dirs=include_dirs, + extra_compile_args=extra_compile_args + openmp_compile_args, + extra_link_args=openmp_link_args, + language="c++", + define_macros=MACROS, + ) + ) + + ext_modules.extend([ + Extension( + name="pysph.base.no_omp_threads", + sources=["pysph/base/no_omp_threads.pyx"], + include_dirs=include_dirs, + extra_compile_args=extra_compile_args, + language="c++", + define_macros=MACROS, + ), + Extension( name="pysph.base.particle_array", sources=["pysph/base/particle_array.pyx"], @@ -511,8 +534,7 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args, define_macros=MACROS, ), - - ] + ]) # OpenCL related modules ext_modules.extend(( From bae1d82569003a736be03786b113bd4cffab64e3 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sun, 22 Sep 2024 04:51:36 +0530 Subject: [PATCH 13/28] chore(nnps_base.pyx): settle deprecation warnings --- pysph/base/nnps_base.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pysph/base/nnps_base.pyx b/pysph/base/nnps_base.pyx index 5e1411cf1..3a70d4389 100644 --- a/pysph/base/nnps_base.pyx +++ b/pysph/base/nnps_base.pyx @@ -522,7 +522,7 @@ cdef class CPUDomainManager(DomainManagerBase): # mirror domain values cdef double xmin = self.xmin, xmax = self.xmax - cdef double ymin = self.ymin, ymax = self.ymax, + cdef double ymin = self.ymin, ymax = self.ymax cdef double zmin = self.zmin, zmax = self.zmax # mirror boundary condition flags @@ -768,7 +768,7 @@ cdef class CPUDomainManager(DomainManagerBase): # periodic domain values cdef double xmin = self.xmin, xmax = self.xmax - cdef double ymin = self.ymin, ymax = self.ymax, + cdef double ymin = self.ymin, ymax = self.ymax cdef double zmin = self.zmin, zmax = self.zmax cdef double xtranslate = self.xtranslate From 47d46f25ce78f79be86708fc8eca2fdfc6d238c2 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sun, 22 Sep 2024 05:00:16 +0530 Subject: [PATCH 14/28] chore(cell_indexing_nnps): settle deprecation warnings --- pysph/base/cell_indexing_nnps.pyx | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pysph/base/cell_indexing_nnps.pyx b/pysph/base/cell_indexing_nnps.pyx index 718edf959..a15525262 100644 --- a/pysph/base/cell_indexing_nnps.pyx +++ b/pysph/base/cell_indexing_nnps.pyx @@ -52,7 +52,7 @@ cdef class CellIndexingNNPS(NNPS): cdef NNPSParticleArrayWrapper pa_wrapper cdef int i, num_particles - for i from 0<=i self.pa_wrappers[i] num_particles = pa_wrapper.get_number_of_particles() @@ -80,7 +80,7 @@ cdef class CellIndexingNNPS(NNPS): def __dealloc__(self): cdef int i - for i from 0<=iself._get_id(current_keys[j], pa_index)) @@ -240,7 +240,7 @@ cdef class CellIndexingNNPS(NNPS): cdef int i, n cdef int c_x, c_y, c_z - for i from 0<=i=0 and j+q>=0 and k+p>=0: x[length] = i+r y[length] = j+q @@ -343,7 +343,7 @@ cdef class CellIndexingNNPS(NNPS): self.J = (1 + log2(ceil((xmax[0] - xmin[0])/self.cell_size))) self.K = (1 + log2(ceil((xmax[1] - xmin[1])/self.cell_size))) - for i from 0<=i Date: Sun, 22 Sep 2024 05:04:34 +0530 Subject: [PATCH 15/28] chore(octree): settle deprecation warnings --- pysph/base/octree.pxd | 4 +- pysph/base/octree.pyx | 152 +++++++++++++++++++++--------------------- 2 files changed, 78 insertions(+), 78 deletions(-) diff --git a/pysph/base/octree.pxd b/pysph/base/octree.pxd index d37934990..c396719d9 100644 --- a/pysph/base/octree.pxd +++ b/pysph/base/octree.pxd @@ -77,8 +77,8 @@ cdef class Octree: cdef public bint test_parallel cdef double machine_eps - cdef double xmin[3] - cdef double xmax[3] + cdef double [3]xmin + cdef double [3]xmax ########################################################################## # Member functions diff --git a/pysph/base/octree.pyx b/pysph/base/octree.pyx index 4ba932e7e..049fb9cfe 100644 --- a/pysph/base/octree.pyx +++ b/pysph/base/octree.pyx @@ -62,7 +62,7 @@ cdef class OctreeNode: equal_length = (self.length == other.length) cdef int i - for i from 0<=i<3: + for i in range(3): if self.xmin[i] != other.xmin[i]: equal_xmin = False @@ -140,7 +140,7 @@ cdef class OctreeNode: cdef int i cdef list py_children = [None for i in range(8)] cdef OctreeNode py_node - for i from 0<=i<8: + for i in range(8): if self._node.children[i] != NULL: py_node = OctreeNode() py_node.wrap_node(self._node.children[i]) @@ -164,29 +164,29 @@ cdef class OctreeNode: cdef double x, y, z cdef list ax_points = [0,0] - for i from 0<=i<2: - for j from 0<=j<2: + for i in range(2): + for j in range(2): x = self.xmin[0] + i*self.length y = self.xmin[1] + j*self.length - for k from 0<=k<2: + for k in range(2): ax_points[k] = self.xmin[2] + k*self.length ax.plot([x,x], [y,y], zs=ax_points[:], color=color) - for i from 0<=i<2: - for k from 0<=k<2: + for i in range(2): + for k in range(2): x = self.xmin[0] + i*self.length z = self.xmin[2] + k*self.length - for j from 0<=j<2: + for j in range(2): ax_points[j] = self.xmin[1] + j*self.length ax.plot([x,x], ax_points[:], zs=[z,z], color=color) - for j from 0<=j<2: - for k from 0<=k<2: + for j in range(2): + for k in range(2): y = self.xmin[1] + j*self.length z = self.xmin[2] + k*self.length - for i from 0<=i<2: + for i in range(2): ax_points[i] = self.xmin[0] + i*self.length ax.plot(ax_points[:], [y,y], zs=[z,z], color=color) @@ -266,7 +266,7 @@ cdef class Octree: cdef int i - for i from 0<=i<8: + for i in range(8): node.children[i] = NULL return node @@ -276,12 +276,12 @@ cdef class Octree: cdef int i cdef cOctreeNode* temp[8] - for i from 0<=i<8: + for i in range(8): temp[i] = node.children[i] free(node) - for i from 0<=i<8: + for i in range(8): if temp[i] == NULL: continue self._delete_tree(temp[i]) @@ -303,7 +303,7 @@ cdef class Octree: cdef int i, j, k cdef u_int p, q - for i from 0<=i<8: + for i in range(8): hmax_children[i] = 0 cdef int oct_id @@ -322,10 +322,10 @@ cdef class Octree: return 1 cdef vector[u_int]* new_indices[8] - for i from 0<=i<8: + for i in range(8): new_indices[i] = new vector[u_int]() - for p from 0<=p EPS_MAX): - for i from 0<=i 0): - for i from 0<=i<8: + for i in range(8): new_indices[i] = vector[u_int]() children = 0 - for n from 0<=npy_leaf_cells[i]).wrap_node(deref(self.leaf_cells)[i]) return py_leaf_cells @@ -863,9 +863,9 @@ cdef class CompressedOctree(Octree): cdef int i, j, k cdef u_int p, q - for i from 0<=i<8: + for i in range(8): hmax_children[i] = 0 - for j from 0<=j<3: + for j in range(3): xmin_new[i][j] = self.dbl_max xmax_new[i][j] = -self.dbl_max @@ -881,13 +881,13 @@ cdef class CompressedOctree(Octree): return 1 cdef vector[u_int]* new_indices[8] - for i from 0<=i<8: + for i in range(8): new_indices[i] = new vector[u_int]() cdef double* xmin_current cdef double* xmax_current - for p from 0<=p malloc(3 * sizeof(double)) xmax_new[i] = malloc(3 * sizeof(double)) tid = threadid() while(count[num_threads]>0): - for i from 0<=i<8: + for i in range(8): new_indices[i] = vector[u_int]() children = 0 - for n from 0<=n Date: Sun, 22 Sep 2024 05:06:44 +0530 Subject: [PATCH 16/28] chore(octree_nnps): settle deprecation warnings --- pysph/base/octree_nnps.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pysph/base/octree_nnps.pyx b/pysph/base/octree_nnps.pyx index 0a25f69fb..e63f89960 100644 --- a/pysph/base/octree_nnps.pyx +++ b/pysph/base/octree_nnps.pyx @@ -124,7 +124,7 @@ cdef class OctreeNNPS(NNPS): return if node.is_leaf: - for i from 0<=iself.tree[pa_index]).pids cdef int i - for i from 0<=icurrent_pids[i]) cpdef _refresh(self): cdef int i - for i from 0<=iself.tree[i]).c_build_tree(self.pa_wrappers[i], self.tree[i].test_parallel) self.current_tree = (self.tree[self.src_index]).root self.current_pids = (self.tree[self.src_index]).pids @@ -221,7 +221,7 @@ cdef class CompressedOctreeNNPS(OctreeNNPS): cpdef _refresh(self): cdef int i - for i from 0<=iself.tree[i]).c_build_tree(self.pa_wrappers[i], self.tree[i].test_parallel) self.current_tree = (self.tree[self.src_index]).root From e3c4f73cec16b52c93c71b7ccbcc66a1c3e911f7 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sun, 22 Sep 2024 05:08:11 +0530 Subject: [PATCH 17/28] chore(spatial_hash_nnps): settle deprecation warnings --- pysph/base/spatial_hash_nnps.pxd | 2 +- pysph/base/spatial_hash_nnps.pyx | 50 ++++++++++++++++---------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pysph/base/spatial_hash_nnps.pxd b/pysph/base/spatial_hash_nnps.pxd index 0362f1a34..226c0a22c 100644 --- a/pysph/base/spatial_hash_nnps.pxd +++ b/pysph/base/spatial_hash_nnps.pxd @@ -12,7 +12,7 @@ cdef extern from "spatial_hash.h": vector[unsigned int] *get_indices() noexcept nogil cdef cppclass HashTable: - HashTable(long long int) nogil except + + HashTable(long long int) except + nogil void add(int, int, int, int, double) noexcept nogil HashEntry* get(int, int, int) noexcept nogil diff --git a/pysph/base/spatial_hash_nnps.pyx b/pysph/base/spatial_hash_nnps.pyx index 487baa8f4..5b18827b1 100644 --- a/pysph/base/spatial_hash_nnps.pyx +++ b/pysph/base/spatial_hash_nnps.pyx @@ -47,14 +47,14 @@ cdef class SpatialHashNNPS(NNPS): self.hashtable = malloc(narrays*sizeof(HashTable*)) cdef int i - for i from 0<=i=0 and j+q>=0 and k+r>=0: x[length] = i+p y[length] = j+q @@ -175,7 +175,7 @@ cdef class SpatialHashNNPS(NNPS): cpdef _refresh(self): cdef int i - for i from 0<=i malloc(narrays*sizeof(HashTable*)) cdef int i - for i from 0<=i Date: Sun, 22 Sep 2024 05:16:32 +0530 Subject: [PATCH 18/28] chore(stratified_hash_nnps): settle deprecation warnings --- pysph/base/stratified_hash_nnps.pxd | 2 +- pysph/base/stratified_hash_nnps.pyx | 30 ++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pysph/base/stratified_hash_nnps.pxd b/pysph/base/stratified_hash_nnps.pxd index 38babdce6..b7de141bd 100644 --- a/pysph/base/stratified_hash_nnps.pxd +++ b/pysph/base/stratified_hash_nnps.pxd @@ -24,7 +24,7 @@ cdef extern from "spatial_hash.h": cdef cppclass HashTable: long long int table_size - HashTable(long long int) nogil except + + HashTable(long long int) except + nogil void add(int, int, int, int, double) noexcept nogil HashEntry* get(int, int, int) noexcept nogil int number_of_particles() noexcept nogil diff --git a/pysph/base/stratified_hash_nnps.pyx b/pysph/base/stratified_hash_nnps.pyx index 5f76a044d..e889549e5 100644 --- a/pysph/base/stratified_hash_nnps.pyx +++ b/pysph/base/stratified_hash_nnps.pyx @@ -56,11 +56,11 @@ cdef class StratifiedHashNNPS(NNPS): self.cell_sizes = malloc(narrays*sizeof(double*)) cdef int i, j - for i from 0<=i malloc(self.num_levels*sizeof(HashTable*)) self.cell_sizes[i] = malloc(self.num_levels*sizeof(double)) current_hash = self.hashtable[i] - for j from 0<=j= 0 and j + y_mask[p] >= 0 and k + z_mask[p] >= 0): @@ -268,7 +268,7 @@ cdef class StratifiedHashNNPS(NNPS): int num_particles) noexcept nogil: cdef double h cdef int i, idx - for i from 0<=i Date: Sun, 22 Sep 2024 05:28:12 +0530 Subject: [PATCH 19/28] chore(stratified_sfc_gpu_nnps): settle deprecation warnings --- pysph/base/stratified_sfc_gpu_nnps.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pysph/base/stratified_sfc_gpu_nnps.pyx b/pysph/base/stratified_sfc_gpu_nnps.pyx index 413cf177c..00294ae55 100644 --- a/pysph/base/stratified_sfc_gpu_nnps.pyx +++ b/pysph/base/stratified_sfc_gpu_nnps.pyx @@ -78,7 +78,7 @@ cdef class StratifiedSFCGPUNNPS(GPUNNPS): else: self.interval_size = self.hmin*self.eps - for i from 0<=iself.pa_wrappers[i] num_particles = pa_wrapper.get_number_of_particles() From d4b8f99bc9edc7603cb8e8ec6c36cd8571b2e4c9 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sun, 22 Sep 2024 05:28:57 +0530 Subject: [PATCH 20/28] chore(stratified_sfc_nnps): settle deprecation warnings --- pysph/base/stratified_sfc_nnps.pxd | 6 +-- pysph/base/stratified_sfc_nnps.pyx | 64 +++++++++++++++--------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pysph/base/stratified_sfc_nnps.pxd b/pysph/base/stratified_sfc_nnps.pxd index a59183bda..10dcd185b 100644 --- a/pysph/base/stratified_sfc_nnps.pxd +++ b/pysph/base/stratified_sfc_nnps.pxd @@ -21,12 +21,12 @@ cdef extern from 'math.h': cdef extern from "z_order.h": ctypedef unsigned int uint32_t ctypedef unsigned long long uint64_t - inline uint64_t get_key(uint64_t i, uint64_t j, uint64_t k) nogil + uint64_t get_key(uint64_t i, uint64_t j, uint64_t k) nogil cdef cppclass CompareSortWrapper: - CompareSortWrapper() nogil except + + CompareSortWrapper() except + CompareSortWrapper(uint32_t* current_pids, uint64_t* current_keys, - int length) nogil except + + int length) except + nogil inline void compare_sort() noexcept nogil cdef class StratifiedSFCNNPS(NNPS): diff --git a/pysph/base/stratified_sfc_nnps.pyx b/pysph/base/stratified_sfc_nnps.pyx index 4c2cc04c1..72cbd2873 100644 --- a/pysph/base/stratified_sfc_nnps.pyx +++ b/pysph/base/stratified_sfc_nnps.pyx @@ -82,14 +82,14 @@ cdef class StratifiedSFCNNPS(NNPS): self.total_mask_len = malloc(narrays*sizeof(int)) cdef int i, j, num_particles - for i from 0<=i malloc(self.num_levels*sizeof(int*)) self.key_to_nbr_idx[i] = malloc(self.num_levels*sizeof(int*)) self.key_to_nbr_length[i] = malloc(self.num_levels*sizeof(int*)) - for j from 0<=j= 0 and num_boxes > 0): return - for i from start_idx<=i \ self.pa_wrappers[pa_index]).get_number_of_particles() keys = np.empty(num_particles) - for i from 0<=i> self.max_num_bits @@ -505,7 +505,7 @@ cdef class StratifiedSFCNNPS(NNPS): current_key_to_nbr_idx_level[key_bottom] = n - for k from 0<=k \ self.pa_wrappers[i]).get_number_of_particles() if self.pids[i] != NULL: @@ -602,7 +602,7 @@ cdef class StratifiedSFCNNPS(NNPS): self.pids[i] = malloc(num_particles*sizeof(uint32_t)) self.keys[i] = malloc(num_particles*sizeof(uint64_t)) current_cells = self.cell_sizes[i] - for j from 0<=j malloc(self.max_possible_key * sizeof(int)) current_key_to_nbr_length[j] = malloc(self.max_possible_key * sizeof(int)) current_key_to_nbr_idx_level = current_key_to_nbr_idx[j] current_key_to_nbr_length_level = current_key_to_nbr_length[j] - for key_iter from 0<=key_iter malloc(max_key * sizeof(int)) current_hmax[i] = malloc(max_key * sizeof(double)) key_idx_level = current_key_to_idx[i] hmax_level = current_hmax[i] current_num_cells[i] = 0 - for j from 0<=j> self.max_num_bits From d30cda35558ab19a5b6ff0b63e078c49210f2045 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sun, 22 Sep 2024 05:30:04 +0530 Subject: [PATCH 21/28] chore(z_order_gpu_nnps): settle deprecation warnings --- pysph/base/z_order_gpu_nnps.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pysph/base/z_order_gpu_nnps.pyx b/pysph/base/z_order_gpu_nnps.pyx index 5a2ec5c8a..33832e20d 100644 --- a/pysph/base/z_order_gpu_nnps.pyx +++ b/pysph/base/z_order_gpu_nnps.pyx @@ -66,7 +66,7 @@ cdef class ZOrderGPUNNPS(GPUNNPS): self.cids = [] self.cid_to_idx = [] - for i from 0<=iself.pa_wrappers[i] num_particles = pa_wrapper.get_number_of_particles() @@ -180,7 +180,7 @@ cdef class ZOrderGPUNNPS(GPUNNPS): self.max_cid = [] self.sorted = False - for i from 0<=iself.pa_wrappers[i] num_particles = pa_wrapper.get_number_of_particles() From b2c090011b52bb0ad0746ec5988eecd196ac2549 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sun, 22 Sep 2024 05:30:35 +0530 Subject: [PATCH 22/28] chore(z_order_nnps): settle deprecation warnings --- pysph/base/z_order_nnps.pxd | 6 +-- pysph/base/z_order_nnps.pyx | 88 ++++++++++++++++++------------------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/pysph/base/z_order_nnps.pxd b/pysph/base/z_order_nnps.pxd index ac15aaa4a..b6d393bac 100644 --- a/pysph/base/z_order_nnps.pxd +++ b/pysph/base/z_order_nnps.pxd @@ -11,12 +11,12 @@ cdef extern from "math.h": cdef extern from "z_order.h": ctypedef unsigned long long uint64_t ctypedef unsigned int uint32_t - inline uint64_t get_key(uint64_t i, uint64_t j, uint64_t k) nogil + uint64_t get_key(uint64_t i, uint64_t j, uint64_t k) nogil cdef cppclass CompareSortWrapper: - CompareSortWrapper() nogil except + + CompareSortWrapper() except + nogil CompareSortWrapper(uint32_t* current_pids, uint64_t* current_keys, - int length) nogil except + + int length) except + nogil inline void compare_sort() nogil ctypedef map[uint64_t, pair[uint32_t, uint32_t]] key_to_idx_t diff --git a/pysph/base/z_order_nnps.pyx b/pysph/base/z_order_nnps.pyx index afb170920..ff1144e1d 100644 --- a/pysph/base/z_order_nnps.pyx +++ b/pysph/base/z_order_nnps.pyx @@ -66,7 +66,7 @@ cdef class ZOrderNNPS(NNPS): self.key_to_idx = malloc(narrays*sizeof(int*)) cdef int i - for i from 0<=icurrent_pids[j]) cdef int fill_array(self, NNPSParticleArrayWrapper pa_wrapper, int pa_index, @@ -263,7 +263,7 @@ cdef class ZOrderNNPS(NNPS): cdef int c_x, c_y, c_z cdef int i, n - for i from 0<=i \ self.pa_wrappers[pa_index]).get_number_of_particles() keys = np.empty(num_particles) - for i from 0<=i=0 and j+q>=0 and k+p>=0: key = get_key(i+r, j+q, k+p) found_idx = self.get_idx(key, current_key_to_idx) @@ -530,7 +530,7 @@ cdef class ZOrderNNPS(NNPS): cdef uint64_t max_key = 1 + get_key(c_x, c_y, c_z) self.max_key = max_key - for i from 0<=i Date: Sun, 22 Sep 2024 05:31:11 +0530 Subject: [PATCH 23/28] chore(point.pyx): settle deprecation warnings --- pysph/base/point.pyx | 58 +++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/pysph/base/point.pyx b/pysph/base/point.pyx index 46dc9c0e8..fd61d9ce4 100644 --- a/pysph/base/point.pyx +++ b/pysph/base/point.pyx @@ -27,23 +27,27 @@ cdef class Point: # Declared in the .pxd file. #cdef public double x, y, z - property x: - def __get__(Point self): - return self.data.x - def __set__(Point self, double x): - self.data.x = x - - property y: - def __get__(Point self): - return self.data.y - def __set__(Point self, double y): - self.data.y = y - - property z: - def __get__(Point self): - return self.data.z - def __set__(Point self, double z): - self.data.z = z + @property + def x(Point self): + return self.data.x + @x.setter + def x(Point self, double x): + self.data.x = x + + @property + def y(Point self): + return self.data.y + @y.setter + def y(Point self, double y): + self.data.y = y + + + @property + def z(Point self): + return self.data.z + @z.setter + def z(Point self, double z): + self.data.z = z ###################################################################### # `object` interface. @@ -191,17 +195,15 @@ cdef class Point: cdef class IntPoint: - property x: - def __get__(self): - return self.data.x - - property y: - def __get__(self): - return self.data.y - - property z: - def __get__(self): - return self.data.z + @property + def x(self): + return self.data.x + @property + def y(self): + return self.data.y + @property + def z(self): + return self.data.z def __init__(self, int x=0, int y=0, int z=0): self.data.x = x From 6e5be66144abf4334add1e427a90f085797a449a Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Sun, 22 Sep 2024 05:31:43 +0530 Subject: [PATCH 24/28] chore(linalg3): settle deprecation warnings --- pysph/base/linalg3.pxd | 14 +++++++------- pysph/base/linalg3.pyx | 38 +++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pysph/base/linalg3.pxd b/pysph/base/linalg3.pxd index 86d4cd8f2..5cfc57c7d 100644 --- a/pysph/base/linalg3.pxd +++ b/pysph/base/linalg3.pxd @@ -3,11 +3,11 @@ """Routines for eigen decomposition of symmetric 3x3 matrices. """ -cdef double det(double a[3][3]) noexcept nogil -cdef void get_eigenvalues(double a[3][3], double *result) noexcept nogil -cdef void eigen_decomposition(double A[3][3], double V[3][3], double *d) noexcept nogil -cdef void transform(double A[3][3], double P[3][3], double res[3][3]) noexcept nogil -cdef void transform_diag(double *A, double P[3][3], double res[3][3]) noexcept nogil -cdef void transform_diag_inv(double *A, double P[3][3], double res[3][3]) nogil +cdef double det(double [3][3]a) noexcept nogil +cdef void get_eigenvalues(double [3][3]a, double *result) noexcept nogil +cdef void eigen_decomposition(double [3][3]A, double [3][3]V, double *d) noexcept nogil +cdef void transform(double [3][3]A, double [3][3]P, double [3][3]res) noexcept nogil +cdef void transform_diag(double *A, double [3][3]P, double [3][3]res) noexcept nogil +cdef void transform_diag_inv(double *A, double [3][3]P, double [3][3]res) nogil -cdef void get_eigenvalvec(double A[3][3], double *R, double *e) +cdef void get_eigenvalvec(double [3][3]A, double *R, double *e) diff --git a/pysph/base/linalg3.pyx b/pysph/base/linalg3.pyx index b8ba16378..490762719 100644 --- a/pysph/base/linalg3.pyx +++ b/pysph/base/linalg3.pyx @@ -30,7 +30,7 @@ cdef inline double hypot2(double x, double y) noexcept nogil: return sqrt(x*x+y*y) -cdef double det(double a[3][3]) noexcept nogil: +cdef double det(double [3][3]a) noexcept nogil: '''Determinant of symmetrix matrix ''' return (a[0][0]*a[1][1]*a[2][2] + 2*a[1][2]*a[0][2]*a[0][1] - @@ -46,12 +46,12 @@ cpdef double py_det(double[:,:] m): # d:11,22,33; s:23,13,12 # d:00,11,22; s:12,02,01 -cdef void get_eigenvalues(double a[3][3], double *result) noexcept nogil: +cdef void get_eigenvalues(double [3][3]a, double *result) noexcept nogil: '''Compute the eigenvalues of symmetric matrix a and return in result array. ''' cdef double m = (a[0][0]+ a[1][1]+a[2][2])/3.0 - cdef double K[3][3] + cdef double [3][3]K memcpy(&K[0][0], &a[0][0], sizeof(double)*9) K[0][0], K[1][1], K[2][2] = a[0][0] - m, a[1][1] - m, a[2][2] - m cdef double q = det(K)*0.5 @@ -89,7 +89,7 @@ cpdef py_get_eigenvalues(double[:,:] m): ############################################################################## -cdef void get_eigenvector_np(double A[n][n], double r, double *res): +cdef void get_eigenvector_np(double [n][n]A, double r, double *res): ''' eigenvector of symmetric matrix for given eigenvalue `r` using numpy ''' cdef numpy.ndarray[ndim=2, dtype=numpy.float64_t] mat=numpy.empty((3,3)), evec @@ -109,7 +109,7 @@ cdef void get_eigenvector_np(double A[n][n], double r, double *res): for i in range(3): res[i] = evec[idx,i] -cdef void get_eigenvector(double A[n][n], double r, double *res): +cdef void get_eigenvector(double [n][n]A, double r, double *res): ''' get eigenvector of symmetric 3x3 matrix for given eigenvalue `r` uses a fast method to get eigenvectors with a fallback to using numpy @@ -134,22 +134,22 @@ cpdef py_get_eigenvector(double[:,:] A, double r): get_eigenvector(&A[0,0], r, &_d[0]) return d -cdef void get_eigenvec_from_val(double A[n][n], double *R, double *e): +cdef void get_eigenvec_from_val(double [n][n]A, double *R, double *e): cdef int i, j - cdef double res[3] + cdef double [3]res for i in range(3): get_eigenvector(A, e[i], &res[0]) for j in range(3): R[j*3+i] = res[j] -cdef bint _nearly_diagonal(double A[n][n]) noexcept nogil: +cdef bint _nearly_diagonal(double [n][n]A) noexcept nogil: return ( (SQR(A[0][0]) + SQR(A[1][1]) + SQR(A[2][2])) > 1e8*(SQR(A[0][1]) + SQR(A[0][2]) + SQR(A[1][2])) ) -cdef void get_eigenvalvec(double A[n][n], double *R, double *e): +cdef void get_eigenvalvec(double [n][n]A, double *R, double *e): '''Get the eigenvalues and eigenvectors of symmetric 3x3 matrix. A is the input 3x3 matrix. @@ -194,7 +194,7 @@ def py_get_eigenvalvec(double[:,:] A): ############################################################################## -cdef void transform(double A[3][3], double P[3][3], double res[3][3]) noexcept nogil: +cdef void transform(double [3][3]A, double [3][3]P, double [3][3]res) noexcept nogil: '''Compute the transformation P.T*A*P and add it into res. ''' cdef int i, j, k, l @@ -204,8 +204,8 @@ cdef void transform(double A[3][3], double P[3][3], double res[3][3]) noexcept n for l in range(3): res[i][j] += P[k][i]*A[k][l]*P[l][j] # P.T*A*P -cdef void transform_diag(double *A, double P[3][3], - double res[3][3]) noexcept nogil: +cdef void transform_diag(double *A, double [3][3]P, + double [3][3]res) noexcept nogil: '''Compute the transformation P.T*A*P and add it into res. A is diagonal and contains the diagonal entries alone. @@ -216,8 +216,8 @@ cdef void transform_diag(double *A, double P[3][3], for k in range(3): res[i][j] += P[k][i]*A[k]*P[k][j] # P.T*A*P -cdef void transform_diag_inv(double *A, double P[3][3], - double res[3][3]) noexcept nogil: +cdef void transform_diag_inv(double *A, double [3][3]P, + double [3][3]res) noexcept nogil: '''Compute the transformation P*A*P.T and set it into res. A is diagonal and contains just the diagonal entries. ''' @@ -257,7 +257,7 @@ def py_transform_diag_inv(double[:] A, double[:,:] P): return res -cdef double * tred2(double V[n][n], double *d, double *e) noexcept nogil: +cdef double * tred2(double [n][n]V, double *d, double *e) noexcept nogil: '''Symmetric Householder reduction to tridiagonal form This is derived from the Algol procedures tred2 by @@ -376,7 +376,7 @@ cdef double * tred2(double V[n][n], double *d, double *e) noexcept nogil: return d -cdef void tql2(double V[n][n], double *d, double *e) noexcept nogil: +cdef void tql2(double [n][n]V, double *d, double *e) noexcept nogil: '''Symmetric tridiagonal QL algo for eigendecomposition This is derived from the Algol procedures tql2, by @@ -492,18 +492,18 @@ cdef void tql2(double V[n][n], double *d, double *e) noexcept nogil: V[j][k] = p -cdef void zero_matrix_case(double V[n][n], double *d) noexcept nogil: +cdef void zero_matrix_case(double [n][n]V, double *d) noexcept nogil: cdef int i, j for i in range(3): d[i] = 0.0 for j in range(3): V[i][j] = (i==j) -cdef void eigen_decomposition(double A[n][n], double V[n][n], double *d) noexcept nogil: +cdef void eigen_decomposition(double [n][n]A, double [n][n]V, double *d) noexcept nogil: '''Get eigenvalues and eigenvectors of matrix A. V is output eigenvectors and d are the eigenvalues. ''' - cdef double e[n] + cdef double [n]e cdef int i, j # Scale the matrix, as if the matrix is tiny, floating point errors # creep up leading to zero division errors in tql2. This is From fa57cc3e64287d7c3f261e0256643a55e5ad3e7a Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:44:35 +0530 Subject: [PATCH 25/28] chore(deps): build using numpy>2.0 Ref https://github.com/scipy/oldest-supported-numpy/blob/687ffc2f57e29ec7c74a28c58c247d16d0f6bee1/README.rst --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ece6eb950..6f6bed96c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ requires = [ "compyle>=0.8", "cyarray", "mako", - "oldest-supported-numpy", + "numpy>=2.0,<3", "pytools", "setuptools>=42.0.0", "wheel>=0.29.0", From fc8046de7c08ef6a0a89978b6673aef5adbe5a43 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Thu, 26 Sep 2024 12:38:03 +0530 Subject: [PATCH 26/28] ci(zoltan/mpi): pin mpi4py<4.0 --- .github/workflows/zoltan-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/zoltan-tests.yml b/.github/workflows/zoltan-tests.yml index 2209c800f..087b496c2 100644 --- a/.github/workflows/zoltan-tests.yml +++ b/.github/workflows/zoltan-tests.yml @@ -42,7 +42,7 @@ jobs: conda info conda install -c conda-forge numpy cython python -m pip install --upgrade pip setuptools wheel - python -m pip install mpi4py + python -m pip install "mpi4py<4.0" python -m pip install https://github.com/pypr/cyarray/zipball/master python -m pip install https://github.com/pypr/compyle/zipball/master python -m pip install --no-build-isolation https://github.com/pypr/pyzoltan/zipball/master From e33482e0589d722f0122a5c00d89c1e5f11cfaec Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Fri, 27 Sep 2024 00:49:22 +0530 Subject: [PATCH 27/28] chore: no more depend on pre-NumPy-1.7 C-API Ref: https://cython.readthedocs.io/en/3.0.x/src/userguide/migrating_to_cy30.html --- pysph/base/box_sort_nnps.pxd | 2 ++ pysph/base/box_sort_nnps.pyx | 5 ++++- pysph/base/cell_indexing_nnps.pxd | 5 ++++- pysph/base/cell_indexing_nnps.pyx | 1 + pysph/base/gpu_nnps_base.pxd | 2 ++ pysph/base/gpu_nnps_base.pyx | 1 + pysph/base/linalg3.pxd | 1 + pysph/base/linalg3.pyx | 1 + pysph/base/linked_list_nnps.pxd | 1 + pysph/base/linked_list_nnps.pyx | 2 ++ pysph/base/nnps_base.pxd | 2 ++ pysph/base/nnps_base.pyx | 2 ++ pysph/base/no_omp_threads.pxd | 4 ++++ pysph/base/no_omp_threads.pyx | 4 ++++ pysph/base/octree.pxd | 2 ++ pysph/base/octree.pyx | 4 +++- pysph/base/octree_gpu_nnps.pxd | 2 ++ pysph/base/octree_gpu_nnps.pyx | 5 ++++- pysph/base/octree_nnps.pxd | 1 + pysph/base/octree_nnps.pyx | 4 +++- pysph/base/omp_threads.pxd | 4 ++++ pysph/base/omp_threads.pyx | 4 ++++ pysph/base/particle_array.pxd | 5 ++++- pysph/base/particle_array.pyx | 2 ++ pysph/base/point.pxd | 2 ++ pysph/base/point.pyx | 4 +++- pysph/base/spatial_hash_nnps.pxd | 2 ++ pysph/base/spatial_hash_nnps.pyx | 1 + pysph/base/stratified_hash_nnps.pxd | 2 ++ pysph/base/stratified_hash_nnps.pyx | 4 +++- pysph/base/stratified_sfc_gpu_nnps.pxd | 2 ++ pysph/base/stratified_sfc_gpu_nnps.pyx | 1 + pysph/base/stratified_sfc_nnps.pxd | 2 ++ pysph/base/stratified_sfc_nnps.pyx | 4 +++- pysph/base/z_order_gpu_nnps.pxd | 2 ++ pysph/base/z_order_gpu_nnps.pyx | 4 +++- pysph/base/z_order_nnps.pxd | 2 ++ pysph/base/z_order_nnps.pyx | 1 + pysph/tools/mesh_tools.pyx | 4 ++++ 39 files changed, 93 insertions(+), 10 deletions(-) diff --git a/pysph/base/box_sort_nnps.pxd b/pysph/base/box_sort_nnps.pxd index fb1c0adf5..cc3daf452 100644 --- a/pysph/base/box_sort_nnps.pxd +++ b/pysph/base/box_sort_nnps.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.map cimport map from .nnps_base cimport * diff --git a/pysph/base/box_sort_nnps.pyx b/pysph/base/box_sort_nnps.pyx index 65637d4b2..6f0ecfb95 100644 --- a/pysph/base/box_sort_nnps.pyx +++ b/pysph/base/box_sort_nnps.pyx @@ -1,4 +1,7 @@ -# cython: language_level=3, language=c++, embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + # Library imports. import numpy as np cimport numpy as np diff --git a/pysph/base/cell_indexing_nnps.pxd b/pysph/base/cell_indexing_nnps.pxd index 2ea50cf5e..5c932e188 100644 --- a/pysph/base/cell_indexing_nnps.pxd +++ b/pysph/base/cell_indexing_nnps.pxd @@ -1,4 +1,7 @@ -# cython: language_level=3, language=c++, embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.map cimport map from libcpp.pair cimport pair diff --git a/pysph/base/cell_indexing_nnps.pyx b/pysph/base/cell_indexing_nnps.pyx index a15525262..38cc87a43 100644 --- a/pysph/base/cell_indexing_nnps.pyx +++ b/pysph/base/cell_indexing_nnps.pyx @@ -1,5 +1,6 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # malloc and friends from libc.stdlib cimport malloc, free diff --git a/pysph/base/gpu_nnps_base.pxd b/pysph/base/gpu_nnps_base.pxd index cc8bcd751..996e1026d 100644 --- a/pysph/base/gpu_nnps_base.pxd +++ b/pysph/base/gpu_nnps_base.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + # numpy cimport numpy as np cimport cython diff --git a/pysph/base/gpu_nnps_base.pyx b/pysph/base/gpu_nnps_base.pyx index 07dd46e8e..1d7ed26d5 100644 --- a/pysph/base/gpu_nnps_base.pyx +++ b/pysph/base/gpu_nnps_base.pyx @@ -1,5 +1,6 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # Library imports. import numpy as np diff --git a/pysph/base/linalg3.pxd b/pysph/base/linalg3.pxd index 5cfc57c7d..0f5bc25a9 100644 --- a/pysph/base/linalg3.pxd +++ b/pysph/base/linalg3.pxd @@ -1,5 +1,6 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION """Routines for eigen decomposition of symmetric 3x3 matrices. """ diff --git a/pysph/base/linalg3.pyx b/pysph/base/linalg3.pyx index 490762719..2ae0e2315 100644 --- a/pysph/base/linalg3.pyx +++ b/pysph/base/linalg3.pyx @@ -1,4 +1,5 @@ #cython: boundscheck=False +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # # Eigen decomposition code for symmetric 3x3 matrices, some code taken diff --git a/pysph/base/linked_list_nnps.pxd b/pysph/base/linked_list_nnps.pxd index b78c994fc..a40150104 100644 --- a/pysph/base/linked_list_nnps.pxd +++ b/pysph/base/linked_list_nnps.pxd @@ -1,5 +1,6 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION from libcpp.map cimport map from libcpp.vector cimport vector diff --git a/pysph/base/linked_list_nnps.pyx b/pysph/base/linked_list_nnps.pyx index 87a099ff0..2c3ff11ff 100644 --- a/pysph/base/linked_list_nnps.pyx +++ b/pysph/base/linked_list_nnps.pyx @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + # Library imports. import numpy as np cimport numpy as np diff --git a/pysph/base/nnps_base.pxd b/pysph/base/nnps_base.pxd index 1999797cb..cbb8c8c78 100644 --- a/pysph/base/nnps_base.pxd +++ b/pysph/base/nnps_base.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + # numpy cimport numpy as np cimport cython diff --git a/pysph/base/nnps_base.pyx b/pysph/base/nnps_base.pyx index 3a70d4389..ea31a2ae8 100644 --- a/pysph/base/nnps_base.pyx +++ b/pysph/base/nnps_base.pyx @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + # Library imports. import numpy as np cimport numpy as np diff --git a/pysph/base/no_omp_threads.pxd b/pysph/base/no_omp_threads.pxd index 831db0e5b..d95441868 100644 --- a/pysph/base/no_omp_threads.pxd +++ b/pysph/base/no_omp_threads.pxd @@ -1,2 +1,6 @@ +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + cpdef int get_number_of_threads() cpdef set_number_of_threads(int) \ No newline at end of file diff --git a/pysph/base/no_omp_threads.pyx b/pysph/base/no_omp_threads.pyx index 00f9eb185..b2bef1d6e 100644 --- a/pysph/base/no_omp_threads.pyx +++ b/pysph/base/no_omp_threads.pyx @@ -1,3 +1,7 @@ +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + cpdef int get_number_of_threads(): return 1 diff --git a/pysph/base/octree.pxd b/pysph/base/octree.pxd index c396719d9..0d5592d6e 100644 --- a/pysph/base/octree.pxd +++ b/pysph/base/octree.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from .nnps_base cimport * from libcpp.vector cimport vector cimport cython diff --git a/pysph/base/octree.pyx b/pysph/base/octree.pyx index 049fb9cfe..e70fc480d 100644 --- a/pysph/base/octree.pyx +++ b/pysph/base/octree.pyx @@ -1,4 +1,6 @@ -#cython: embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION from .nnps_base cimport * diff --git a/pysph/base/octree_gpu_nnps.pxd b/pysph/base/octree_gpu_nnps.pxd index 0c1556236..7794ab4a1 100644 --- a/pysph/base/octree_gpu_nnps.pxd +++ b/pysph/base/octree_gpu_nnps.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from pysph.base.gpu_nnps_base cimport * diff --git a/pysph/base/octree_gpu_nnps.pyx b/pysph/base/octree_gpu_nnps.pyx index 634ab2dc3..bad0ef413 100644 --- a/pysph/base/octree_gpu_nnps.pyx +++ b/pysph/base/octree_gpu_nnps.pyx @@ -1,4 +1,7 @@ -#cython: embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + import numpy as np cimport numpy as np from pysph.base.tree.point_tree import PointTree diff --git a/pysph/base/octree_nnps.pxd b/pysph/base/octree_nnps.pxd index e5ee774b4..dc5f6a13b 100644 --- a/pysph/base/octree_nnps.pxd +++ b/pysph/base/octree_nnps.pxd @@ -1,5 +1,6 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION from .nnps_base cimport * from .octree cimport Octree, CompressedOctree, cOctreeNode diff --git a/pysph/base/octree_nnps.pyx b/pysph/base/octree_nnps.pyx index e63f89960..b550d204e 100644 --- a/pysph/base/octree_nnps.pyx +++ b/pysph/base/octree_nnps.pyx @@ -1,4 +1,6 @@ -#cython: embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION from .nnps_base cimport * from .octree cimport Octree, CompressedOctree, cOctreeNode diff --git a/pysph/base/omp_threads.pxd b/pysph/base/omp_threads.pxd index 831db0e5b..d95441868 100644 --- a/pysph/base/omp_threads.pxd +++ b/pysph/base/omp_threads.pxd @@ -1,2 +1,6 @@ +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + cpdef int get_number_of_threads() cpdef set_number_of_threads(int) \ No newline at end of file diff --git a/pysph/base/omp_threads.pyx b/pysph/base/omp_threads.pyx index 3c3bc9394..83233e123 100644 --- a/pysph/base/omp_threads.pyx +++ b/pysph/base/omp_threads.pyx @@ -1,3 +1,7 @@ +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from cython.parallel import parallel, prange cimport openmp diff --git a/pysph/base/particle_array.pxd b/pysph/base/particle_array.pxd index 98c7bacc3..16854b1df 100644 --- a/pysph/base/particle_array.pxd +++ b/pysph/base/particle_array.pxd @@ -1,4 +1,7 @@ -# cython: language_level=3, language=c++, embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + cimport numpy as np from cyarray.carray cimport BaseArray, UIntArray, IntArray, LongArray diff --git a/pysph/base/particle_array.pyx b/pysph/base/particle_array.pyx index 43df0efc4..b19a96111 100644 --- a/pysph/base/particle_array.pyx +++ b/pysph/base/particle_array.pyx @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + """ A `ParticleArray` represents a collection of particles. diff --git a/pysph/base/point.pxd b/pysph/base/point.pxd index 0c25fe20d..4fddd20a1 100644 --- a/pysph/base/point.pxd +++ b/pysph/base/point.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + cimport numpy cdef extern from "math.h": diff --git a/pysph/base/point.pyx b/pysph/base/point.pyx index fd61d9ce4..f953ff4f5 100644 --- a/pysph/base/point.pyx +++ b/pysph/base/point.pyx @@ -1,4 +1,6 @@ -#cython: embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION """A handy set of classes/functions for 3D points. """ diff --git a/pysph/base/spatial_hash_nnps.pxd b/pysph/base/spatial_hash_nnps.pxd index 226c0a22c..bd3819f29 100644 --- a/pysph/base/spatial_hash_nnps.pxd +++ b/pysph/base/spatial_hash_nnps.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.vector cimport vector from .nnps_base cimport * diff --git a/pysph/base/spatial_hash_nnps.pyx b/pysph/base/spatial_hash_nnps.pyx index 5b18827b1..1d99b98ae 100644 --- a/pysph/base/spatial_hash_nnps.pyx +++ b/pysph/base/spatial_hash_nnps.pyx @@ -1,5 +1,6 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # malloc and friends from libc.stdlib cimport malloc, free diff --git a/pysph/base/stratified_hash_nnps.pxd b/pysph/base/stratified_hash_nnps.pxd index b7de141bd..d0336de5d 100644 --- a/pysph/base/stratified_hash_nnps.pxd +++ b/pysph/base/stratified_hash_nnps.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.vector cimport vector from .nnps_base cimport * diff --git a/pysph/base/stratified_hash_nnps.pyx b/pysph/base/stratified_hash_nnps.pyx index e889549e5..eb7e7820c 100644 --- a/pysph/base/stratified_hash_nnps.pyx +++ b/pysph/base/stratified_hash_nnps.pyx @@ -1,4 +1,6 @@ -#cython: embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # malloc and friends from libc.stdlib cimport malloc, free diff --git a/pysph/base/stratified_sfc_gpu_nnps.pxd b/pysph/base/stratified_sfc_gpu_nnps.pxd index 0325b413c..3ee580c75 100644 --- a/pysph/base/stratified_sfc_gpu_nnps.pxd +++ b/pysph/base/stratified_sfc_gpu_nnps.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.vector cimport vector from libcpp.map cimport map from libcpp.pair cimport pair diff --git a/pysph/base/stratified_sfc_gpu_nnps.pyx b/pysph/base/stratified_sfc_gpu_nnps.pyx index 00294ae55..022b76667 100644 --- a/pysph/base/stratified_sfc_gpu_nnps.pyx +++ b/pysph/base/stratified_sfc_gpu_nnps.pyx @@ -1,5 +1,6 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # malloc and friends from libc.stdlib cimport malloc, free diff --git a/pysph/base/stratified_sfc_nnps.pxd b/pysph/base/stratified_sfc_nnps.pxd index 10dcd185b..d5bd5e911 100644 --- a/pysph/base/stratified_sfc_nnps.pxd +++ b/pysph/base/stratified_sfc_nnps.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.vector cimport vector from libcpp.map cimport map from libcpp.pair cimport pair diff --git a/pysph/base/stratified_sfc_nnps.pyx b/pysph/base/stratified_sfc_nnps.pyx index 72cbd2873..ae1e78b0d 100644 --- a/pysph/base/stratified_sfc_nnps.pyx +++ b/pysph/base/stratified_sfc_nnps.pyx @@ -1,4 +1,6 @@ -#cython: embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # malloc and friends from libc.stdlib cimport malloc, free diff --git a/pysph/base/z_order_gpu_nnps.pxd b/pysph/base/z_order_gpu_nnps.pxd index 50a59981d..7b00b2189 100644 --- a/pysph/base/z_order_gpu_nnps.pxd +++ b/pysph/base/z_order_gpu_nnps.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.map cimport map from libcpp.pair cimport pair diff --git a/pysph/base/z_order_gpu_nnps.pyx b/pysph/base/z_order_gpu_nnps.pyx index 33832e20d..5076729bf 100644 --- a/pysph/base/z_order_gpu_nnps.pyx +++ b/pysph/base/z_order_gpu_nnps.pyx @@ -1,4 +1,6 @@ -#cython: embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # malloc and friends from libc.stdlib cimport malloc, free diff --git a/pysph/base/z_order_nnps.pxd b/pysph/base/z_order_nnps.pxd index b6d393bac..2871e3156 100644 --- a/pysph/base/z_order_nnps.pxd +++ b/pysph/base/z_order_nnps.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.map cimport map from libcpp.pair cimport pair diff --git a/pysph/base/z_order_nnps.pyx b/pysph/base/z_order_nnps.pyx index ff1144e1d..7aa7f1408 100644 --- a/pysph/base/z_order_nnps.pyx +++ b/pysph/base/z_order_nnps.pyx @@ -1,4 +1,5 @@ #cython: embedsignature=True +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # malloc and friends from libc.stdlib cimport malloc, free diff --git a/pysph/tools/mesh_tools.pyx b/pysph/tools/mesh_tools.pyx index a5eee6c14..198c87cff 100644 --- a/pysph/tools/mesh_tools.pyx +++ b/pysph/tools/mesh_tools.pyx @@ -1,4 +1,8 @@ +# cython: language_level=3, embedsignature=True +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from pysph.base.particle_array import ParticleArray + from pysph.base import nnps from pysph.tools.geometry import remove_repeated_points import numpy as np From 7bbf1cac2f9338e2d3439bf33289031d471c55e5 Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Fri, 27 Sep 2024 03:09:02 +0530 Subject: [PATCH 28/28] fix(test_equations): use numpy.all, not numpy.alltrue --- pysph/sph/tests/test_equations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pysph/sph/tests/test_equations.py b/pysph/sph/tests/test_equations.py index 10f86feef..0c54c7bb0 100644 --- a/pysph/sph/tests/test_equations.py +++ b/pysph/sph/tests/test_equations.py @@ -61,8 +61,8 @@ def test_basic_code_block(self): self.assertEqual(ctx.s_idx, 0) self.assertEqual(ctx.d_idx, 0) x = numpy.zeros(2, dtype=float) - self.assertTrue(numpy.alltrue(ctx.d_x == x)) - self.assertTrue(numpy.alltrue(ctx.s_x == x)) + self.assertTrue(numpy.all(ctx.d_x == x)) + self.assertTrue(numpy.all(ctx.s_x == x)) def test_that_code_block_is_callable(self): code = '''