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

No matching definition when using deferred_type #4492

Open
synapticarbors opened this issue Aug 28, 2019 · 1 comment
Open

No matching definition when using deferred_type #4492

synapticarbors opened this issue Aug 28, 2019 · 1 comment
Labels
bug discussion An issue requiring discussion

Comments

@synapticarbors
Copy link
Contributor

In answering a question on Stackoverflow, I came across an issue that I don't fully understand. Disregarding whether you actually need to use a deferred_type, the following fails:

import numpy as np
import numba as nb

spec = [('x', nb.float64)]

@nb.jitclass(spec)
class EarthModel:
    def __init__(self, x):
        self.x = x

earth_model_type = nb.deferred_type()
earth_model_type.define(EarthModel.class_type.instance_type)


@nb.jit(nb.float64(nb.float64[:, :], nb.float64[:, :], nb.float64[:, :], earth_model_type))
def test(x, y, z, em):
    return em.x

when running:

em = EarthModel(9.9)
x = np.random.normal(size=(3,3))
y = np.random.normal(size=(3,3))
z = np.random.normal(size=(3,3))

test(x, y, z, em)

with the error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-d98a87d86d5c> in <module>
      4 z = np.random.normal(size=(3,3))
      5 
----> 6 test(x, y, z, em)

~/miniconda2/envs/numba-latest/lib/python3.7/site-packages/numba/dispatcher.py in _explain_matching_error(self, *args, **kws)
    498         msg = ("No matching definition for argument type(s) %s"
    499                % ', '.join(map(str, args)))
--> 500         raise TypeError(msg)
    501 
    502     def _search_new_conversions(self, *args, **kws):

TypeError: No matching definition for argument type(s) array(float64, 2d, C), array(float64, 2d, C), array(float64, 2d, C), instance.jitclass.EarthModel#6231b36d8<x:float64>

If you instead allow numba to jit the function without supplying types:

import numpy as np
import numba as nb

spec = [('x', nb.float64)]

@nb.jitclass(spec)
class EarthModel:
    def __init__(self, x):
        self.x = x

@nb.jit(nopython=True)
def test(x, y, z, em):
    return em.x

and then this works and the result of test.signatures is:

[(array(float64, 2d, C),
  array(float64, 2d, C),
  array(float64, 2d, C),
  instance.jitclass.EarthModel#623186470<x:float64>)]

so the types look pretty similar. Of course everything works fine if you specify the types, but instead define earth_model_type = EarthModel.class_type.instance_type directly instead of using the deferred_type.

@sklam sklam added bug discussion An issue requiring discussion labels Aug 28, 2019
@sklam
Copy link
Member

sklam commented Aug 28, 2019

The reason for the error is that numba did not register a conversion of the deferred-type from its defined-type. It can be easily fixed by adding a can_convert_from() method to DeferredType.

But, should it?

I expect the DeferredType to be used only as the type of fields of aggregates that can refer to itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug discussion An issue requiring discussion
Projects
None yet
Development

No branches or pull requests

2 participants