diff --git a/ikpls/__init__.py b/ikpls/__init__.py index b3f9ac7..b7e1990 100644 --- a/ikpls/__init__.py +++ b/ikpls/__init__.py @@ -1 +1 @@ -__version__ = "1.2.4" +__version__ = "1.2.5" diff --git a/ikpls/fast_cross_validation/numpy_ikpls.py b/ikpls/fast_cross_validation/numpy_ikpls.py index 9c4208c..8c0d241 100644 --- a/ikpls/fast_cross_validation/numpy_ikpls.py +++ b/ikpls/fast_cross_validation/numpy_ikpls.py @@ -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 @@ -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]], ], ]: """ @@ -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 @@ -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: """ diff --git a/ikpls/jax_ikpls_base.py b/ikpls/jax_ikpls_base.py index f645dfd..12cefef 100644 --- a/ikpls/jax_ikpls_base.py +++ b/ikpls/jax_ikpls_base.py @@ -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. diff --git a/ikpls/numpy_ikpls.py b/ikpls/numpy_ikpls.py index 0ff7109..0d895c2 100644 --- a/ikpls/numpy_ikpls.py +++ b/ikpls/numpy_ikpls.py @@ -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 @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 00b72b1..3c33fe9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] maintainers = ["Sm00thix "] @@ -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" diff --git a/tests/load_data.py b/tests/load_data.py index f1b6c4d..8572d9e 100644 --- a/tests/load_data.py +++ b/tests/load_data.py @@ -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 diff --git a/tests/test_ikpls.py b/tests/test_ikpls.py index 98e7395..6a86dd1 100644 --- a/tests/test_ikpls.py +++ b/tests/test_ikpls.py @@ -47,14 +47,14 @@ 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 ----------- @@ -62,12 +62,12 @@ def load_X(self) -> npt.NDArray[np.float_]: 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 ----------- @@ -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()