Giter Site home page Giter Site logo

Comments (2)

teoliphant avatar teoliphant commented on July 22, 2024

Currently, you can't return array's from numba functions. Try passing the array in as an argument.

Also, we are deprecating the use of the "d" symbol. Use "f8" instead or "float64". You can also just try using @autojit which will detect types when it's called and compile an appropriate version.

-Travis

On Sep 27, 2012, at 12:59 PM, Hernan Grecco wrote:

While trying Numba for some simple operations I came to this:

import numpy as np

from numba import d, int_
from numba.decorators import jit as jit

@jit(ret_type=d[:], arg_types=[d[:], int_])
def calculate_moments(data, n_moments):

rs = data.shape[0]
result = np.zeros((n_moments, ))
for r in range(rs):
    for m in range(n_moments):
        result[m] += data[r] ** m

return result

data = np.random.random((1000,))
print(calculate_moments(data, 5))
output:

DEBUG -- translate:241:str_to_llvmtype
str_to_llvmtype(): str = ''
Traceback (most recent call last):
File "m1.py", line 9, in
@jit(ret_type=d[:], arg_types=[d[:], int_])
File "/Users/grecco/bin/anaconda/lib/python2.7/site-packages/numba/decorators.py", line 212, in jit
t.translate()
File "/Users/grecco/bin/anaconda/lib/python2.7/site-packages/numba/translate.py", line 951, in translate
getattr(self, 'op
'+name)(i, op, arg)
File "/Users/grecco/bin/anaconda/lib/python2.7/site-packages/numba/translate.py", line 1544, in op_CALL_FUNCTION
func, args = self.func_resolve_type(func, args)
File "/Users/grecco/bin/anaconda/lib/python2.7/site-packages/numba/translate.py", line 1234, in func_resolve_type
lfunc = map_to_function(func.val, typs, self.mod)
File "/Users/grecco/bin/anaconda/lib/python2.7/site-packages/numba/translate.py", line 139, in map_to_function
typs = [str_to_llvmtype(x) if isinstance(x, str) else x for x in typs]
File "/Users/grecco/bin/anaconda/lib/python2.7/site-packages/numba/translate.py", line 246, in str_to_llvmtype
first_char = str[0]
IndexError: string index out of range
I think is related to have result as a np array. It is fine when I run the following (different purpose) code:

import numpy as np

from numba import d, int_
from numba.decorators import jit as jit

@jit(ret_type=d, arg_types=[d[:], int_])
def calculate_moment(data, moment):

rs = data.shape[0]
result = 0.0
for r in range(rs):
    result += data[r] ** moment

return result

data = np.random.random((1000,))
print(calculate_moment(data, 5))
Mac OS X 10.6.8
Python 2.7.3 AnacondaCE (default, Sep 4 2012, 10:42:42)
numba sha1: 948c5b9

Ps.- After writing this, I realized that in the fbcorr example you give the output array


Reply to this email directly or view it on GitHub.

from numba.

hgrecco avatar hgrecco commented on July 22, 2024

Passing the argument as an array did the job. And autojit worked perfectly. Thanks

from numba.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.