Skip to content

Commit

Permalink
Update to support NumPy >= 1.26.3 which includes 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Sm00thix committed Aug 4, 2024
1 parent e7046e8 commit 556d36b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion ikpls/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.4"
__version__ = "1.2.5"
54 changes: 27 additions & 27 deletions ikpls/fast_cross_validation/numpy_ikpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(
scale_X: bool = True,
scale_Y: bool = True,
algorithm: int = 1,
dtype: np.float_ = np.float64,
dtype: Union[np.float16, np.float32, np.float64, np.float128] = np.float64,
) -> None:
self.center_X = center_X
self.center_Y = center_Y
Expand Down Expand Up @@ -139,27 +139,27 @@ def _stateless_fit(
validation_indices: npt.NDArray[np.int_],
) -> Union[
tuple[
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
],
tuple[
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[np.float_],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
],
]:
"""
Expand Down Expand Up @@ -433,13 +433,13 @@ def _stateless_fit(
def _stateless_predict(
self,
indices: npt.NDArray[np.int_],
B: npt.NDArray[np.float_],
training_X_mean: npt.NDArray[np.float_],
training_Y_mean: npt.NDArray[np.float_],
training_X_std: npt.NDArray[np.float_],
training_Y_std: npt.NDArray[np.float_],
B: npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
training_X_mean: npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
training_Y_mean: npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
training_X_std: npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
training_Y_std: npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]],
n_components: Union[None, int] = None,
) -> npt.NDArray[np.float_]:
) -> npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]]:
"""
Predicts with Improved Kernel PLS Algorithm #1 on `X` with `B` using
`n_components` components. If `n_components` is None, then predictions are
Expand Down Expand Up @@ -503,7 +503,7 @@ def _stateless_fit_predict_eval(
self,
validation_indices: npt.NDArray[np.int_],
metric_function: Callable[
[npt.NDArray[np.float_], npt.NDArray[np.float_]], Any
[npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]], npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]]], Any
],
) -> Any:
"""
Expand Down
2 changes: 1 addition & 1 deletion ikpls/jax_ikpls_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(
self.X_std = None
self.Y_std = None

def _weight_warning(self, arg: Tuple[npt.NDArray[np.int_], npt.NDArray[np.float_]]):
def _weight_warning(self, arg: Tuple[npt.NDArray[np.int_], npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]]]):
"""
Display a warning message if the weight is close to zero.
Expand Down
4 changes: 2 additions & 2 deletions ikpls/numpy_ikpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(
scale_X: bool = True,
scale_Y: bool = True,
copy: bool = True,
dtype: np.float_ = np.float64,
dtype: Union[np.float16, np.float32, np.float64, np.float128] = np.float64,
) -> None:
self.algorithm = algorithm
self.center_X = center_X
Expand Down Expand Up @@ -300,7 +300,7 @@ def fit(self, X: npt.ArrayLike, Y: npt.ArrayLike, A: int) -> None:

def predict(
self, X: npt.ArrayLike, n_components: Union[None, int] = None
) -> npt.NDArray[np.float_]:
) -> npt.NDArray[Union[np.float16, np.float32, np.float64, np.float128]]:
"""
Predicts with Improved Kernel PLS Algorithm #1 on `X` with `B` using
`n_components` components. If `n_components` is None, then predictions are
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ikpls"
version = "1.2.4"
version = "1.2.5"
description = "Improved Kernel PLS and Fast Cross-Validation."
authors = ["Sm00thix <oleemail@icloud.com>"]
maintainers = ["Sm00thix <oleemail@icloud.com>"]
Expand All @@ -11,7 +11,7 @@ repository = "https://github.com/Sm00thix/IKPLS"

[tool.poetry.dependencies]
python = ">=3.9, <3.13"
numpy = "^1.26.3"
numpy = ">=1.26.3"
jax = "^0.4.20"
jaxlib = "^0.4.20"
scikit-learn = "^1.5.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def load_spectra():
resp_byte_array = resp.read()
byte_contents = io.BytesIO(resp_byte_array)
npz_arr = np.load(byte_contents)
spectra = np.row_stack([npz_arr[k] for k in npz_arr.keys()])
spectra = np.vstack([npz_arr[k] for k in npz_arr.keys()])
spectra = spectra.astype(np.float64)
spectra = -np.log10(spectra)
return spectra
10 changes: 5 additions & 5 deletions tests/test_ikpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,27 @@ class TestClass:
csv : DataFrame
The CSV data containing target values.
raw_spectra : NDArray[float]
raw_spectra : npt.NDArray[np.float64]
The raw spectral data.
"""

csv = load_data.load_csv()
raw_spectra = load_data.load_spectra()

def load_X(self) -> npt.NDArray[np.float_]:
def load_X(self) -> npt.NDArray[np.float64]:
"""
Description
-----------
Load the raw spectral data.
Returns
-------
npt.NDArray[np.float_]
npt.NDArray[np.float64]
The raw spectral data.
"""
return np.copy(self.raw_spectra)

def load_Y(self, values: list[str]) -> npt.NDArray[np.float_]:
def load_Y(self, values: list[str]) -> npt.NDArray[np.float64]:
"""
Description
-----------
Expand All @@ -80,7 +80,7 @@ def load_Y(self, values: list[str]) -> npt.NDArray[np.float_]:
Returns
-------
NDArray[float]
npt.NDArray[np.float64]
Target values as a NumPy array.
"""
target_values = self.csv[values].to_numpy()
Expand Down

0 comments on commit 556d36b

Please sign in to comment.