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

In jitclass, will not compile when a member variable is used in numpy.zeros() #5095

Closed
ghost opened this issue Jan 17, 2020 · 5 comments
Closed
Labels
jitclass no action required No action was needed to resolve.

Comments

@ghost
Copy link

ghost commented Jan 17, 2020

outputs = np.zeros((len(inputs), self.output_shape), dtype=float64)

does not work, but

i = self.output_shape
outputs = np.zeros((len(inputs), i), dtype=float64)

does.

@stuartarchibald
Copy link
Contributor

Thanks for the report. Slightly modifying the Bag example from here: https://github.com/numba/numba/blob/master/examples/jitclass.py

I cannot seem to reproduce:

import numpy as np
from numba import jitclass          # import the decorator
from numba import int32, float32    # import the types

spec = [
    ('value', int32),               # a simple scalar field
    ('array', float32[:]),          # an array field
]


@jitclass(spec)
class Bag(object):
    def __init__(self, value):
        self.value = value
        self.array = np.zeros(value, dtype=np.float32)
        outputs = np.zeros((10, self.value), dtype=np.float64)

    @property
    def size(self):
        return self.array.size

    def increment(self, val):
        for i in range(self.size):
            self.array[i] += val
        outputs = np.zeros((10, self.value), dtype=np.float64)
        return self.array, outputs


mybag = Bag(21)
print('isinstance(mybag, Bag)', isinstance(mybag, Bag))
print('mybag.value', mybag.value)
print('mybag.array', mybag.array)
print('mybag.size', mybag.size)
print('mybag.increment(3)', mybag.increment(3))
print('mybag.increment(6)', mybag.increment(6))

Please could you provide more information about what caused this problem:

  1. The code that you were running (as a minimal working reproducer, if you are unsure how to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).
  2. Any data needed to run the code.
  3. The full trace back of the exception.

Once we have a reproducer someone can take a look and work on a fix. Thanks for your help.

@ghost
Copy link
Author

ghost commented Jan 23, 2020

Strangely enough, I'm not able to reproduce the error either. I continued working on my project with my work around because it was time-sensitive. I just came back to this issue and removed the work around and it compiles just fine.

@stuartarchibald
Copy link
Contributor

Thanks for reporting back. Closing this issue as it seems to be resolved. If this is not the case please re-open with a comment about any item that appears to be unresolved. Many thanks.

@stuartarchibald stuartarchibald added no action required No action was needed to resolve. and removed needtriage labels Jan 23, 2020
@capocci-d
Copy link

Dear all, unfortunately I have the same problem i.e. I get an error when I declare a zero-matrix inside a jitclass. Was this issue solved?

@gmarkall
Copy link
Member

@capocci-d It looks like it - if you're having an issue could you please post details of the code you're struggling with on https://numba.discourse.group ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jitclass no action required No action was needed to resolve.
Projects
None yet
Development

No branches or pull requests

3 participants