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

Inconsistency with cmp_instance and typedispatch because of binary sort algorithm #100

Closed
kessido opened this issue Sep 27, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@kessido
Copy link
Contributor

kessido commented Sep 27, 2020

Basically, typedispatch assume that the type in funcs are ordered in a topological sort, but this is not true as the key comparison is not defined well under this.

stupid example (edited, now it is less stupid :P ):

>>> from fastcore.dispatch import *
>>> 
>>> class A: pass
... 
>>> class B(A): pass
... 
>>> @typedispatch
... def f(a:A): print('A')
... 
>>> @typedispatch
... def f(x:int): pass
... 
>>> @typedispatch
... def f(x:tuple): pass
... 
>>> @typedispatch
... def f(b:B): print('B')
... 
>>> @typedispatch
... def f(x:list): pass
... 
>>> f(B()) 
A
>>> print(f)
(list,object) -> f
(tuple,object) -> f
(A,object) -> f
(int,object) -> f
(B,object) -> f

doing insertion sort variation with the key comparison at hand will solve the issue I believe. I can implement this quickly but would love hearing your opinion first.

Ido

@jph00
Copy link
Contributor

jph00 commented Sep 28, 2020

I'd love to see your approach as a PR - honestly, I didn't put that much time into thinking about the sort, and just kinda used the first thing I tried because it passed my tests! I'm glad you've taken the time to think through it more carefully. A test showing where the existing approach breaks would be very useful to include in the PR.

@jph00 jph00 added the bug Something isn't working label Oct 5, 2020
@jph00 jph00 closed this as completed Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants