Comments (7)
It looks like you have 1-d arrays in your examples, but your jit decorator is indicating 2-d arrays (with [:,:]).
Try changing your decorator to:
cmult2arr = autojit(mult2arr)
-Travis
On Dec 21, 2012, at 9:10 AM, mattbellis wrote:
Hi numba developers. I only just learned about this project and it looks extremely interesting. I got everything to build fine and the examples work great. I then went to write my own test to see if there is any speed-up with multiplying two arrays in numba vs. in numpy.
However, I get an error that suggests that multiplication of doubles is not yet supported? I just wanted to make sure I'm interpreting this correctly.
I'm not sure if this is really an ``Issue", but I wasn't sure where else to post . Thanks!
--- snip ---
numba.error.NumbaError: 23:20: Binary operations mul on values typed double[:] and double[:] not (yet) supported
--- snip ---Here's my code, inspired by the current examples.
--- snip ---
from numpy import random,zeros
from numba import double
from numba.decorators import jit as jitimport time
####################################################################
def mult2arr_np(x,y):result = x*y
return result
####################################################################################################################################################
def mult2arr(x,y):ix = len(x)
jy = len(y)
result = zeros(ix)
for i in range(ix):
result[i] = x[i]*y[i]return result
################################################################################cmult2arr = jit(restype=double[:,:], argtypes=[double[:,:],double[:,:]])(mult2arr)
x = random.random(100000)
y = random.random(100000)################################################################################
start = time.time()
res = mult2arr(x,y)
duration = time.time() - start
print "Result from python is %s in %s (msec)" % (res, duration*1000)################################################################################
start = time.time()
res = cmult2arr(x,y)
duration2 = time.time() - start
print "Result from compiled is %s in %s (msec)" % (res, duration2*1000)print "Speed up is %s" % (duration / duration2)
################################################################################
start = time.time()
res = mult2arr_np(x,y)
duration3 = time.time() - start
print "Result from numpy is %s in %s (msec)" % (res, duration3*1000)################################################################################
—
Reply to this email directly or view it on GitHub.
from numba.
Ah, perfect! Thanks!
Obviously, this was not a bug...merely my ignorance. Where is the right place to post questions of this sort?
from numba.
Oh.
One more thing. Rather than import zeros from numpy like you have done, you should do:
import numpy
numpy.zeros(..)
or
import numpy as np
np.zeros(...)
The type-inference only currently works if you use these name-spaces.
If you find your code slower than you expect (i.e. only about 5-6 times faster than Python rather than closer to 100x faster), then try this...
-Travis
On Dec 21, 2012, at 9:10 AM, mattbellis wrote:
Hi numba developers. I only just learned about this project and it looks extremely interesting. I got everything to build fine and the examples work great. I then went to write my own test to see if there is any speed-up with multiplying two arrays in numba vs. in numpy.
However, I get an error that suggests that multiplication of doubles is not yet supported? I just wanted to make sure I'm interpreting this correctly.
I'm not sure if this is really an ``Issue", but I wasn't sure where else to post . Thanks!
--- snip ---
numba.error.NumbaError: 23:20: Binary operations mul on values typed double[:] and double[:] not (yet) supported
--- snip ---Here's my code, inspired by the current examples.
--- snip ---
from numpy import random,zeros
from numba import double
from numba.decorators import jit as jitimport time
####################################################################
def mult2arr_np(x,y):result = x*y
return result
####################################################################################################################################################
def mult2arr(x,y):ix = len(x)
jy = len(y)
result = zeros(ix)
for i in range(ix):
result[i] = x[i]*y[i]return result
################################################################################cmult2arr = jit(restype=double[:,:], argtypes=[double[:,:],double[:,:]])(mult2arr)
x = random.random(100000)
y = random.random(100000)################################################################################
start = time.time()
res = mult2arr(x,y)
duration = time.time() - start
print "Result from python is %s in %s (msec)" % (res, duration*1000)################################################################################
start = time.time()
res = cmult2arr(x,y)
duration2 = time.time() - start
print "Result from compiled is %s in %s (msec)" % (res, duration2*1000)print "Speed up is %s" % (duration / duration2)
################################################################################
start = time.time()
res = mult2arr_np(x,y)
duration3 = time.time() - start
print "Result from numpy is %s in %s (msec)" % (res, duration3*1000)################################################################################
—
Reply to this email directly or view it on GitHub.
from numba.
Hi Travis,
Thanks for the suggestions. Using numba is faster than python, but only about 4x faster than regular python, even with those changes. I'm trying this out with 1M events in the two arrays that I am multiplying. Numpy is about 100x faster than the regular python. You can see the code here:
When I run this, the output is.
Result from python is [ 0.12852594 0.17960238 0.23382419]
in 418.634176254 (msec)
Result from compiled is [ 0.12852594 0.17960238 0.23382419]
in 103.728055954 (msec)
Result from numpy is [ 0.12852594 0.17960238 0.23382419]
in 4.23502922058 (msec)
This isn't pressing for my work or anything, so don't let this distract you from your work on this project. I'm just trying to learn more about it and provide some feedback. :) I'm probably just not using it properly.
Matt
from numba.
You are using autojit, which means it will be compiled when you call it, unless it has a cached version ready. If you use the 'jit' version, it should be significantly better. I'm getting:
Result from python is [ 0.07991542 0.43555985 0.30507656]
in 804.233789444 (msec)
Result from compiled is [ 0.07991542 0.43555985 0.30507656]
in 7.45105743408 (msec)
Result from numpy is [ 0.07991542 0.43555985 0.30507656]
in 2.65884399414 (msec)
So it's still slower, but within a reasonable factor, maybe because it's not vectorized.
from numba.
Ah, ok. I've changed...
cmult2arr = autojit(mult2arr)
to
cmult2arr = jit(restype=double[:], argtypes=[double[:],double[:]])(mult2arr)
I get not quite the numbers you see, but still, significantly better.
Result from python is [ 0.54940225 0.17901628 0.11145486]
in 438.78698349 (msec)
Result from compiled is [ 0.54940225 0.17901628 0.11145486]
in 84.3341350555 (msec)
Result from numpy is [ 0.54940225 0.17901628 0.11145486]
in 3.68285179138 (msec)
I think I understand this all a little better now. For my own purposes, I'm using numpy arrays/functions for much of my work, so I'm getting a pretty big speed-up there. I'll keep following numba and I'm sure in the near future, I'll be using it. Thanks for all the feedback!
from numba.
Looks like this has been resolved. Closing.
from numba.
Related Issues (20)
- Different type hints will result in `TypingError` when using `overload` HOT 3
- Incrementing array location with rank 0 array HOT 6
- LLVM objmode compilation error: Instruction does not dominate all uses HOT 1
- jitclass doesn't use correct type for init arg HOT 1
- 0.60.0rc1 regression: NameError: name 'length_of_iterator' is not defined HOT 2
- Global flag to prefer 32bit whenever possible HOT 3
- Non-det bug with prange code 2 HOT 4
- Parallel providing wrong result on some machine but not on other HOT 28
- `NotImplementedError` for `datetime64[10Y]`
- TypingError when conditionally shadowing variable HOT 2
- numba.typed.List fails for F-contiguous np.ndarrays if one is also C-contiguous HOT 1
- No implementation of function `Function(<built-in function setitem>)` found for signature: `setitem(readonly array(uint64, 3d, C), int64, array(int64, 1d, C))` HOT 1
- numba.core.errors.CompilerError: Failed in nopython mode pipeline (step: analyzing bytecode) / Illegal IR, del found at: del foo HOT 1
- numpy.std() results differ with and without numba HOT 4
- cumprod method doesn't upcast unsigned integer array
- A tuple of uint64 (> 2**63 but < 2**64) as the key of numba Dict HOT 3
- NumPy 2.0 incompatibility - A use of `np.complex_` still remains
- NumPy 2.0 incompatibility: RNG's `__getstate__()` returns `None`
- Specialized CUDA kernels lose a reference to the cache
- using rtsys in objmode incur pickle issue HOT 8
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.