Allow non `int` as poly. degree in the construction of MultiIndexSet via `from_degree()`
Currently, the from_degree()
constructor only accepts integer value for the parameter poly_degree
.
Specifically, via an isinstance(..., int)
checking, only a value of the int
type can be accepted as poly_degree
, otherwise TypeError
will be raised.
While imposing a particular type for a property makes sense and safe,
it can be rather too restrictive for the construction of MultiIndexSet
.
For instance, the elements of np.arange()
cannot be used as an argument value for poly_degree
:
>>> import numpy as np
>>> import minterpy as mp
>>> poly_degrees = np.arange(1, 3)
>>> for poly_degree in poly_degrees:
mi = mp.MultiIndexSet.from_degree(2, poly_degree, 1.0)
...
TypeError: only integer polynomial degrees are supported.
because the elements are of type np.int32
, an integer type but not int
specifically.
It works only with an explicit conversion:
>>> poly_degrees = np.arange(1, 3)
>>> for poly_degree in poly_degrees:
mi = mp.MultiIndexSet.from_degree(2, int(poly_degree), 1.0)
which is not very intuitive; np.integer
types are quite commonly used.
Because from_degree()
constructor can be considered high-level, it is the intention that matters: 5.
(integral float, float without fractional part), 5
, np.array([5], dtype=int)[0]
as far as a poly. degree value goes, all mean the same thing (while 5.1
or "5"
is clearly non-sensical as a poly. degree). The constructor should, therefore, be more forgiving about the particular type of polynomial degree as long as the value itself remains reasonable.
Note that the property should still store the poly_degree
value as int
.