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

numpy.zeros not recognized? #22

Closed
charlesdoutriaux opened this issue Aug 16, 2012 · 2 comments
Closed

numpy.zeros not recognized? #22

charlesdoutriaux opened this issue Aug 16, 2012 · 2 comments

Comments

@charlesdoutriaux
Copy link

Hello,

The follwing bare bone function seems to fail to understand numpy.zeros.

I see in the example you could use zero_like maybe, but in my case my output is 1D greater than any input, so I need to create it via a numpy.zeros or similar.

I left the actual function I'm trying to implement commented out, if naybody can comment on obvious numba errors with it please feel free to do so.

Also if I type n1=n2=n3=n4=10 the jit doesn't understand.

import numba
from numba.decorators import jit as jit

def recontruct4DCore(ps,A,B,P0):
## n1,n3,n4 = ps.shape
## n2=A.shape[0]
n1=10
n2=10
n3=10
n4=10
p = numpy.zeros((n1,n2,n3,n4))
## for j in range(n2):
## Afact=A[j]_P0
## for i in range(n1):
## for k in range(n3):
## for l in range(n4):
## p[i,j,k,l]=ps[i,k,l]_B[j]+Afact
return p

numbaReconstruct4D = jit(ret_type = numba.d[:,:,:,:], arg_types=[numba.d[:,:,:],numba.d[:],numba.d[:],numba.d])(recontruct4DCore)

@jriehl
Copy link
Contributor

jriehl commented Aug 17, 2012

There are many Numpy function not currently supported, and numpy.zeros() is no exception. The work around is to use an output parameter, similar to the example in fbcorr.py (modulo the "return" statement, see issue #21). For example:

def recontruct4DCore(ps,A,B,P0, output):
  n1,n3,n4 = ps.shape
  n2=A.shape[0]
  for j in range(n2):
    Afact=A[j]*P0
    for i in range(n1):
      for k in range(n3):
        for l in range(n4):
          output[i,j,k,l]=ps[i,k,l]*B[j]+Afact

Use numpy.zeros() outside the call to this function to create the output array, and it should work (not sure if shape support handles indexing that well, however).

@markflorisson
Copy link
Contributor

np.zeros is recognized now, but a dtype argument needs to be passed in. This is also documented, so I'm closing this for now.

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

3 participants