From 58f9a882b2552b69cf858a3646e6b8064212a0f9 Mon Sep 17 00:00:00 2001 From: kinnala Date: Tue, 9 Jan 2024 08:56:11 +0200 Subject: [PATCH] Fixes for numpy 2.0 (#1090) --- skfem/assembly/dofs.py | 2 +- skfem/io/meshio.py | 2 +- skfem/mesh/mesh.py | 9 +++++---- skfem/mesh/mesh_3d.py | 2 +- tests/test_dofs.py | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/skfem/assembly/dofs.py b/skfem/assembly/dofs.py index c7ff3b638..241f56faf 100644 --- a/skfem/assembly/dofs.py +++ b/skfem/assembly/dofs.py @@ -444,7 +444,7 @@ def get_facet_dofs( nodal_ix, facet_ix, edge_ix, - np.empty((0,), dtype=np.uint64), + np.empty((0,), dtype=np.int64), r1, r2, r3, diff --git a/skfem/io/meshio.py b/skfem/io/meshio.py index b3ee2a788..f52e90313 100644 --- a/skfem/io/meshio.py +++ b/skfem/io/meshio.py @@ -111,7 +111,7 @@ def from_meshio(m, # parse any subdomains from cell_sets if m.cell_sets: - subdomains = {k: v[meshio_type].astype(np.uint64) + subdomains = {k: v[meshio_type].astype(np.int64) for k, v in m.cell_sets_dict.items() if meshio_type in v} diff --git a/skfem/mesh/mesh.py b/skfem/mesh/mesh.py index 4adf5a9d9..d67d099cd 100644 --- a/skfem/mesh/mesh.py +++ b/skfem/mesh/mesh.py @@ -152,7 +152,7 @@ def boundary_edges(self) -> ndarray: A = self.edges[:, edge_candidates].T B = boundary_edges dims = A.max(0) + 1 - ix = np.where(np.in1d( + ix = np.where(np.isin( np.ravel_multi_index(A.T, dims), # type: ignore np.ravel_multi_index(B.T, dims), # type: ignore ))[0] @@ -271,7 +271,8 @@ def encode_boundary(boundary: Union[ndarray, OrientedBoundary] return { **{ f"skfem:s:{name}": [ - np.isin(np.arange(self.t.shape[1]), subdomain).astype(int) + np.isin(np.arange(self.t.shape[1], + dtype=np.int64), subdomain).astype(int) ] for name, subdomain in subdomains.items() }, @@ -295,7 +296,7 @@ def _decode_cell_data(self, cell_data: Dict[str, List[ndarray]]): elif subnames[1] == "b": mask = ( (1 << np.arange(self.refdom.nfacets))[:, None] - & data[0].astype(int) + & data[0].astype(np.int64) ).astype(bool) facets = np.sort(self.t2f[mask]) cells = mask.nonzero()[1] @@ -399,7 +400,7 @@ def elements_satisfying(self, """ midp = self.p[:, self.t].mean(axis=1) - return np.nonzero(test(midp))[0].astype(np.uint64) + return np.nonzero(test(midp))[0].astype(np.int64) def _expand_facets(self, ix: ndarray) -> Tuple[ndarray, ndarray]: """Return vertices and edges corresponding to given facet indices. diff --git a/skfem/mesh/mesh_3d.py b/skfem/mesh/mesh_3d.py index 4ebdd6e2e..e8a643021 100644 --- a/skfem/mesh/mesh_3d.py +++ b/skfem/mesh/mesh_3d.py @@ -43,7 +43,7 @@ def boundary_edges(self) -> ndarray: A = self.edges[:, edge_candidates].T B = boundary_edges dims = A.max(0) + 1 - ix = np.where(np.in1d( + ix = np.where(np.isin( np.ravel_multi_index(A.T, dims), # type: ignore np.ravel_multi_index(B.T, dims), # type: ignore ))[0] diff --git a/tests/test_dofs.py b/tests/test_dofs.py index 7339b1327..b7f72a021 100644 --- a/tests/test_dofs.py +++ b/tests/test_dofs.py @@ -48,7 +48,7 @@ def runTest(self): self.assertEqual(len(all_dofs.drop('u').facet), 1) all_dofs = basis.dofs.get_facet_dofs( - m.facets_satisfying(lambda x: 1)) + m.facets_satisfying(lambda x: 1 + x[0] * 0)) self.assertEqual(len(all_dofs.keep('u_n').facet), 1) self.assertEqual(len(all_dofs.drop('u').facet), 1)