Allow the default constructor of MultiIndexSet to accept non-lexicographically sorted and repeat exponents
Currently, the default constructor of MultiIndexSet
only accepts a set of exponents that is lexicographically sorted:
>>> import minterpy as mp
>>> import numpy as np
>>> exp = np.array([[1, 1], [2, 1]]) # non-downward-closed, lexicographically sorted
>>> mp.MultiIndexSet(exp, lp_degree=1.0) # No problem
MultiIndexSet
[[1 1]
[2 1]]
>>> exp = np.array([[2, 1], [1, 1]]) # non-downward-closed, lexicographically unsorted
>>> mp.MultiIndexSet(exp, lp_degree=1.0) # exception is raised
41 check_shape(exponents, dimensionality=2)
42 if not have_lexicographical_ordering(exponents):
---> 43 raise ValueError(
44 "The multi-index set must be lexicographically ordered from "
45 "the last to the first column."
46 )
47 self._exponents: ARRAY = exponents
49 # Verify the given lp_degree
ValueError: The multi-index set must be lexicographically ordered from the last to the first column.
I think, there is no reason why we have to separately and lexicographically order the set of exponents before feeding it into the default constructor of the MultiIndexSet
class. Shouldn't this happen automatically? i.e., internally it will be sorted.
Furthermore, the constructor also complains if there are repeated elements in the input exponents:
>>> exp = np.array([[1], [1]])
>>> mp.MultiIndexSet(exp, lp_degree=1.0)
41 check_shape(exponents, dimensionality=2)
42 if not have_lexicographical_ordering(exponents):
---> 43 raise ValueError(
44 "The multi-index set must be lexicographically ordered from "
45 "the last to the first column."
46 )
47 self._exponents: ARRAY = exponents
49 # Verify the given lp_degree
ValueError: The multi-index set must be lexicographically ordered from the last to the first column.
Again, as a set, we expect a multi-index set to ignore any repeated elements and not to raise an exception like the above.
I propose to remove exception raised and either sort all input exponents automatically or check first if they are ordered before sorting (not sure if this is necessary, though).
This issue is part of the larger issue of refactoring the multi-index set (Issue #99 (closed)).