Avoid Duplicate Terms in the Generator of Missing Backward Neighbors Multi-Indices
As part of the refactoring of the MultiIndexSet
class (see Issue #99 (closed)), especially in relation to the separation between the notion of completeness and downward-closedness (see Issue #105 (closed)), several internal utility functions shall be refactored.
A utility function of interest is minterpy.core.utils.gen_missing_derivatives()
which is a generator function that yields the missing (first) derivatives ("hole" or backward neighbors in the literature) from a non-downward closed multi-index set. The current implementation may generate duplicates of missing multi-index elements. For instances:
>>> import minterpy as mp
>>> import numpy as np
>>> indices = np.array([
... [0, 0, 0],
... [1, 0, 0],
... [1, 0, 1],
... [0, 1, 1],
... ]) # not downward closed
>>> missing_derivatives = mp.core.utils.gen_missing_derivatives(indices)
>>> for _ in missing_derivatives:
... print(_)
[0 0 1]
[0 1 0]
[0 0 1]
Notice that the element [0, 0, 1]
is repeated twice because it's one of the missing terms with respect to the elements [1, 0, 1]
and [0, 1, 1]
.
While so far there has been no issue, but I'd consider this to be an unexpected/unintuitive behavior of the generator as we have to always remember that the missing terms maybe repeated more than once, we don't know which one and for how many times.