Refactor `make_complete()` method of the `MultiIndexSet` class
Currently, the method make_complete()
of a MultiIndexSet
instance either returns the instance itself (if the current instance already complete) or create a new one (if the current instance is not complete). This is potentially unsafe because we don't readily know if the current instance or a new instance is returned from calling the method.
Furthermore, in the current implementation and when a new instance is created, the content of the exponents_completed
property is used as the exponents of the new instance without copying. This means that the array in exponents_completed
property of the old instance is the same (as in the same object) as the array in exponents
property of the new instance.
I'd like to propose to refactor make_complete()
by introducing an inplace
parameter. When the parameter is True
, the exponents
property of the current instance is replaced with the completed exponents. When the parameter is False
(preferably the default), a new instance with a completed exponents is created regardless the exponents of the current instance is complete or not. This way the creation of a new instance is more explicit (which is usually better than implicit).
>>> import numpy as np
>>> import minterpy as mp
>>> exp = np.array([[1, 1, 1]], dtype=int)
>>> mi = mi.MultiIndexSet(mi, lp_degree=np.inf)
>>> mi
MultiIndexSet
[[1 1 1]]
>>> mi.is_complete
False
>>> new_mi = mi.make_complete() # or mi.make_complete(inplace=False)
>>> new_mi.is_complete
True
>>> new_mi
MultiIndexSet
[[0 0 0]
[1 0 0]
[0 1 0]
[1 1 0]
[0 0 1]
[1 0 1]
[0 1 1]
[1 1 1]]
>>> mi.make_complete(inplace=True) # in-place modification
>>> mi.is_complete
True
>>> mi
[[0 0 0]
[1 0 0]
[0 1 0]
[1 1 0]
[0 0 1]
[1 0 1]
[0 1 1]
[1 1 1]]
This is related to Issue #104 (closed); if the complete exponents is indeed required then this method should be called instead of storing the complete set of exponents in a dedicated property.
PS: The inplace
parameter trick should be implemented to other methods of the MultiIndexSet
class that potentially alter the underlying data (e.g., exponents) such as add_exponents()
.