Comments (2)
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: 948c5b9Ps.- 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.
Passing the argument as an array did the job. And autojit worked perfectly. Thanks
from numba.
Related Issues (20)
- lack of overflow check and incorrect type init when using jitclass HOT 1
- Tuples and inline = 'always' don't play together HOT 5
- `sign` with complex values does not match numpy 2.0 HOT 1
- AttributeError: 'Integer' object has no attribute 'literal_value' #115 HOT 8
- Can Numba use c++functions? HOT 6
- objects from the jitclass lose dynamic features about the class attributions HOT 6
- unchecked out of bound when enable jit HOT 2
- let `new_style` be a superset of `old_style`? HOT 2
- Missing type promotions when doing python API calls HOT 7
- cuInit fails also "else without an if" HOT 4
- config.OPT is not overridden with override_config('OPT', 0) HOT 7
- Inconsistent behavior when handling empty iterator with jit HOT 2
- Change to versioning HOT 4
- Improve DeadBranchPrune to be type aware in `x is None` case HOT 1
- Function with @guvectorize allow the index of array out of bound, not sure if this is in purpose HOT 2
- Strange issue with round() function used in CUDA kernel HOT 1
- Numba njit "parallel=True"& Function Signature & Tuple int64 HOT 2
- Pass NULL pointer for cffi.FFI().from_buffer(empty array) HOT 7
- Allow passing of NULL pointer in CUDA function HOT 2
- compiling code ahead of time error with latest version 0.60.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from numba.