Skip to content
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

Use multipledispatch #42

Open
asmeurer opened this issue Jun 16, 2020 · 3 comments
Open

Use multipledispatch #42

asmeurer opened this issue Jun 16, 2020 · 3 comments

Comments

@asmeurer
Copy link
Member

Functions like as_subindex, and in the future things from #14 will have different logic for every combination of two argument types. It might be helpful to organize the code using multipledispatch.

The actual dispatching isn't necessary. It would just help with organization. So maybe in fact we can just roll our own simple variant, since we don't really need to handle subclasses or collisions.

@asmeurer
Copy link
Member Author

Particularly for #14 most of the binary operations are commutative, so it we want to avoid duplicating the same logic for a.op(b) and b.op(a).

@asmeurer
Copy link
Member Author

Looking into it, I'm not sure if multipledispatch supports commutative matching. It may be simpler to simply roll our own thing, especially since I don't really care about extensibility from third-party libraries. NumPy doesn't have any way to define custom index types, so I don't see any reason why ndindex should support it either. Maybe if someone comes up with a use-case we can consider it, but I can't think of any right now.

@asmeurer
Copy link
Member Author

Actually there are a lot of cases where you want a default implementation that falls back to the Tuple implementation, for example. So perhaps the subclass logic in multipledispatch would be useful. We should figure out if it can do commutative dispatching, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants