From fb6502f6d23fe6ab8cd0bfe599dedd418bf8bf44 Mon Sep 17 00:00:00 2001 From: VNMabus Date: Thu, 7 Mar 2024 17:18:25 +0100 Subject: [PATCH] Fix doctests. Automatic casting to float dtype is removed, as it prevents using different float sizes (or even integers in the future). --- skfda/representation/irregular.py | 38 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/skfda/representation/irregular.py b/skfda/representation/irregular.py index f4c7c4a7f..1524a02fa 100644 --- a/skfda/representation/irregular.py +++ b/skfda/representation/irregular.py @@ -24,11 +24,7 @@ import pandas.api.extensions from matplotlib.figure import Figure -from .._utils import ( - _cartesian_product, - _check_array_key, - _to_grid_points, -) +from .._utils import _cartesian_product, _check_array_key, _to_grid_points from ..typing._base import ( DomainRange, DomainRangeLike, @@ -56,6 +52,7 @@ # Auxiliary functions# ###################### + def _reduceat( ufunc, array: ArrayLike, @@ -113,6 +110,7 @@ def _reduceat( return out + def _get_sample_range_from_data( start_indices: NDArrayInt, points: NDArrayFloat, @@ -142,6 +140,7 @@ def _get_sample_range_from_data( axis=-1, ) + def _get_domain_range_from_sample_range( sample_range: DomainRangeLike, ) -> DomainRange: @@ -254,8 +253,8 @@ class FDataIrregular(FData): # noqa: WPS214 representing a function :math:`f : \mathbb{R}\longmapsto\mathbb{R}^2`. >>> indices = [0, 2] - >>> arguments = [[1], [2], [3], [4], [5]] - >>> values = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]] + >>> arguments = [[1.], [2.], [3.], [4.], [5.]] + >>> values = [[1., 1.], [2., 2.], [3., 3.], [4., 4.], [5., 5.]] >>> fd = FDataIrregular(indices, arguments, values) >>> fd.dim_domain, fd.dim_codomain (1, 2) @@ -264,8 +263,8 @@ class FDataIrregular(FData): # noqa: WPS214 representing a function :math:`f : \mathbb{R}^2\longmapsto\mathbb{R}`. >>> indices = [0, 2] - >>> arguments = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]] - >>> values = [[1], [2], [3], [4], [5]] + >>> arguments = [[1., 1.], [2., 2.], [3., 3.], [4., 4.], [5., 5.]] + >>> values = [[1.], [2.], [3.], [4.], [5.]] >>> fd = FDataIrregular(indices, arguments, values) >>> fd.dim_domain, fd.dim_codomain (2, 1) @@ -288,10 +287,10 @@ def __init__( # noqa: WPS211 ): """Construct a FDataIrregular object.""" self.start_indices = np.asarray(start_indices) - self.points = np.asarray(points, dtype=float) + self.points = np.asarray(points) if self.points.ndim == 1: self.points = self.points.reshape(-1, 1) - self.values = np.asarray(values, dtype=float) + self.values = np.asarray(values) if self.values.ndim == 1: self.values = self.values.reshape(-1, 1) @@ -313,7 +312,8 @@ def __init__( # noqa: WPS211 self.values = sorted_values self._sample_range = _get_sample_range_from_data( - self.start_indices, self.points + self.start_indices, + self.points, ) # Default value for sample_range is a list of tuples with @@ -465,9 +465,9 @@ def from_fdatagrid( def _sort_by_arguments(self) -> Tuple[ArrayLike, ArrayLike]: """Sort the arguments lexicographically functionwise. - + Additionally, sort the values accordingly. - + Returns: Tuple[ArrayLike, Arraylike]: sorted pair (arguments, values) """ @@ -789,7 +789,8 @@ def _get_op_matrix( # noqa: WPS212 other_vector = other[other_index] # Number of values in each curve - values_curve = np.diff(self.start_indices, append=len(self.points)) + values_curve = np.diff( + self.start_indices, append=len(self.points)) # Repeat the other value for each curve as many times # as values inside the curve @@ -807,7 +808,8 @@ def _get_op_matrix( # noqa: WPS212 other_vector = other[other_index] # Number of values in each curve - values_curve = np.diff(self.start_indices, append=len(self.points)) + values_curve = np.diff( + self.start_indices, append=len(self.points)) # Repeat the other value for each curve as many times # as values inside the curve @@ -938,13 +940,13 @@ def concatenate(self: T, *others: T, as_coordinates: bool = False) -> T: Examples: >>> indices = [0, 2] - >>> arguments = values = np.arange(5).reshape(-1, 1) + >>> arguments = values = np.arange(5.).reshape(-1, 1) >>> fd = FDataIrregular(indices, arguments, values) >>> arguments_2 = values_2 = np.arange(5, 10).reshape(-1, 1) >>> fd_2 = FDataIrregular(indices, arguments_2, values_2) >>> fd.concatenate(fd_2) FDataIrregular( - start_indices=array([0, 2, 5, 7], dtype=uint32), + start_indices=array([0, 2, 5, 7]), points=array([[ 0.], [ 1.], [ 2.],