Skip to content

Commit

Permalink
Extend support for Numpy 2.0 (#514)
Browse files Browse the repository at this point in the history
Convert Numpy scalars to Python numbers so the outputs of examples that
are being compared when running doctests support Numpy>=2.0. Cast
`points` in equivalent source classes to the desired `dtype` passed as
argument.
  • Loading branch information
santisoler authored Jun 18, 2024
1 parent d7b315b commit f6d52b9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion harmonica/_equivalent_sources/cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ def fit(self, coordinates, data, weights=None):
self.region_ = vd.get_region(coordinates[:2])
coordinates = vdb.n_1d_arrays(coordinates, 3)
if self.points is None:
self.points_ = self._build_points(coordinates)
self.points_ = tuple(
p.astype(self.dtype) for p in self._build_points(coordinates)
)
else:
self.depth_ = None # set depth_ to None so we don't leave it unset
self.points_ = tuple(
Expand Down
9 changes: 6 additions & 3 deletions harmonica/_equivalent_sources/gradient_boosted.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def estimate_required_memory(self, coordinates):
Returns
-------
memory_required : float
memory_required : int
Amount of memory required to store the largest Jacobian matrix in
bytes.
Expand All @@ -157,7 +157,8 @@ def estimate_required_memory(self, coordinates):
... random_state=42,
... )
>>> eqs = EquivalentSourcesGB(window_size=2e3)
>>> eqs.estimate_required_memory(coordinates)
>>> n_bytes = eqs.estimate_required_memory(coordinates)
>>> int(n_bytes)
9800
"""
# Build the sources and assign the points_ attribute
Expand Down Expand Up @@ -216,7 +217,9 @@ def fit(self, coordinates, data, weights=None):
weights = weights.ravel()
# Build point sources
if self.points is None:
self.points_ = self._build_points(coordinates)
self.points_ = tuple(
p.astype(self.dtype) for p in self._build_points(coordinates)
)
else:
self.points_ = tuple(
p.astype(self.dtype) for p in vdb.n_1d_arrays(self.points, 3)
Expand Down
10 changes: 6 additions & 4 deletions harmonica/_forward/prism_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ def prism_layer(
coords_units: meters
properties_units: SI
>>> # Get the boundaries of the layer (will exceed the region)
>>> print(prisms.prism_layer.boundaries)
(-1.25, 11.25, 1.0, 9.0)
>>> boundaries = prisms.prism_layer.boundaries
>>> list(float(b) for b in boundaries)
[-1.25, 11.25, 1.0, 9.0]
>>> # Get the boundaries of one of the prisms
>>> print(prisms.prism_layer.get_prism((0, 2)))
(3.75, 6.25, 1.0, 3.0, 0.0, 2.0)
>>> prism = prisms.prism_layer.get_prism((0, 2))
>>> list(float(b) for b in prism)
[3.75, 6.25, 1.0, 3.0, 0.0, 2.0]
""" # noqa: W505
dims = ("northing", "easting")
# Initialize data and data_names as None
Expand Down

0 comments on commit f6d52b9

Please sign in to comment.