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

.ptp() not @njit compilable anymore? #6257

Closed
2 tasks done
La-Li-Lu-Le-Loa opened this issue Sep 19, 2020 · 2 comments · Fixed by #6261
Closed
2 tasks done

.ptp() not @njit compilable anymore? #6257

La-Li-Lu-Le-Loa opened this issue Sep 19, 2020 · 2 comments · Fixed by #6261
Labels
question Notes an issue as a question

Comments

@La-Li-Lu-Le-Loa
Copy link

La-Li-Lu-Le-Loa commented Sep 19, 2020

I cant pass numpy arrays like the following to an njit compiled function that contains numpy.ptp().
Why is that ( I think here it says, that .ptp() is supported: https://numba.pydata.org/numba-doc/dev/reference/numpysupported.html)

a = [0.         ,0.         ,0.         ,0.         ,0.         ,0.
,0.         ,0.         ,0.00224828 ,0.00317533 ,0.00830591 ,0.00934349  
,0.80603907 ,0.80603907 ,0.80603907 ,0.80603907 ,0.80603907 ,0.94597275,
1.,        1.,        1.,        1.,        1.,        1., 
1.,       ]

import math
from numba import  prange
@nb.njit(nopython=True,parallel=True)
def anynan(array): 
   for i in prange(array.size):
       if math.isnan(array[i]):
           return True
   return False
@nb.njit
def scale_zero2one(x):
     
   x -= x.min()  
   x /= x.ptp()   
   if anynan(x):  
       x[np.isnan(x)] = 0               
   return x 

a = np.asarray(a,dtype=np.float32) 
print(scale_zero2one(a))
@gmarkall
Copy link
Member

np.ptp is supported, but the .ptp method of array objects is not. Modifying your reproducer to define missing imports, define a, and use np.ptp instead results in a successful compilation:

import math
import numpy as np
from numba import prange, njit


@njit(nopython=True, parallel=True)
def anynan(array):
    for i in prange(array.size):
        if math.isnan(array[i]):
            return True
    return False


@njit
def scale_zero2one(x):

    x -= x.min()
    x /= np.ptp(x)
    if anynan(x):
        x[np.isnan(x)] = 0
    return x


a = [1, 2, 3]

a = np.asarray(a, dtype=np.float32)
print(scale_zero2one(a))

@gmarkall gmarkall added the question Notes an issue as a question label Sep 21, 2020
stuartarchibald added a commit to stuartarchibald/numba that referenced this issue Sep 21, 2020
As title, just wiring.

Fixes numba#6257
@stuartarchibald
Copy link
Contributor

#6261 fixes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Notes an issue as a question
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants