Scalar math module is ready for testing
![](https://secure.gravatar.com/avatar/49df8cd4b1b6056c727778925f86147a.jpg?s=120&d=mm&r=g)
The scalar math module is complete and ready to be tested. It should speed up code that relies heavily on scalar arithmetic by by-passing the ufunc machinery. It needs lots of testing to be sure that it is doing the "right" thing. To enable scalarmath you need to import numpy.core.scalarmath You cannot disable it once it's enabled except by restarting Python. If we need that feature we can add it. The array scalars respond to the error modes of ufuncs. There is an experimental function called alter_scalars that replaces the Python int, float, and complex number tables with the array scalar equivalents. Thus, to amaze (or seriously annoy) your Python friends you can do import numpy.core.scalarmath as ncs ncs.alter_scalars(int) 1 / 0 This will return 0 unless you change the error modes... ncs.retore_scalars(int) Will put things back the way Guido intended.... Please try it out and send us error reports. Many thanks to Sasha for his help in getting all the code so it at least compiles and loads. All bugs should be blamed on me, though... Best, -Travis
![](https://secure.gravatar.com/avatar/beebe07772844149dcd47e23e5276e72.jpg?s=120&d=mm&r=g)
Hi Travis, On Fri, 28 Apr 2006, Travis Oliphant wrote:
LOL ;-)
Well, it does not compile for me (64 Bit opteron, as usual;-): gcc options: '-pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC' compile options: '-Inumpy/core/include -Ibuild/src.linux-x86_64-2.4/numpy/core -Inumpy/core/src -Inumpy/core/include -I/scr/python/include/python2.4 -c' gcc: build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c:472: error: redefinition of 'ulong_ctype_multiply' build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c:421: error: previous definition of 'ulong_ctype_multiply' was here build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c:421: warning: 'ulong_ctype_multiply' defined but not used build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c:472: error: redefinition of 'ulong_ctype_multiply' build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c:421: error: previous definition of 'ulong_ctype_multiply' was here build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c:421: warning: 'ulong_ctype_multiply' defined but not used error: Command "gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -Inumpy/core/include -Ibuild/src.linux-x86_64-2.4/numpy/core -Inumpy/core/src -Inumpy/core/include -I/scr/python/include/python2.4 -c build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c -o build/temp.linux-x86_64-2.4/build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.o" failed with exit status 1 (I can't look into this now - meeting in -2 minutes ;-) Best, Arnd
![](https://secure.gravatar.com/avatar/c248bc10c66731ecd789b0135b635329.jpg?s=120&d=mm&r=g)
Travis Oliphant wrote:
Excellent!
It needs lots of testing to be sure that it is doing the "right" thing.
With revision 2454 I get a segfault in numpy.test() after importing numpy.core.scalarmath: check_1 (numpy.distutils.tests.test_misc_util.test_appendpath) ... ok check_2 (numpy.distutils.tests.test_misc_util.test_appendpath) ... ok check_3 (numpy.distutils.tests.test_misc_util.test_appendpath) ... ok check_gpaths (numpy.distutils.tests.test_misc_util.test_gpaths) ... ok check_1 (numpy.distutils.tests.test_misc_util.test_minrelpath) ... ok check_singleton (numpy.lib.tests.test_getlimits.test_double) Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -1208403744 (LWP 11232)] 0xb7142cf7 in int_richcompare (self=0x81c0ab8, other=0x8141dbc, cmp_op=3) at build/src.linux-i686-2.4/numpy/core/src/scalarmathmodule.c:19120 19120 PyArrayScalar_RETURN_TRUE; (gdb) bt #0 0xb7142cf7 in int_richcompare (self=0x81c0ab8, other=0x8141dbc, cmp_op=3) at build/src.linux-i686-2.4/numpy/core/src/scalarmathmodule.c:19120 #1 0x0807ce1f in PyObject_Print () #2 0x0807e451 in PyObject_RichCompare () Is this helpful? -- Ed
![](https://secure.gravatar.com/avatar/0836223223b7ff2e1d2084065722cfe0.jpg?s=120&d=mm&r=g)
On Friday 28 April 2006 09:12 am, Travis Oliphant wrote:
Running the tests with numpy.test(10) i get: /test/lib/python2.3/site-packages/numpy/testing/numpytest.py:179: DeprecationWarning: Non-ASCII character '\xf2' in file/test/lib/python2.3/site-packages/numpy/lib/tests/test_ufunclike.pyc on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details m = imp.load_module(name, open(filename), filename,('.py','U',1)) E................................../test/lib/python2.3/site-packages/numpy/testing/numpytest.py:179: DeprecationWarning: Non-ASCII character '\xf2' in file test/lib/python2.3/site-packages/numpy/lib/tests/test_polynomial.pyc on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details m = imp.load_module(name, open(filename), filename,('.py','U',1)) E........................................................................... ====================================================================== ERROR: check_doctests (numpy.lib.tests.test_ufunclike.test_docs) ---------------------------------------------------------------------- Traceback (most recent call last): File "/test/lib/python2.3/site-packages/numpy/lib/tests/test_ufunclike.py", line 59, in check_doctests def check_doctests(self): return self.rundocs() File "/test//lib/python2.3/site-packages/numpy/testing/numpytest.py", line 179, in rundocs m = imp.load_module(name, open(filename), filename,('.py','U',1)) File "test/lib/python2.3/site-packages/numpy/lib/tests/test_ufunclike.pyc", line 1 ;ò ^ SyntaxError: invalid syntax ====================================================================== ERROR: check_doctests (numpy.lib.tests.test_polynomial.test_docs) ---------------------------------------------------------------------- Traceback (most recent call last): File "/test/lib/python2.3/site-packages/numpy/lib/tests/test_polynomial.py", line 79, in check_doctests def check_doctests(self): return self.rundocs() File "/test//lib/python2.3/site-packages/numpy/testing/numpytest.py", line 179, in rundocs m = imp.load_module(name, open(filename), filename,('.py','U',1)) File "/test/lib/python2.3/site-packages/numpy/lib/tests/test_polynomial.pyc", line 1 ;ò ^ SyntaxError: invalid syntax I have no idea, where this comes from. Regards, Steffen
![](https://secure.gravatar.com/avatar/fa3279b202e9a85f7d90a0422bca4489.jpg?s=120&d=mm&r=g)
From this it would seem that Microsoft doesn't consider sqrtf and fabsf to be part of the C language? However, the C++ code provides a clue for how
Hello Travis I'm having some problems compiling the scalarmath code with the Visual Studio .NET 2003 compiler. Specifically, the compiler is failing to link in the llabs, fabsf and sqrtf functions. The reason it is not finding these symbols could be explained by the following errors I get when building the object file by hand using the parameters distutils passes to the compiler (for some reason distutils is suppressing compiler output -- this is pretty, but it makes debugging build failures hard): build\src.win32-2.4\numpy\core\src\scalarmathmodule.c(1737) : warning C4013: 'llabs' undefined; assuming extern returning int build\src.win32-2.4\numpy\core\src\scalarmathmodule.c(1751) : warning C4013: 'fabsf' undefined; assuming extern returning int build\src.win32-2.4\numpy\core\src\scalarmathmodule.c(1773) : warning C4013: 'sqrtf' undefined; assuming extern returning int In c:\Program Files\Microsoft Visual Studio .NET 2003\vc7\crt\src\math.h I have the following (extra code stripped): ... #ifndef __cplusplus #define acosl(x) ((long double)acos((double)(x))) #define asinl(x) ((long double)asin((double)(x))) #define atanl(x) ((long double)atan((double)(x))) ... /* NOTE! no sqrtf or fabsf is defined in this block */ #else /* __cplusplus */ ... #if !defined (_M_MRX000) && !defined (_M_ALPHA) && !defined (_M_IA64) /* NOTE! none of the above are defined on x86 */ ... inline float fabsf(float _X) {return ((float)fabs((double)_X)); } ... inline float sqrtf(float _X) {return ((float)sqrt((double)_X)); } ... #endif /* !defined (_M_MRX000) && !defined (_M_ALPHA) && !defined (_M_IA64) */ #endif /* __cplusplus */ they implemented it. Also, llabs isn't defined anywhere. From reading the MSDN docs, I suspect it is called _abs64 on Windows. Regards, Albert
![](https://secure.gravatar.com/avatar/4ad4c6cde7394086a8079e9817417474.jpg?s=120&d=mm&r=g)
Here is an issue I am having with scalarmath:
This happens because PyArray_CanCastSafely returns false for casting from int to short. alter_scalars(int) fixes this, but I have lots of non-numpy code that I don't want to behave differently. Ted On Apr 28, 2006, at 02:12, Travis Oliphant wrote:
![](https://secure.gravatar.com/avatar/beebe07772844149dcd47e23e5276e72.jpg?s=120&d=mm&r=g)
On Fri, 28 Apr 2006, Travis Oliphant wrote:
After numpy compiles on the 64 Bit machine I tried: import numpy import numpy.core.scalarmath numpy.test(1) The only failure is ====================================================================== FAIL: check_basic (numpy.lib.tests.test_function_base.test_prod) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/lib/tests/test_function_base.py", line 149, in check_basic assert_equal(prod(a),26400) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 128, in assert_equal assert desired == actual, msg AssertionError: Items are not equal: DESIRED: 26400 ACTUAL: 26400L ---------------------------------------------------------------------- Ran 363 tests in 0.246s Not sure if this is more a bug of assert_equal? Testing scipy with `import numpy.core.scalarmath` before leads to quite a few errors, many of them related to sparse, see below for an exerpt, and a couple of others. Best, Arnd ====================================================================== ERROR: check_eye (scipy.sparse.tests.test_sparse.test_construct_utils) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/tests/test_sparse.py", line 626, in check_eye a = speye(2, 3 ) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 2810, in speye return spdiags(diags, k, n, m) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 2792, in spdiags return csc_matrix((a, rowa, ptra), dims=(M, N)) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 574, in __init__ self._check() File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 590, in _check raise ValueError, "nzmax must not be less than nnz" ValueError: nzmax must not be less than nnz ====================================================================== ERROR: check_identity (scipy.sparse.tests.test_sparse.test_construct_utils) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/tests/test_sparse.py", line 621, in check_identity a = spidentity(3) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 2800, in spidentity return spdiags( diags, 0, n, n ) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 2792, in spdiags return csc_matrix((a, rowa, ptra), dims=(M, N)) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 574, in __init__ self._check() File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 590, in _check raise ValueError, "nzmax must not be less than nnz" ValueError: nzmax must not be less than nnz ====================================================================== ERROR: check_add (scipy.sparse.tests.test_sparse.test_csc) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/tests/test_sparse.py", line 33, in setUp self.datsp = self.spmatrix(self.dat) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 574, in __init__ self._check() File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 590, in _check raise ValueError, "nzmax must not be less than nnz" ValueError: nzmax must not be less than nnz ====================================================================== ERROR: Check whether adding a dense matrix to a sparse matrix works ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/tests/test_sparse.py", line 33, in setUp self.datsp = self.spmatrix(self.dat) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 574, in __init__ self._check() File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 590, in _check raise ValueError, "nzmax must not be less than nnz" ValueError: nzmax must not be less than nnz ====================================================================== ERROR: Check whether the copy=True and copy=False keywords work ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/tests/test_sparse.py", line 33, in setUp self.datsp = self.spmatrix(self.dat) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 574, in __init__ self._check() File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 590, in _check raise ValueError, "nzmax must not be less than nnz" ValueError: nzmax must not be less than nnz [....] ====================================================================== ERROR: Solve: single precision ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/linsolve/umfpack/tests/test_umfpack.py", line 67, in setUp self.a = spdiags([[1, 2, 3, 4, 5], [6, 5, 8, 9, 10]], [0, 1], 5, 5) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 2792, in spdiags return csc_matrix((a, rowa, ptra), dims=(M, N)) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 574, in __init__ self._check() File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 590, in _check raise ValueError, "nzmax must not be less than nnz" ValueError: nzmax must not be less than nnz ====================================================================== ERROR: check_exact (scipy.stats.tests.test_morestats.test_ansari) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/stats/tests/test_morestats.py", line 79, in check_exact W,pval = stats.ansari([1,2,3,4],[15,5,20,8,10,12]) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/stats/morestats.py", line 591, in ansari pval = 2.0*sum(a1[:cind+1])/total TypeError: unsupported operand type(s) for *: 'float' and 'float32scalar' ====================================================================== FAIL: check_simple_complex (scipy.linalg.tests.test_decomp.test_eigvals) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/linalg/tests/test_decomp.py", line 53, in check_simple_complex assert_array_almost_equal(w,exact_w) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 66.6666666667%): Array 1: [ 9.2983779e+00 +6.5630282e-01j -5.5210285e-16 -1.7300711e-16j -2.9837791e-01 +3.4369718e-01j] Array 2: [ 1.+0.0705825j 0.+0.j 1.-1.1518855j] ====================================================================== FAIL: check_definition (scipy.fftpack.tests.test_basic.test_ifft) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/fftpack/tests/test_basic.py", line 183, in check_definition assert_array_almost_equal(y,y1) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [ 2.5 +0.375j 0.0883883+0.0883883j -0.125 -0.5j 0.0883883-0.0883883j -0.5 -0.375j -0.0883883-0.0... Array 2: [ 1.+0.15j 1.+1.j 1.+4.j 1.-1.j 1.+0.75j 1.+1.j 1.-0.5714286j 1.-1.j ] ====================================================================== FAIL: check_definition (scipy.fftpack.tests.test_basic.test_irfft) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/fftpack/tests/test_basic.py", line 340, in check_definition assert_array_almost_equal(y,y1) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [ 2.625 -1.6856602 -0.375 -1.1856602 0.625 0.4356602 -0.375 0.9356602] Array 2: [ 1. 1. 1. 1. 1. 1. 1. 1.] ====================================================================== FAIL: check_h1vp (scipy.special.tests.test_basic.test_h1vp) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/special/tests/test_basic.py", line 1118, in check_h1vp assert_almost_equal(h1,h1real,8) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 148, in assert_almost_equal assert round(abs(desired - actual),decimal) == 0, msg AssertionError: Items are not equal: DESIRED: (0.49812630170362004+63.055272295669909j) ACTUAL: (1+126.58490844594492j) ====================================================================== FAIL: check_h2vp (scipy.special.tests.test_basic.test_h2vp) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/special/tests/test_basic.py", line 1125, in check_h2vp assert_almost_equal(h2,h2real,8) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 148, in assert_almost_equal assert round(abs(desired - actual),decimal) == 0, msg AssertionError: Items are not equal: DESIRED: (0.49812630170362004-63.055272295669909j) ACTUAL: (1-126.58490844594492j) ====================================================================== FAIL: check_nils (scipy.linalg.tests.test_matfuncs.test_signm) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/linalg/tests/test_matfuncs.py", line 42, in check_nils assert_array_almost_equal(r,cr) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [[ 20.728 -6.576 29.592 32.88 -6.576] [ -5.808 2.936 -8.712 -9.68 1.936] [ -6.24 2.08 -8.36 -10.4 ... Array 2: [[ 11.9493333 -2.2453333 15.3173333 21.6533333 -2.2453333] [ -3.8426667 0.4986667 -4.5906667 -7.1866667 0.498... ====================================================================== FAIL: check_bad (scipy.linalg.tests.test_matfuncs.test_sqrtm) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/linalg/tests/test_matfuncs.py", line 99, in check_bad assert_array_almost_equal(dot(esa,esa),a) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [[ nan +nanj nan +n... Array 2: [[ 1. 0. 0. 1. ] [ 0. 0.03125 0. 0. ] [ 0. 0. 0.03125 0. ] [ ... ---------------------------------------------------------------------- Ran 1119 tests in 1.151s FAILED (failures=7, errors=82)
![](https://secure.gravatar.com/avatar/612395b66b3e7959997007b342b3688a.jpg?s=120&d=mm&r=g)
Arnd Baecker wrote:
On 32 bit : scipy.test(1) results in ====================================================================== ERROR: check_exact (scipy.stats.tests.test_morestats.test_ansari) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/stats/tests/test_morestats.py", line 79, in check_exact W,pval = stats.ansari([1,2,3,4],[15,5,20,8,10,12]) File "/usr/lib/python2.4/site-packages/scipy/stats/morestats.py", line 591, in ansari pval = 2.0*sum(a1[:cind+1])/total TypeError: unsupported operand type(s) for *: 'float' and 'float32scalar' ====================================================================== FAIL: check_simple_complex (scipy.linalg.tests.test_decomp.test_eigvals) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/linalg/tests/test_decomp.py", line 53, in check_simple_complex assert_array_almost_equal(w,exact_w) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 66.6666666667%): Array 1: [ 9.2983779e+00 +6.5630282e-01j -4.1690526e-16 -9.3738002e-17j -2.9837791e-01 +3.4369718e-01j] Array 2: [ 1.+0.0705825j 0.+0.j 1.-1.1518855j] ====================================================================== FAIL: check_definition (scipy.fftpack.tests.test_basic.test_ifft) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/fftpack/tests/test_basic.py", line 183, in check_definition assert_array_almost_equal(y,y1) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [ 2.5 +0.375j 0.0883883+0.0883883j -0.125 -0.5j 0.0883883-0.0883883j -0.5 -0.375j -0.0883883-0.0... Array 2: [ 1.+0.15j 1.+1.j 1.+4.j 1.-1.j 1.+0.75j 1.+1.j 1.-0.5714286j 1.-1.j ] ====================================================================== FAIL: check_definition (scipy.fftpack.tests.test_basic.test_irfft) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/fftpack/tests/test_basic.py", line 340, in check_definition assert_array_almost_equal(y,y1) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [ 2.625 -1.6856602 -0.375 -1.1856602 0.625 0.4356602 -0.375 0.9356602] Array 2: [ 1. 1. 1. 1. 1. 1. 1. 1.] ====================================================================== FAIL: check_h1vp (scipy.special.tests.test_basic.test_h1vp) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/special/tests/test_basic.py", line 1118, in check_h1vp assert_almost_equal(h1,h1real,8) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 148, in assert_almost_equal assert round(abs(desired - actual),decimal) == 0, msg AssertionError: Items are not equal: DESIRED: (0.49812630170362004+63.055272295669901j) ACTUAL: (1+126.58490844594493j) ====================================================================== FAIL: check_h2vp (scipy.special.tests.test_basic.test_h2vp) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/special/tests/test_basic.py", line 1125, in check_h2vp assert_almost_equal(h2,h2real,8) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 148, in assert_almost_equal assert round(abs(desired - actual),decimal) == 0, msg AssertionError: Items are not equal: DESIRED: (0.49812630170362004-63.055272295669901j) ACTUAL: (1-126.58490844594493j) ====================================================================== FAIL: check_nils (scipy.linalg.tests.test_matfuncs.test_signm) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/linalg/tests/test_matfuncs.py", line 42, in check_nils assert_array_almost_equal(r,cr) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [[ 20.728 -6.576 29.592 32.88 -6.576] [ -5.808 2.936 -8.712 -9.68 1.936] [ -6.24 2.08 -8.36 -10.4 ... Array 2: [[ 11.9493333 -2.2453333 15.3173333 21.6533333 -2.2453333] [ -3.8426667 0.4986667 -4.5906667 -7.1866667 0.498... ====================================================================== FAIL: check_bad (scipy.linalg.tests.test_matfuncs.test_sqrtm) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/linalg/tests/test_matfuncs.py", line 99, in check_bad assert_array_almost_equal(dot(esa,esa),a) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [[ nan +nanj nan +nanj nan ... Array 2: [[ 1. 0. 0. 1. ] [ 0. 0.03125 0. 0. ] [ 0. 0. 0.03125 0. ] [ ... ---------------------------------------------------------------------- Ran 1516 tests in 7.346s FAILED (failures=7, errors=1) and numpy.test(1) yields ====================================================================== FAIL: check_basic (numpy.lib.tests.test_function_base.test_prod) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/numpy/lib/tests/test_function_base.py", line 149, in check_basic assert_equal(prod(a),26400) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 128, in assert_equal assert desired == actual, msg AssertionError: Items are not equal: DESIRED: 26400 ACTUAL: 26400L ---------------------------------------------------------------------- Ran 363 tests in 0.935s FAILED (failures=1) Nils
![](https://secure.gravatar.com/avatar/0836223223b7ff2e1d2084065722cfe0.jpg?s=120&d=mm&r=g)
After changing some code to numpy/new scipy my programs slowed down remarkably, so i did some comparison between Numeric, numpy and math using timeit.py. At first the sin(x) function was tested: Results (in usec per loop): sin-scalar sin-array Numeric 118 130 numpy 66.3 191 numpy + scalarmath 65.8 112 numpy + math 12.3 143 numpy + math + scalarmath 14.7 37.8 Numeric + math 14.8 22.3 The scripts are shown at the end. So using numpy.core.scalarmath improves speed. The fastest way however is using Numeric and the sin function from math. Second is the test of the modulo operation %: %-array Numeric 17.1 numpy 299 numpy + scalarmath 55.6 Things get faster using scalarmath but are still four times slower then with Numeric. Is there any possibility to speed up the modulo operation? scripts: Numeric: /usr/lib/python2.3/timeit.py \ -s "from Numeric import sin,arange; x=0.1" "for i in arange(9): x=sin(x)" /usr/lib/python2.3/timeit.py \ -s "from Numeric import sin,zeros,arange; x=x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=sin(x[i])" /usr/lib/python2.3/timeit.py \ -s "from Numeric import zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=(x[i]+1.1)%(1.0)" numpy: /usr/lib/python2.3/timeit.py \ -s "from numpy import sin,arange; x=0.1" "for i in arange(9): x=sin(x)" /usr/lib/python2.3/timeit.py \ -s "from numpy import sin,zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=sin(x[i])" /usr/lib/python2.3/timeit.py \ -s "from numpy import zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=(x[i]+1.1)%(1.0)" numpy + scalarmath: /usr/lib/python2.3/timeit.py \ -s "import numpy.core.scalarmath; from numpy import sin; x=0.1"\ "for i in xrange(9): x=sin(x)" /usr/lib/python2.3/timeit.py \ -s "import numpy.core.scalarmath; from numpy import sin,zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=sin(x[i])" /usr/lib/python2.3/timeit.py \ -s "import numpy.core.scalarmath; from numpy import zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=(x[i]+1.1)%(1.0)" numpy + math: /usr/lib/python2.3/timeit.py \ -s "from math import sin; from numpy import arange; x=0.1"\ "for i in arange(9): x=sin(x)" /usr/lib/python2.3/timeit.py \ -s "from math import sin; from numpy import zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=sin(x[i])" numpy + scalarmath + math /usr/lib/python2.3/timeit.py \ -s "import numpy.core.scalarmath; from math import sin; from numpy import arange; x=0.1"\ "for i in arange(9): x=sin(x)" /usr/lib/python2.3/timeit.py \ -s "import numpy.core.scalarmath; from math import sin; from numpy import zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=sin(x[i])" Numeric + math /usr/lib/python2.3/timeit.py \ -s "from math import sin; from Numeric import arange; x=0.1"\ "for i in arange(9): x=sin(x)" /usr/lib/python2.3/timeit.py \ -s "from math import sin; from Numeric import zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=sin(x[i])" Regards, Steffen
![](https://secure.gravatar.com/avatar/beebe07772844149dcd47e23e5276e72.jpg?s=120&d=mm&r=g)
Hi Travis, On Fri, 28 Apr 2006, Travis Oliphant wrote:
LOL ;-)
Well, it does not compile for me (64 Bit opteron, as usual;-): gcc options: '-pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC' compile options: '-Inumpy/core/include -Ibuild/src.linux-x86_64-2.4/numpy/core -Inumpy/core/src -Inumpy/core/include -I/scr/python/include/python2.4 -c' gcc: build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c:472: error: redefinition of 'ulong_ctype_multiply' build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c:421: error: previous definition of 'ulong_ctype_multiply' was here build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c:421: warning: 'ulong_ctype_multiply' defined but not used build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c:472: error: redefinition of 'ulong_ctype_multiply' build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c:421: error: previous definition of 'ulong_ctype_multiply' was here build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c:421: warning: 'ulong_ctype_multiply' defined but not used error: Command "gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -Inumpy/core/include -Ibuild/src.linux-x86_64-2.4/numpy/core -Inumpy/core/src -Inumpy/core/include -I/scr/python/include/python2.4 -c build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.c -o build/temp.linux-x86_64-2.4/build/src.linux-x86_64-2.4/numpy/core/src/scalarmathmodule.o" failed with exit status 1 (I can't look into this now - meeting in -2 minutes ;-) Best, Arnd
![](https://secure.gravatar.com/avatar/c248bc10c66731ecd789b0135b635329.jpg?s=120&d=mm&r=g)
Travis Oliphant wrote:
Excellent!
It needs lots of testing to be sure that it is doing the "right" thing.
With revision 2454 I get a segfault in numpy.test() after importing numpy.core.scalarmath: check_1 (numpy.distutils.tests.test_misc_util.test_appendpath) ... ok check_2 (numpy.distutils.tests.test_misc_util.test_appendpath) ... ok check_3 (numpy.distutils.tests.test_misc_util.test_appendpath) ... ok check_gpaths (numpy.distutils.tests.test_misc_util.test_gpaths) ... ok check_1 (numpy.distutils.tests.test_misc_util.test_minrelpath) ... ok check_singleton (numpy.lib.tests.test_getlimits.test_double) Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -1208403744 (LWP 11232)] 0xb7142cf7 in int_richcompare (self=0x81c0ab8, other=0x8141dbc, cmp_op=3) at build/src.linux-i686-2.4/numpy/core/src/scalarmathmodule.c:19120 19120 PyArrayScalar_RETURN_TRUE; (gdb) bt #0 0xb7142cf7 in int_richcompare (self=0x81c0ab8, other=0x8141dbc, cmp_op=3) at build/src.linux-i686-2.4/numpy/core/src/scalarmathmodule.c:19120 #1 0x0807ce1f in PyObject_Print () #2 0x0807e451 in PyObject_RichCompare () Is this helpful? -- Ed
![](https://secure.gravatar.com/avatar/0836223223b7ff2e1d2084065722cfe0.jpg?s=120&d=mm&r=g)
On Friday 28 April 2006 09:12 am, Travis Oliphant wrote:
Running the tests with numpy.test(10) i get: /test/lib/python2.3/site-packages/numpy/testing/numpytest.py:179: DeprecationWarning: Non-ASCII character '\xf2' in file/test/lib/python2.3/site-packages/numpy/lib/tests/test_ufunclike.pyc on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details m = imp.load_module(name, open(filename), filename,('.py','U',1)) E................................../test/lib/python2.3/site-packages/numpy/testing/numpytest.py:179: DeprecationWarning: Non-ASCII character '\xf2' in file test/lib/python2.3/site-packages/numpy/lib/tests/test_polynomial.pyc on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details m = imp.load_module(name, open(filename), filename,('.py','U',1)) E........................................................................... ====================================================================== ERROR: check_doctests (numpy.lib.tests.test_ufunclike.test_docs) ---------------------------------------------------------------------- Traceback (most recent call last): File "/test/lib/python2.3/site-packages/numpy/lib/tests/test_ufunclike.py", line 59, in check_doctests def check_doctests(self): return self.rundocs() File "/test//lib/python2.3/site-packages/numpy/testing/numpytest.py", line 179, in rundocs m = imp.load_module(name, open(filename), filename,('.py','U',1)) File "test/lib/python2.3/site-packages/numpy/lib/tests/test_ufunclike.pyc", line 1 ;ò ^ SyntaxError: invalid syntax ====================================================================== ERROR: check_doctests (numpy.lib.tests.test_polynomial.test_docs) ---------------------------------------------------------------------- Traceback (most recent call last): File "/test/lib/python2.3/site-packages/numpy/lib/tests/test_polynomial.py", line 79, in check_doctests def check_doctests(self): return self.rundocs() File "/test//lib/python2.3/site-packages/numpy/testing/numpytest.py", line 179, in rundocs m = imp.load_module(name, open(filename), filename,('.py','U',1)) File "/test/lib/python2.3/site-packages/numpy/lib/tests/test_polynomial.pyc", line 1 ;ò ^ SyntaxError: invalid syntax I have no idea, where this comes from. Regards, Steffen
![](https://secure.gravatar.com/avatar/fa3279b202e9a85f7d90a0422bca4489.jpg?s=120&d=mm&r=g)
From this it would seem that Microsoft doesn't consider sqrtf and fabsf to be part of the C language? However, the C++ code provides a clue for how
Hello Travis I'm having some problems compiling the scalarmath code with the Visual Studio .NET 2003 compiler. Specifically, the compiler is failing to link in the llabs, fabsf and sqrtf functions. The reason it is not finding these symbols could be explained by the following errors I get when building the object file by hand using the parameters distutils passes to the compiler (for some reason distutils is suppressing compiler output -- this is pretty, but it makes debugging build failures hard): build\src.win32-2.4\numpy\core\src\scalarmathmodule.c(1737) : warning C4013: 'llabs' undefined; assuming extern returning int build\src.win32-2.4\numpy\core\src\scalarmathmodule.c(1751) : warning C4013: 'fabsf' undefined; assuming extern returning int build\src.win32-2.4\numpy\core\src\scalarmathmodule.c(1773) : warning C4013: 'sqrtf' undefined; assuming extern returning int In c:\Program Files\Microsoft Visual Studio .NET 2003\vc7\crt\src\math.h I have the following (extra code stripped): ... #ifndef __cplusplus #define acosl(x) ((long double)acos((double)(x))) #define asinl(x) ((long double)asin((double)(x))) #define atanl(x) ((long double)atan((double)(x))) ... /* NOTE! no sqrtf or fabsf is defined in this block */ #else /* __cplusplus */ ... #if !defined (_M_MRX000) && !defined (_M_ALPHA) && !defined (_M_IA64) /* NOTE! none of the above are defined on x86 */ ... inline float fabsf(float _X) {return ((float)fabs((double)_X)); } ... inline float sqrtf(float _X) {return ((float)sqrt((double)_X)); } ... #endif /* !defined (_M_MRX000) && !defined (_M_ALPHA) && !defined (_M_IA64) */ #endif /* __cplusplus */ they implemented it. Also, llabs isn't defined anywhere. From reading the MSDN docs, I suspect it is called _abs64 on Windows. Regards, Albert
![](https://secure.gravatar.com/avatar/4ad4c6cde7394086a8079e9817417474.jpg?s=120&d=mm&r=g)
Here is an issue I am having with scalarmath:
This happens because PyArray_CanCastSafely returns false for casting from int to short. alter_scalars(int) fixes this, but I have lots of non-numpy code that I don't want to behave differently. Ted On Apr 28, 2006, at 02:12, Travis Oliphant wrote:
![](https://secure.gravatar.com/avatar/beebe07772844149dcd47e23e5276e72.jpg?s=120&d=mm&r=g)
On Fri, 28 Apr 2006, Travis Oliphant wrote:
After numpy compiles on the 64 Bit machine I tried: import numpy import numpy.core.scalarmath numpy.test(1) The only failure is ====================================================================== FAIL: check_basic (numpy.lib.tests.test_function_base.test_prod) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/lib/tests/test_function_base.py", line 149, in check_basic assert_equal(prod(a),26400) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 128, in assert_equal assert desired == actual, msg AssertionError: Items are not equal: DESIRED: 26400 ACTUAL: 26400L ---------------------------------------------------------------------- Ran 363 tests in 0.246s Not sure if this is more a bug of assert_equal? Testing scipy with `import numpy.core.scalarmath` before leads to quite a few errors, many of them related to sparse, see below for an exerpt, and a couple of others. Best, Arnd ====================================================================== ERROR: check_eye (scipy.sparse.tests.test_sparse.test_construct_utils) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/tests/test_sparse.py", line 626, in check_eye a = speye(2, 3 ) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 2810, in speye return spdiags(diags, k, n, m) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 2792, in spdiags return csc_matrix((a, rowa, ptra), dims=(M, N)) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 574, in __init__ self._check() File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 590, in _check raise ValueError, "nzmax must not be less than nnz" ValueError: nzmax must not be less than nnz ====================================================================== ERROR: check_identity (scipy.sparse.tests.test_sparse.test_construct_utils) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/tests/test_sparse.py", line 621, in check_identity a = spidentity(3) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 2800, in spidentity return spdiags( diags, 0, n, n ) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 2792, in spdiags return csc_matrix((a, rowa, ptra), dims=(M, N)) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 574, in __init__ self._check() File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 590, in _check raise ValueError, "nzmax must not be less than nnz" ValueError: nzmax must not be less than nnz ====================================================================== ERROR: check_add (scipy.sparse.tests.test_sparse.test_csc) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/tests/test_sparse.py", line 33, in setUp self.datsp = self.spmatrix(self.dat) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 574, in __init__ self._check() File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 590, in _check raise ValueError, "nzmax must not be less than nnz" ValueError: nzmax must not be less than nnz ====================================================================== ERROR: Check whether adding a dense matrix to a sparse matrix works ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/tests/test_sparse.py", line 33, in setUp self.datsp = self.spmatrix(self.dat) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 574, in __init__ self._check() File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 590, in _check raise ValueError, "nzmax must not be less than nnz" ValueError: nzmax must not be less than nnz ====================================================================== ERROR: Check whether the copy=True and copy=False keywords work ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/tests/test_sparse.py", line 33, in setUp self.datsp = self.spmatrix(self.dat) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 574, in __init__ self._check() File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 590, in _check raise ValueError, "nzmax must not be less than nnz" ValueError: nzmax must not be less than nnz [....] ====================================================================== ERROR: Solve: single precision ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/linsolve/umfpack/tests/test_umfpack.py", line 67, in setUp self.a = spdiags([[1, 2, 3, 4, 5], [6, 5, 8, 9, 10]], [0, 1], 5, 5) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 2792, in spdiags return csc_matrix((a, rowa, ptra), dims=(M, N)) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 574, in __init__ self._check() File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 590, in _check raise ValueError, "nzmax must not be less than nnz" ValueError: nzmax must not be less than nnz ====================================================================== ERROR: check_exact (scipy.stats.tests.test_morestats.test_ansari) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/stats/tests/test_morestats.py", line 79, in check_exact W,pval = stats.ansari([1,2,3,4],[15,5,20,8,10,12]) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/stats/morestats.py", line 591, in ansari pval = 2.0*sum(a1[:cind+1])/total TypeError: unsupported operand type(s) for *: 'float' and 'float32scalar' ====================================================================== FAIL: check_simple_complex (scipy.linalg.tests.test_decomp.test_eigvals) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/linalg/tests/test_decomp.py", line 53, in check_simple_complex assert_array_almost_equal(w,exact_w) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 66.6666666667%): Array 1: [ 9.2983779e+00 +6.5630282e-01j -5.5210285e-16 -1.7300711e-16j -2.9837791e-01 +3.4369718e-01j] Array 2: [ 1.+0.0705825j 0.+0.j 1.-1.1518855j] ====================================================================== FAIL: check_definition (scipy.fftpack.tests.test_basic.test_ifft) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/fftpack/tests/test_basic.py", line 183, in check_definition assert_array_almost_equal(y,y1) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [ 2.5 +0.375j 0.0883883+0.0883883j -0.125 -0.5j 0.0883883-0.0883883j -0.5 -0.375j -0.0883883-0.0... Array 2: [ 1.+0.15j 1.+1.j 1.+4.j 1.-1.j 1.+0.75j 1.+1.j 1.-0.5714286j 1.-1.j ] ====================================================================== FAIL: check_definition (scipy.fftpack.tests.test_basic.test_irfft) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/fftpack/tests/test_basic.py", line 340, in check_definition assert_array_almost_equal(y,y1) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [ 2.625 -1.6856602 -0.375 -1.1856602 0.625 0.4356602 -0.375 0.9356602] Array 2: [ 1. 1. 1. 1. 1. 1. 1. 1.] ====================================================================== FAIL: check_h1vp (scipy.special.tests.test_basic.test_h1vp) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/special/tests/test_basic.py", line 1118, in check_h1vp assert_almost_equal(h1,h1real,8) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 148, in assert_almost_equal assert round(abs(desired - actual),decimal) == 0, msg AssertionError: Items are not equal: DESIRED: (0.49812630170362004+63.055272295669909j) ACTUAL: (1+126.58490844594492j) ====================================================================== FAIL: check_h2vp (scipy.special.tests.test_basic.test_h2vp) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/special/tests/test_basic.py", line 1125, in check_h2vp assert_almost_equal(h2,h2real,8) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 148, in assert_almost_equal assert round(abs(desired - actual),decimal) == 0, msg AssertionError: Items are not equal: DESIRED: (0.49812630170362004-63.055272295669909j) ACTUAL: (1-126.58490844594492j) ====================================================================== FAIL: check_nils (scipy.linalg.tests.test_matfuncs.test_signm) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/linalg/tests/test_matfuncs.py", line 42, in check_nils assert_array_almost_equal(r,cr) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [[ 20.728 -6.576 29.592 32.88 -6.576] [ -5.808 2.936 -8.712 -9.68 1.936] [ -6.24 2.08 -8.36 -10.4 ... Array 2: [[ 11.9493333 -2.2453333 15.3173333 21.6533333 -2.2453333] [ -3.8426667 0.4986667 -4.5906667 -7.1866667 0.498... ====================================================================== FAIL: check_bad (scipy.linalg.tests.test_matfuncs.test_sqrtm) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/scipy/linalg/tests/test_matfuncs.py", line 99, in check_bad assert_array_almost_equal(dot(esa,esa),a) File "/home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [[ nan +nanj nan +n... Array 2: [[ 1. 0. 0. 1. ] [ 0. 0.03125 0. 0. ] [ 0. 0. 0.03125 0. ] [ ... ---------------------------------------------------------------------- Ran 1119 tests in 1.151s FAILED (failures=7, errors=82)
![](https://secure.gravatar.com/avatar/612395b66b3e7959997007b342b3688a.jpg?s=120&d=mm&r=g)
Arnd Baecker wrote:
On 32 bit : scipy.test(1) results in ====================================================================== ERROR: check_exact (scipy.stats.tests.test_morestats.test_ansari) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/stats/tests/test_morestats.py", line 79, in check_exact W,pval = stats.ansari([1,2,3,4],[15,5,20,8,10,12]) File "/usr/lib/python2.4/site-packages/scipy/stats/morestats.py", line 591, in ansari pval = 2.0*sum(a1[:cind+1])/total TypeError: unsupported operand type(s) for *: 'float' and 'float32scalar' ====================================================================== FAIL: check_simple_complex (scipy.linalg.tests.test_decomp.test_eigvals) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/linalg/tests/test_decomp.py", line 53, in check_simple_complex assert_array_almost_equal(w,exact_w) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 66.6666666667%): Array 1: [ 9.2983779e+00 +6.5630282e-01j -4.1690526e-16 -9.3738002e-17j -2.9837791e-01 +3.4369718e-01j] Array 2: [ 1.+0.0705825j 0.+0.j 1.-1.1518855j] ====================================================================== FAIL: check_definition (scipy.fftpack.tests.test_basic.test_ifft) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/fftpack/tests/test_basic.py", line 183, in check_definition assert_array_almost_equal(y,y1) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [ 2.5 +0.375j 0.0883883+0.0883883j -0.125 -0.5j 0.0883883-0.0883883j -0.5 -0.375j -0.0883883-0.0... Array 2: [ 1.+0.15j 1.+1.j 1.+4.j 1.-1.j 1.+0.75j 1.+1.j 1.-0.5714286j 1.-1.j ] ====================================================================== FAIL: check_definition (scipy.fftpack.tests.test_basic.test_irfft) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/fftpack/tests/test_basic.py", line 340, in check_definition assert_array_almost_equal(y,y1) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [ 2.625 -1.6856602 -0.375 -1.1856602 0.625 0.4356602 -0.375 0.9356602] Array 2: [ 1. 1. 1. 1. 1. 1. 1. 1.] ====================================================================== FAIL: check_h1vp (scipy.special.tests.test_basic.test_h1vp) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/special/tests/test_basic.py", line 1118, in check_h1vp assert_almost_equal(h1,h1real,8) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 148, in assert_almost_equal assert round(abs(desired - actual),decimal) == 0, msg AssertionError: Items are not equal: DESIRED: (0.49812630170362004+63.055272295669901j) ACTUAL: (1+126.58490844594493j) ====================================================================== FAIL: check_h2vp (scipy.special.tests.test_basic.test_h2vp) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/special/tests/test_basic.py", line 1125, in check_h2vp assert_almost_equal(h2,h2real,8) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 148, in assert_almost_equal assert round(abs(desired - actual),decimal) == 0, msg AssertionError: Items are not equal: DESIRED: (0.49812630170362004-63.055272295669901j) ACTUAL: (1-126.58490844594493j) ====================================================================== FAIL: check_nils (scipy.linalg.tests.test_matfuncs.test_signm) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/linalg/tests/test_matfuncs.py", line 42, in check_nils assert_array_almost_equal(r,cr) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [[ 20.728 -6.576 29.592 32.88 -6.576] [ -5.808 2.936 -8.712 -9.68 1.936] [ -6.24 2.08 -8.36 -10.4 ... Array 2: [[ 11.9493333 -2.2453333 15.3173333 21.6533333 -2.2453333] [ -3.8426667 0.4986667 -4.5906667 -7.1866667 0.498... ====================================================================== FAIL: check_bad (scipy.linalg.tests.test_matfuncs.test_sqrtm) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/scipy/linalg/tests/test_matfuncs.py", line 99, in check_bad assert_array_almost_equal(dot(esa,esa),a) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 231, in assert_array_almost_equal assert cond,\ AssertionError: Arrays are not almost equal (mismatch 100.0%): Array 1: [[ nan +nanj nan +nanj nan ... Array 2: [[ 1. 0. 0. 1. ] [ 0. 0.03125 0. 0. ] [ 0. 0. 0.03125 0. ] [ ... ---------------------------------------------------------------------- Ran 1516 tests in 7.346s FAILED (failures=7, errors=1) and numpy.test(1) yields ====================================================================== FAIL: check_basic (numpy.lib.tests.test_function_base.test_prod) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/numpy/lib/tests/test_function_base.py", line 149, in check_basic assert_equal(prod(a),26400) File "/usr/lib/python2.4/site-packages/numpy/testing/utils.py", line 128, in assert_equal assert desired == actual, msg AssertionError: Items are not equal: DESIRED: 26400 ACTUAL: 26400L ---------------------------------------------------------------------- Ran 363 tests in 0.935s FAILED (failures=1) Nils
![](https://secure.gravatar.com/avatar/0836223223b7ff2e1d2084065722cfe0.jpg?s=120&d=mm&r=g)
After changing some code to numpy/new scipy my programs slowed down remarkably, so i did some comparison between Numeric, numpy and math using timeit.py. At first the sin(x) function was tested: Results (in usec per loop): sin-scalar sin-array Numeric 118 130 numpy 66.3 191 numpy + scalarmath 65.8 112 numpy + math 12.3 143 numpy + math + scalarmath 14.7 37.8 Numeric + math 14.8 22.3 The scripts are shown at the end. So using numpy.core.scalarmath improves speed. The fastest way however is using Numeric and the sin function from math. Second is the test of the modulo operation %: %-array Numeric 17.1 numpy 299 numpy + scalarmath 55.6 Things get faster using scalarmath but are still four times slower then with Numeric. Is there any possibility to speed up the modulo operation? scripts: Numeric: /usr/lib/python2.3/timeit.py \ -s "from Numeric import sin,arange; x=0.1" "for i in arange(9): x=sin(x)" /usr/lib/python2.3/timeit.py \ -s "from Numeric import sin,zeros,arange; x=x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=sin(x[i])" /usr/lib/python2.3/timeit.py \ -s "from Numeric import zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=(x[i]+1.1)%(1.0)" numpy: /usr/lib/python2.3/timeit.py \ -s "from numpy import sin,arange; x=0.1" "for i in arange(9): x=sin(x)" /usr/lib/python2.3/timeit.py \ -s "from numpy import sin,zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=sin(x[i])" /usr/lib/python2.3/timeit.py \ -s "from numpy import zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=(x[i]+1.1)%(1.0)" numpy + scalarmath: /usr/lib/python2.3/timeit.py \ -s "import numpy.core.scalarmath; from numpy import sin; x=0.1"\ "for i in xrange(9): x=sin(x)" /usr/lib/python2.3/timeit.py \ -s "import numpy.core.scalarmath; from numpy import sin,zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=sin(x[i])" /usr/lib/python2.3/timeit.py \ -s "import numpy.core.scalarmath; from numpy import zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=(x[i]+1.1)%(1.0)" numpy + math: /usr/lib/python2.3/timeit.py \ -s "from math import sin; from numpy import arange; x=0.1"\ "for i in arange(9): x=sin(x)" /usr/lib/python2.3/timeit.py \ -s "from math import sin; from numpy import zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=sin(x[i])" numpy + scalarmath + math /usr/lib/python2.3/timeit.py \ -s "import numpy.core.scalarmath; from math import sin; from numpy import arange; x=0.1"\ "for i in arange(9): x=sin(x)" /usr/lib/python2.3/timeit.py \ -s "import numpy.core.scalarmath; from math import sin; from numpy import zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=sin(x[i])" Numeric + math /usr/lib/python2.3/timeit.py \ -s "from math import sin; from Numeric import arange; x=0.1"\ "for i in arange(9): x=sin(x)" /usr/lib/python2.3/timeit.py \ -s "from math import sin; from Numeric import zeros,arange; x=zeros(10, 'd'); x[0]=0.1"\ "for i in arange(9): x[i+1]=sin(x[i])" Regards, Steffen
participants (7)
-
Albert Strasheim
-
Arnd Baecker
-
Ed Schofield
-
Nils Wagner
-
Steffen Loeck
-
Ted Horst
-
Travis Oliphant