The verification function "check_shape" is ineffective if called only with the "dimensionality" parameter.
The verification function minterpy.core.verification.check_shape()
has the following signature:
def check_shape(
a: np.ndarray, shape: Optional[Sized] = None, dimensionality: int = None
):
"""Verify the shape of an input array.
...
Some examples of it being called in the code base:
-
check_shape(internal_domain, (spatial_dimension, 2))
(theshape
parameter is provided) -
check_shape(exponents, dimensionality=2)
(thedimensionality
parameter is provided)
In the code base, there is currently no use case where both the shape
and dimensionality
parameters are provided.
The problem with the current function is that, if only the dimensionality parameter is provided (and shape
is None
),
the function actually does nothing.
The first couple of lines of the function read:
if shape is None:
return
Out of seven usages of this function, four of them are called only with dimensionality
and thus, for these cases, the function verifies nothing.
For instance, a MultiIndexSet
instance should strictly accept two-dimensional NumPy array (whose columns corresponds to the "spatial dimension" of the set).
The default constructor of the class does employ check_shape()
(i.e., check_shape(exponents, dimensionality=2)
)
And yet:
>>> import minterpy as mp
>>> import numpy as np
>>> xx = np.random.randint(1, 5, size=(2, 3, 4)) # three-dimensional array
>>> mp.MultiIndexSet(xx, 1)
MultiIndexSet
[[[[2 1 3 3]
[1 4 3 1]
[3 4 4 4]]
[[1 2 4 4]
[1 4 4 4]
[4 3 4 1]]]
[[[2 1 3 3]
[1 4 3 1]
[3 4 4 4]]
[[1 2 4 4]
[1 4 4 4]
[4 3 4 1]]]
[[[1 2 4 4]
[1 4 4 4]
[4 3 4 1]]
[[2 1 3 3]
[1 4 3 1]
[3 4 4 4]]]]
which is nonsensical.
Fix the implementation of this function such that the "dimensionality" check is carried out correctly.