-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start of a prototype for string-based, very strict, type dispatching #2
base: main
Are you sure you want to change the base?
Conversation
Right now, no order is enforced if multiple backends match!
for t in types: | ||
ident = get_identifier(t) | ||
|
||
if ident in self.type_names: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this uses the string types, and @eriknw correctly pointed out (independent of this PR), that projects may sometimes be sloppy about which __module__
they define types.
I am not sure this is a problem, but we could work around it, with something like:
module, name = self.type_names[0] # all of them of course
if module in sys.modules:
t = getattr(module, name, None) # ignore error?
...
I.e. I think rather than matching only by strings, we could check whether the type may be defined, by testing if the module exists.
For comparison, this is how we're currently doing basic type-delegation in |
FWIW, this is a branch in skimage: scikit-image/scikit-image@main...seberg:backend-cucim-try that uses the state here. I added a backend for cucim there (for filters.median and filters.gaussian), that has to live in cucim and be auto-generated of course. |
This is an early (and very dirty) start, in case it is useful to get going. (Ping @eriknw)
The "example" is just the
prototype_*
modules, with the_example
one being executable. I did not look into the entry-points, and of course this is all very raw:cucim
may want to only kick in for cupy arrays, but understandnumpy
arrays. A better example maybe adask.array
backend which can understand cupy/numpy, but will never be picked for those.WillNotHandle()
return class to pass out information for rejection, since I liked that idea:inspect
, which I really like for simplicity.We need the signature fetching for it, but otherwise we can always optimize it.
Anyway, sharing in the hoping it might help. But please feel free to ignore if you have another start and are pushing forward there!