Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ #49

Merged
merged 9 commits into from
Feb 2, 2024
Merged

C++ #49

Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: actions/setup-python@v4
- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.10.0
- name: Install gcc for mac
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: actions/setup-python@v4
- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.10.0
- name: Install gcc for mac
Expand Down
2 changes: 1 addition & 1 deletion _build_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LazyImport(dict):
# https://github.com/cython/cython/blob/6ad6ca0e9e7d030354b7fe7d7b56c3f6e6a4bc23/Cython/Compiler/ModuleNode.py#L773
def __init__(self, module_name):
self.module_name = module_name
return super().__init__(self, description=self.__doc__)
super().__init__(self, description=self.__doc__)

# Must be hashable due to
# https://github.com/cython/cython/blob/6ad6ca0e9e7d030354b7fe7d7b56c3f6e6a4bc23/Cython/Compiler/Main.py#L307
Expand Down
2 changes: 1 addition & 1 deletion imops/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.8.5'
__version__ = '0.8.6'
16 changes: 8 additions & 8 deletions imops/interp2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
):
if triangles is not None:
if not isinstance(triangles, np.ndarray):
raise TypeError(f'Wrong type of `triangles` argument, expected np.ndarray. Got {type(triangles)}')

Check warning on line 55 in imops/interp2d.py

View check run for this annotation

Codecov / codecov/patch

imops/interp2d.py#L55

Added line #L55 was not covered by tests
if triangles.ndim != 2 or triangles.shape[1] != 3 or triangles.shape[0] * 3 != triangles.size:
raise ValueError('Passed `triangles` argument has an incorrect shape')

if not isinstance(points, np.ndarray):
raise TypeError(f'Wrong type of `points` argument, expected np.ndarray. Got {type(points)}')

Check warning on line 60 in imops/interp2d.py

View check run for this annotation

Codecov / codecov/patch

imops/interp2d.py#L60

Added line #L60 was not covered by tests

if values is not None:
if not isinstance(values, np.ndarray):
Expand All @@ -81,7 +81,7 @@
points: np.ndarray
2-D array of data point coordinates to interpolate at
values: np.ndarray
1-D array of fp32/fp64 values to use at initial points. If passed, existing values will be rewritten
1-D array of fp32/fp64 values to use at initial points. If passed, existing values will NOT be rewritten
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"If passed, existing values will NOT be rewritten" - you don't need to specify this. This is what the user expects anyway

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

fill_value: float
value to fill past edges

Expand All @@ -90,22 +90,22 @@
new_values: np.ndarray
interpolated values at given points
"""
self.values = values or self.values
x_values = values if values is not None else self.values
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just

if values is None:
  values = self.values

? the new variable seems redundant

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


if self.values is None:
if x_values is None:
raise ValueError('`values` argument was never passed neither in __init__ or __call__ methods')

if not isinstance(self.values, np.ndarray):
raise TypeError(f'Wrong type of `values` argument, expected np.ndarray. Got {type(self.values)}')
if not isinstance(x_values, np.ndarray):
raise TypeError(f'Wrong type of `values` argument, expected np.ndarray. Got {type(x_values)}')

if self.values.ndim > 1:
raise ValueError(f'Wrong shape of `values` argument, expected ndim=1. Got shape {self.values.shape}')
if x_values.ndim > 1:
raise ValueError(f'Wrong shape of `values` argument, expected ndim=1. Got shape {x_values.shape}')

_, neighbors = self.kdtree.query(
points, 1, **{'workers': self.num_threads} if python_version()[:3] != '3.6' else {}
)

if not isinstance(points, np.ndarray):
raise TypeError(f'Wrong type of `points` argument, expected np.ndarray. Got {type(points)}')

Check warning on line 109 in imops/interp2d.py

View check run for this annotation

Codecov / codecov/patch

imops/interp2d.py#L109

Added line #L109 was not covered by tests

return super().__call__(points, self.values, neighbors, fill_value)
return super().__call__(points, x_values, neighbors, fill_value)
9 changes: 9 additions & 0 deletions tests/test_interp2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ def test_no_values(example):
Linear2DInterpolator(x_points)(int_points)


def test_no_changes_in_values(example):
x_points, int_points = example
first_values = np.ones((x_points.shape[0],), dtype=float)
second_values = 2.0 * np.ones((x_points.shape[0],), dtype=float)
interpolator = Linear2DInterpolator(x_points, first_values)
interpolator(int_points, second_values)
assert np.all(interpolator.values == first_values), 'Failed with changes in self.values after __call__'


def test_bad_values_dtype(example):
x_points, int_points = example

Expand Down
Loading