Hi,
A friend of mine just pointed out that dividing by int64 is
considerably slower than multiplying in numpy:
<script>
from timeit import timeit
import numpy as np
import numpy.random as npr
sz = (1024,)
a32 = npr.randint(1, 5001, sz).astype(np.int32)
b32 = npr.randint(1, 5001, sz).astype(np.int32)
a64 = a32.astype(np.int64)
b64 = b32.astype(np.int64)
print 'Mul32', timeit('d = a32 * b32', 'from __main__ import a32, b32')
print 'Div32', timeit('d = a32 / b32', 'from __main__ import a32, b32')
print 'Mul64', timeit('d = a64 * b64', 'from __main__ import a64, b64')
print 'Div64', timeit('d = a64 / b64', 'from __main__ import a64, b64')
</script>
gives (64 bit Debian Intel system, numpy trunk):
Mul32 2.71295905113
Div32 6.61985301971
Mul64 2.78101611137
Div64 22.8217148781
with similar values for numpy 1.5.1.
Crude testing with Matlab and Octave suggests they do not seem to have
this same difference:
>> divtest
Mul32 4.300662
Div32 5.638622
Mul64 7.894490
Div64 18.121182
octave:2> divtest
Mul32 3.960577
Div32 6.553704
Mul64 7.268324
Div64 13.670760
(files attached)
Is there something specific about division in numpy that would cause
this slowdown?
Cheers,
Matthew