Skip to content

Commit

Permalink
Fix doctests.
Browse files Browse the repository at this point in the history
Automatic casting to float dtype is removed, as it prevents using
different float sizes (or even integers in the future).
  • Loading branch information
vnmabus committed Mar 7, 2024
1 parent 777bd5d commit fb6502f
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions skfda/representation/irregular.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -56,6 +52,7 @@
# Auxiliary functions#
######################


def _reduceat(
ufunc,
array: ArrayLike,
Expand Down Expand Up @@ -113,6 +110,7 @@ def _reduceat(

return out


def _get_sample_range_from_data(
start_indices: NDArrayInt,
points: NDArrayFloat,
Expand Down Expand Up @@ -142,6 +140,7 @@ def _get_sample_range_from_data(
axis=-1,
)


def _get_domain_range_from_sample_range(
sample_range: DomainRangeLike,
) -> DomainRange:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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)
"""
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.],
Expand Down

0 comments on commit fb6502f

Please sign in to comment.