Skip to content

Commit

Permalink
Change np.float_ for np.float64.
Browse files Browse the repository at this point in the history
  • Loading branch information
vnmabus committed Jun 21, 2024
1 parent a445b03 commit 1582445
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _rkhs_vs(
indexes = np.delete(indexes, selected_features[0])

for i in range(1, n_features_to_select):
aux = np.zeros_like(indexes, dtype=np.float_)
aux = np.zeros_like(indexes, dtype=np.float64)

for j in range(0, indexes.shape[0]):
new_selection = np.concatenate([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import numpy as np
import scipy.signal
import sklearn.utils
from sklearn.base import clone

from dcor import u_distance_correlation_sqr
from sklearn.base import clone

from ...._utils._sklearn_adapter import (
BaseEstimator,
Expand Down Expand Up @@ -232,7 +231,7 @@ def fit( # type: ignore[override] # noqa: D102
self.features_shape_ = X.data_matrix.shape[1:]
self.dependence_ = _compute_dependence(
X,
y.astype(np.float_),
y.astype(np.float64),
dependence_measure=self.dependence_measure,
)

Expand Down
28 changes: 14 additions & 14 deletions skfda/preprocessing/dim_reduction/variable_selection/mrmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
bound="MinimumRedundancyMaximumRelevance[Any]",
)

dtype_X_T = TypeVar("dtype_X_T", bound=np.float_, covariant=True)
dtype_X_T = TypeVar("dtype_X_T", bound=np.float64, covariant=True)
dtype_y_T = TypeVar(
"dtype_y_T",
bound=Union[np.int_, np.float_],
bound=Union[np.int_, np.float64],
covariant=True,
)

Expand Down Expand Up @@ -108,7 +108,7 @@ def mutual_information(
MethodName = Literal["MID", "MIQ"]


def _parse_method(name: MethodName) -> Method[Union[np.int_, np.float_]]:
def _parse_method(name: MethodName) -> Method[Union[np.int_, np.float64]]:
if name == "MID":
return MID
elif name == "MIQ":
Expand Down Expand Up @@ -336,8 +336,8 @@ def __init__(
*,
n_features_to_select: int = 1,
dependence_measure: _DependenceMeasure[
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float_ | dtype_y_T],
np.typing.NDArray[np.float64],
np.typing.NDArray[np.float64 | dtype_y_T],
],
criterion: _CriterionLike,
) -> None:
Expand All @@ -349,12 +349,12 @@ def __init__(
*,
n_features_to_select: int = 1,
relevance_dependence_measure: _DependenceMeasure[
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float64],
np.typing.NDArray[dtype_y_T],
],
redundancy_dependence_measure: _DependenceMeasure[
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float64],
np.typing.NDArray[np.float64],
],
criterion: _CriterionLike,
) -> None:
Expand All @@ -366,16 +366,16 @@ def __init__(
n_features_to_select: int = 1,
method: Method[dtype_y_T] | MethodName | None = None,
dependence_measure: _DependenceMeasure[
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float_ | dtype_y_T],
np.typing.NDArray[np.float64],
np.typing.NDArray[np.float64 | dtype_y_T],
] | None = None,
relevance_dependence_measure: _DependenceMeasure[
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float64],
np.typing.NDArray[dtype_y_T],
] | None = None,
redundancy_dependence_measure: _DependenceMeasure[
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float64],
np.typing.NDArray[np.float64],
] | None = None,
criterion: _CriterionLike | None = None,
) -> None:
Expand Down Expand Up @@ -417,7 +417,7 @@ def _validate_parameters(self) -> None:
)

self.relevance_dependence_measure_: _DependenceMeasure[
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float64],
np.typing.NDArray[dtype_y_T],
] = (
method.relevance_dependence_measure
Expand Down
2 changes: 1 addition & 1 deletion skfda/tests/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def test_evaluation_nodes(self) -> None:
@np.vectorize
def _coordinate_function(
*args: float,
) -> np.typing.NDArray[np.float_]:
) -> np.typing.NDArray[np.float64]:
_, *domain_indexes, _ = args
return np.sum(domain_indexes) # type: ignore[no-any-return]

Expand Down
18 changes: 9 additions & 9 deletions skfda/tests/test_kernel_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from skfda.representation.basis import FDataBasis, FourierBasis, MonomialBasis
from skfda.representation.grid import FDataGrid

FloatArray = np.typing.NDArray[np.float_]
FloatArray = np.typing.NDArray[np.float64]


def _nw_alt(
Expand Down Expand Up @@ -151,7 +151,7 @@ def test_nadaraya_watson(self) -> None:
fd_train_grid, fd_test_grid, y_train_grid = _create_data_grid()

# Test NW method with basis representation and bandwidth=1
nw_basis = KernelRegression[FDataBasis, np.typing.NDArray[np.float_]](
nw_basis = KernelRegression[FDataBasis, np.typing.NDArray[np.float64]](
kernel_estimator=NadarayaWatsonHatMatrix(bandwidth=1),
)
nw_basis.fit(fd_train_basis, y_train_basis)
Expand All @@ -168,7 +168,7 @@ def test_nadaraya_watson(self) -> None:
)

# Test NW method with grid representation and bandwidth=1
nw_grid = KernelRegression[FDataGrid, np.typing.NDArray[np.float_]](
nw_grid = KernelRegression[FDataGrid, np.typing.NDArray[np.float64]](
kernel_estimator=NadarayaWatsonHatMatrix(bandwidth=1),
)
nw_grid.fit(fd_train_grid, y_train_grid)
Expand All @@ -192,7 +192,7 @@ def test_knn(self) -> None:

# Test KNN method with basis representation, n_neighbours=3 and
# uniform kernel
knn_basis = KernelRegression[FDataBasis, np.typing.NDArray[np.float_]](
knn_basis = KernelRegression[FDataBasis, np.typing.NDArray[np.float64]](
kernel_estimator=KNeighborsHatMatrix(n_neighbors=3),
)
knn_basis.fit(fd_train_basis, y_train_basis)
Expand All @@ -210,7 +210,7 @@ def test_knn(self) -> None:

# Test KNN method with grid representation, n_neighbours=3 and
# uniform kernel
knn_grid = KernelRegression[FDataGrid, np.typing.NDArray[np.float_]](
knn_grid = KernelRegression[FDataGrid, np.typing.NDArray[np.float64]](
kernel_estimator=KNeighborsHatMatrix(n_neighbors=3),
)
knn_grid.fit(fd_train_grid, y_train_grid)
Expand Down Expand Up @@ -253,7 +253,7 @@ def test_llr(self) -> None:
# Creating data
fd_train_basis, fd_test_basis, y_train_basis = _create_data_basis()

llr_basis = KernelRegression[FDataBasis, np.typing.NDArray[np.float_]](
llr_basis = KernelRegression[FDataBasis, np.typing.NDArray[np.float64]](
kernel_estimator=LocalLinearRegressionHatMatrix(bandwidth=1),
)
llr_basis.fit(fd_train_basis, y_train_basis)
Expand All @@ -273,7 +273,7 @@ def test_nw_r(self) -> None:
"""Comparison of NW's results with results from fda.usc."""
X_train, X_test, y_train = _create_data_r()

nw = KernelRegression[FDataGrid, np.typing.NDArray[np.float_]](
nw = KernelRegression[FDataGrid, np.typing.NDArray[np.float64]](
kernel_estimator=NadarayaWatsonHatMatrix(bandwidth=1),
)
nw.fit(X_train, y_train)
Expand All @@ -298,7 +298,7 @@ def test_knn_r(self) -> None:
"""Comparison of NW's results with results from fda.usc."""
X_train, X_test, y_train = _create_data_r()

knn = KernelRegression[FDataGrid, np.typing.NDArray[np.float_]](
knn = KernelRegression[FDataGrid, np.typing.NDArray[np.float64]](
kernel_estimator=KNeighborsHatMatrix(n_neighbors=3),
)
knn.fit(X_train, y_train)
Expand Down Expand Up @@ -337,7 +337,7 @@ def test_llr_non_orthonormal(self) -> None:
bandwidth=100,
kernel=uniform,
)
kr = KernelRegression[FDataBasis, np.typing.NDArray[np.float_]](
kr = KernelRegression[FDataBasis, np.typing.NDArray[np.float64]](
kernel_estimator=llr,
)
kr.fit(X_train, y_train)
Expand Down
26 changes: 13 additions & 13 deletions skfda/tests/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@


def _ndm(
*args: np.typing.NDArray[np.float_],
) -> Sequence[np.typing.NDArray[np.float_]]:
*args: np.typing.NDArray[np.float64],
) -> Sequence[np.typing.NDArray[np.float64]]:
return [
x[(None,) * i + (slice(None),) + (None,) * (len(args) - i - 1)]
for i, x in enumerate(args)
Expand All @@ -30,10 +30,10 @@ class InnerProductTest(unittest.TestCase):
def test_several_variables(self) -> None:
"""Test inner_product with functions of several variables."""
def f( # noqa: WPS430
x: np.typing.NDArray[np.float_],
y: np.typing.NDArray[np.float_],
z: np.typing.NDArray[np.float_],
) -> np.typing.NDArray[np.float_]:
x: np.typing.NDArray[np.float64],
y: np.typing.NDArray[np.float64],
z: np.typing.NDArray[np.float64],
) -> np.typing.NDArray[np.float64]:
return x * y * z

t = np.linspace(0, 1, 30)
Expand Down Expand Up @@ -73,9 +73,9 @@ def f( # noqa: WPS430
def test_mixed_several_variables(self) -> None:
"""Test inner_product with basis and grid multivariable functions."""
def f( # noqa: WPS430
x: np.typing.NDArray[np.float_],
y: np.typing.NDArray[np.float_],
) -> np.typing.NDArray[np.float_]:
x: np.typing.NDArray[np.float64],
y: np.typing.NDArray[np.float64],
) -> np.typing.NDArray[np.float64]:
return x + y

t = np.linspace(0, 1, 50)
Expand Down Expand Up @@ -103,13 +103,13 @@ def f( # noqa: WPS430
def test_vector_valued(self) -> None:
"""Test inner_product with vector valued functions."""
def f( # noqa: WPS430
x: np.typing.NDArray[np.float_],
) -> np.typing.NDArray[np.float_]:
x: np.typing.NDArray[np.float64],
) -> np.typing.NDArray[np.float64]:
return x**2

def g( # noqa: WPS430
y: np.typing.NDArray[np.float_],
) -> np.typing.NDArray[np.float_]:
y: np.typing.NDArray[np.float64],
) -> np.typing.NDArray[np.float64]:
return 3 * y

t = np.linspace(0, 1, 100)
Expand Down
18 changes: 9 additions & 9 deletions skfda/tests/test_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ def test_predict_regressor(self) -> None:
"""Test scalar regression, predicts mode location."""
# Dummy test, with weight = distance, only the sample with distance 0
# will be returned, obtaining the exact location
knnr = KNeighborsRegressor[FDataGrid, np.typing.NDArray[np.float_]](
knnr = KNeighborsRegressor[FDataGrid, np.typing.NDArray[np.float64]](
weights='distance',
)
rnnr = RadiusNeighborsRegressor[
FDataGrid,
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float64],
](
weights='distance',
radius=0.1,
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_kneighbors(self) -> None:
knn = KNeighborsClassifier()
knn.fit(self.X, self.y)

knnr = KNeighborsRegressor[FDataGrid, np.typing.NDArray[np.float_]]()
knnr = KNeighborsRegressor[FDataGrid, np.typing.NDArray[np.float64]]()
knnr.fit(self.X, self.modes_location)

neigh: KNeighborsMixin[FDataGrid, Any]
Expand Down Expand Up @@ -201,7 +201,7 @@ def test_radius_neighbors(self) -> None:

knnr = RadiusNeighborsRegressor[
FDataGrid,
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float64],
](radius=0.1)
knnr.fit(self.X, self.modes_location)

Expand Down Expand Up @@ -241,7 +241,7 @@ def test_knn_functional_response_precomputed(self) -> None:
"""Test that precomputed distances work for functional response."""
# Non-precomputed
knnr = KNeighborsRegressor[
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float64],
FDataGrid,
](
weights='distance',
Expand All @@ -252,7 +252,7 @@ def test_knn_functional_response_precomputed(self) -> None:

# Precomputed
knnr_pre = KNeighborsRegressor[
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float64],
FDataGrid,
](
weights='distance',
Expand Down Expand Up @@ -395,7 +395,7 @@ def test_score_scalar_response(self) -> None:
"""Test regression with scalar response."""
neigh = KNeighborsRegressor[
FDataGrid,
np.typing.NDArray[np.float_],
np.typing.NDArray[np.float64],
]()

neigh.fit(self.X, self.modes_location)
Expand Down Expand Up @@ -522,8 +522,8 @@ def test_lof_exceptions(self) -> None:

def _weights(
self,
weights: np.typing.NDArray[np.float_],
) -> np.typing.NDArray[np.float_]:
weights: np.typing.NDArray[np.float64],
) -> np.typing.NDArray[np.float64]:
return np.array([w == np.min(weights) for w in weights], dtype=float)


Expand Down
2 changes: 1 addition & 1 deletion skfda/tests/test_pandas_fdatabasis.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def data_missing(basis: Basis) -> FDataBasis:
"""Length-2 array with [NA, Valid]."""
coef_matrix = np.arange(
2 * basis.n_basis,
dtype=np.float_,
dtype=np.float64,
).reshape(2, basis.n_basis)
coef_matrix[0, :] = np.NaN

Expand Down
2 changes: 1 addition & 1 deletion skfda/tests/test_pandas_fdatagrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def data_missing() -> ExtensionArray:
"""Return a length-2 array with [NA, Valid]."""
data_matrix = np.arange(
2 * 10 * 10 * 3,
dtype=np.float_,
dtype=np.float64,
).reshape(2, 10, 10, 3)
data_matrix[0, ...] = np.NaN
grid_points = [
Expand Down
4 changes: 2 additions & 2 deletions skfda/tests/test_per_class_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setUp(self) -> None:

def test_transform(self) -> None:
"""Check the data transformation is done correctly."""
t = PerClassTransformer[FDataGrid, np.typing.NDArray[np.float_]](
t = PerClassTransformer[FDataGrid, np.typing.NDArray[np.float64]](
RecursiveMaximaHunting(),
array_output=True,
)
Expand All @@ -46,7 +46,7 @@ def test_transform(self) -> None:

def test_not_transformer_argument(self) -> None:
"""Check that invalid arguments in fit raise exception."""
t = PerClassTransformer[FDataGrid, np.typing.NDArray[np.float_]](
t = PerClassTransformer[FDataGrid, np.typing.NDArray[np.float64]](
KNeighborsClassifier(),
)
self.assertRaises(
Expand Down
8 changes: 4 additions & 4 deletions skfda/tests/test_recursive_maxima_hunting.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_gaussian_homoscedastic(self) -> None:
n_features = 101

def mean_1( # noqa: WPS430
t: np.typing.NDArray[np.float_],
) -> np.typing.NDArray[np.float_]:
t: np.typing.NDArray[np.float64],
) -> np.typing.NDArray[np.float64]:

return ( # type: ignore[no-any-return]
np.abs(t - 0.25)
Expand Down Expand Up @@ -86,8 +86,8 @@ def test_fit_exponential(self) -> None:
n_features = 101

def mean_1( # noqa: WPS430
t: np.typing.NDArray[np.float_],
) -> np.typing.NDArray[np.float_]:
t: np.typing.NDArray[np.float64],
) -> np.typing.NDArray[np.float64]:

return ( # type: ignore[no-any-return]
np.abs(t - 0.25)
Expand Down
2 changes: 1 addition & 1 deletion skfda/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def test_mixed_regularization(self) -> None:
])

X: Sequence[
np.typing.NDArray[np.float_] | FDataBasis,
np.typing.NDArray[np.float64] | FDataBasis,
] = [multivariate, x_fd]

# y = 2 + sum([3, 1] * array) + int(3 * function) # noqa: E800
Expand Down
Loading

0 comments on commit 1582445

Please sign in to comment.