Open InfProbSciX opened 1 year ago
Hey @InfProbSciX! I’m very sorry this is broken now. Just sending a quick message here to let you know that I’ve seen this and will reply very soon with how this now works.
Hey @InfProbSciX. I believe that your snippet should work with minimal changes:
from typing import Union
import lab as B
import scipy.sparse as sp
from plum import Signature
SparseArray = Union[
sp.bsr_matrix,
int, # Dummy for other types
]
_SparseArraySign = Signature(SparseArray)
def sparse_transpose(a):
return a.T
B.T.register(sparse_transpose, _SparseArraySign)
B.T(sp.bsr_array([0, 0])) # OK
B.T(sp.csr_array([0, 0])) # error
Is this what you're after?
Note that aliasing unions has been removed, because Plum now runs fully on standard type hints. Nevertheless, it is still possible to achieve the desired behaviour, which is documented here. This would work as follows:
>>> from plum import activate_union_aliases, set_union_alias
>>> activate_union_aliases()
>>> set_union_alias(SparseArray, "SparseArray")
>>> SparseArray
typing.Union[SparseArray]
This feature must be activated explicitly because it patches typing.Union.__repr__
and might therefore cause unintended behaviour.
With the previous versions of plum and lab (
backends==1.4.32 plum-dispatch==1.7.4
), the following was a way in which one could register a new set of types for a function:This doesn't work anymore. For starters, I've fixed the way Union works now:
but the usage of
B.T
still fails:Is there a fix for this, and could the documentation be updated on how one updates such functions?
This is from GeometricKernels.