numba / numba

NumPy aware dynamic Python compiler using LLVM
https://numba.pydata.org/
BSD 2-Clause "Simplified" License
9.9k stars 1.12k forks source link

[For discussion] Subtyping proposal #5554

Open luk-f-a opened 4 years ago

luk-f-a commented 4 years ago

Hi,

In many cases it would be useful to treat some type as a subtype of another one. In the gist below, I describe a proposal to get this working in Numba

https://gist.github.com/luk-f-a/9063ee1eea50166141a21ee852fb4812

I'm opening this issue for discussion. I am able to take care of the PR once an initial agreement is reached.

cc: @stuartarchibald

stuartarchibald commented 4 years ago

Thanks for proposing this @luk-f-a, ping @sklam @pearu this might be of interest to you?

sklam commented 4 years ago

Oh, row polymorphism for structured dtype

sklam commented 4 years ago

You can get the effect via the existing type conversion system. You can define that two types are compatible by overriding type-conversion methods on the type class.

i.e. https://github.com/numba/numba/blob/ce2139c7dd93127efb04b35f28f4bebc7f44dfd5/numba/core/types/npytypes.py#L453-L462

Conversion kinds are listed in:

https://github.com/numba/numba/blob/ce2139c7dd93127efb04b35f28f4bebc7f44dfd5/numba/core/typeconv/castgraph.py#L6-L27

luk-f-a commented 4 years ago

thanks @sklam, I didn't know about this mechanism. I will look into it.

stuartarchibald commented 2 years ago

@luk-f-a can this be closed since #5560 was merged?