From numpy-svn at scipy.org Sun Mar 1 12:07:29 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 1 Mar 2009 11:07:29 -0600 (CST) Subject: [Numpy-svn] r6520 - in trunk/numpy/core: src tests Message-ID: <20090301170729.3B24FC7C125@scipy.org> Author: ptvirtan Date: 2009-03-01 11:07:06 -0600 (Sun, 01 Mar 2009) New Revision: 6520 Modified: trunk/numpy/core/src/umath_funcs.inc.src trunk/numpy/core/tests/test_umath.py Log: Fixed #1008: loss of precision issues in arcsin, arcsinh, arctan, arctanh The complex-valued arc* functions (that -> 0 for z -> 0) have loss of precision issues for small arguments. This patch addresses this by switching to a series expansion (in Horner form) in this regime. Tests included. Modified: trunk/numpy/core/src/umath_funcs.inc.src =================================================================== --- trunk/numpy/core/src/umath_funcs.inc.src 2009-02-27 22:27:14 UTC (rev 6519) +++ trunk/numpy/core/src/umath_funcs.inc.src 2009-03-01 17:07:06 UTC (rev 6520) @@ -96,6 +96,17 @@ #c=f,,l# */ +/* Perform the operation result := 1 + coef * x * result, + * with real coefficient `coef`. + */ +#define SERIES_HORNER_TERM at c@(result, x, coef) \ + do { \ + nc_prod at c@((result), (x), (result)); \ + (result)->real *= (coef); \ + (result)->imag *= (coef); \ + nc_sum at c@((result), &nc_1 at c@, (result)); \ + } while(0) + /* constants */ static c at typ@ nc_1 at c@ = {1., 0.}; static c at typ@ nc_half at c@ = {0.5, 0.}; @@ -319,15 +330,33 @@ * return nc_neg(nc_prodi(nc_log(nc_sum(nc_prod(nc_i,x), * nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))))); */ - c at typ@ a, *pa=&a; - nc_prod at c@(x, x, r); - nc_diff at c@(&nc_1 at c@, r, r); - nc_sqrt at c@(r, r); - nc_prodi at c@(x, pa); - nc_sum at c@(pa, r, r); - nc_log at c@(r, r); - nc_prodi at c@(r, r); - nc_neg at c@(r, r); + if (fabs(x->real) > 1e-3 || fabs(x->imag) > 1e-3) { + c at typ@ a, *pa=&a; + nc_prod at c@(x, x, r); + nc_diff at c@(&nc_1 at c@, r, r); + nc_sqrt at c@(r, r); + nc_prodi at c@(x, pa); + nc_sum at c@(pa, r, r); + nc_log at c@(r, r); + nc_prodi at c@(r, r); + nc_neg at c@(r, r); + } + else { + /* + * Small arguments: series expansion, to avoid loss of precision + * asin(x) = x [1 + (1/6) x^2 [1 + (9/20) x^2 [1 - ...]]] + * + * |x| < 1e-3 => |rel. error| < 1e-20 + */ + c at typ@ x2; + nc_prod at c@(x, x, &x2); + + *r = nc_1 at c@; + SERIES_HORNER_TERM at c@(r, &x2, 25./42); + SERIES_HORNER_TERM at c@(r, &x2, 9./20); + SERIES_HORNER_TERM at c@(r, &x2, 1./6); + nc_prod at c@(r, x, r); + } return; } @@ -338,11 +367,29 @@ /* * return nc_log(nc_sum(nc_sqrt(nc_sum(nc_1,nc_prod(x,x))),x)); */ - nc_prod at c@(x, x, r); - nc_sum at c@(&nc_1 at c@, r, r); - nc_sqrt at c@(r, r); - nc_sum at c@(r, x, r); - nc_log at c@(r, r); + if (fabs(x->real) > 1e-3 || fabs(x->imag) > 1e-3) { + nc_prod at c@(x, x, r); + nc_sum at c@(&nc_1 at c@, r, r); + nc_sqrt at c@(r, r); + nc_sum at c@(r, x, r); + nc_log at c@(r, r); + } + else { + /* + * Small arguments: series expansion, to avoid loss of precision + * asinh(x) = x [1 - (1/6) x^2 [1 - (9/20) x^2 [1 - ...]]] + * + * |x| < 1e-3 => |rel. error| < 1e-20 + */ + c at typ@ x2; + nc_prod at c@(x, x, &x2); + + *r = nc_1 at c@; + SERIES_HORNER_TERM at c@(r, &x2, -25./42); + SERIES_HORNER_TERM at c@(r, &x2, -9./20); + SERIES_HORNER_TERM at c@(r, &x2, -1./6); + nc_prod at c@(r, x, r); + } return; } @@ -352,12 +399,30 @@ /* * return nc_prod(nc_i2,nc_log(nc_quot(nc_sum(nc_i,x),nc_diff(nc_i,x)))); */ - c at typ@ a, *pa=&a; - nc_diff at c@(&nc_i at c@, x, pa); - nc_sum at c@(&nc_i at c@, x, r); - nc_quot at c@(r, pa, r); - nc_log at c@(r,r); - nc_prod at c@(&nc_i2 at c@, r, r); + if (fabs(x->real) > 1e-3 || fabs(x->imag) > 1e-3) { + c at typ@ a, *pa=&a; + nc_diff at c@(&nc_i at c@, x, pa); + nc_sum at c@(&nc_i at c@, x, r); + nc_quot at c@(r, pa, r); + nc_log at c@(r,r); + nc_prod at c@(&nc_i2 at c@, r, r); + } + else { + /* + * Small arguments: series expansion, to avoid loss of precision + * atan(x) = x [1 - (1/3) x^2 [1 - (3/5) x^2 [1 - ...]]] + * + * |x| < 1e-3 => |rel. error| < 1e-20 + */ + c at typ@ x2; + nc_prod at c@(x, x, &x2); + + *r = nc_1 at c@; + SERIES_HORNER_TERM at c@(r, &x2, -5./7); + SERIES_HORNER_TERM at c@(r, &x2, -3./5); + SERIES_HORNER_TERM at c@(r, &x2, -1./3); + nc_prod at c@(r, x, r); + } return; } @@ -367,12 +432,30 @@ /* * return nc_prod(nc_half,nc_log(nc_quot(nc_sum(nc_1,x),nc_diff(nc_1,x)))); */ - c at typ@ a, *pa=&a; - nc_diff at c@(&nc_1 at c@, x, r); - nc_sum at c@(&nc_1 at c@, x, pa); - nc_quot at c@(pa, r, r); - nc_log at c@(r, r); - nc_prod at c@(&nc_half at c@, r, r); + if (fabs(x->real) > 1e-3 || fabs(x->imag) > 1e-3) { + c at typ@ a, *pa=&a; + nc_diff at c@(&nc_1 at c@, x, r); + nc_sum at c@(&nc_1 at c@, x, pa); + nc_quot at c@(pa, r, r); + nc_log at c@(r, r); + nc_prod at c@(&nc_half at c@, r, r); + } + else { + /* + * Small arguments: series expansion, to avoid loss of precision + * atan(x) = x [1 + (1/3) x^2 [1 + (3/5) x^2 [1 - ...]]] + * + * |x| < 1e-3 => |rel. error| < 1e-20 + */ + c at typ@ x2; + nc_prod at c@(x, x, &x2); + + *r = nc_1 at c@; + SERIES_HORNER_TERM at c@(r, &x2, 5./7); + SERIES_HORNER_TERM at c@(r, &x2, 3./5); + SERIES_HORNER_TERM at c@(r, &x2, 1./3); + nc_prod at c@(r, x, r); + } return; } @@ -463,5 +546,7 @@ return; } +#undef SERIES_HORNER_TERM at c@ + /**end repeat**/ Modified: trunk/numpy/core/tests/test_umath.py =================================================================== --- trunk/numpy/core/tests/test_umath.py 2009-02-27 22:27:14 UTC (rev 6519) +++ trunk/numpy/core/tests/test_umath.py 2009-03-01 17:07:06 UTC (rev 6520) @@ -422,6 +422,81 @@ assert abs(a - b) < atol, "%s %s: %s; cmath: %s"%(fname,p,a,b) + def check_loss_of_precision(self, dtype): + """Check loss of precision in complex arc* functions""" + + # Check against known-good functions + + info = np.finfo(dtype) + real_dtype = dtype(0.).real.dtype + + eps = info.eps + + def check(x, rtol): + d = np.absolute(np.arcsinh(x)/np.arcsinh(x+0j).real - 1) + assert np.all(d < rtol), (x[np.argmax(d)], d.max()) + + d = np.absolute(np.arcsinh(x)/np.arcsin(1j*x).imag - 1) + assert np.all(d < rtol), (x[np.argmax(d)], d.max()) + + d = np.absolute(np.arctanh(x)/np.arctanh(x+0j).real - 1) + assert np.all(d < rtol), (x[np.argmax(d)], d.max()) + + d = np.absolute(np.arctanh(x)/np.arctan(1j*x).imag - 1) + assert np.all(d < rtol), (x[np.argmax(d)], d.max()) + + # The switchover was chosen as 1e-3; hence there can be up to + # ~eps/1e-3 of relative cancellation error before it + + x_series = np.logspace(np.log10(info.tiny/eps).real, -3, 200, + endpoint=False) + x_basic = np.logspace(dtype(-3.).real, -1e-8, 10) + + check(x_series, 2*eps) + check(x_basic, 2*eps/1e-3) + + # Check a few points + + z = np.array([1e-5*(1+1j)], dtype=dtype) + p = 9.999999999333333333e-6 + 1.000000000066666666e-5j + d = np.absolute(1-np.arctanh(z)/p) + assert np.all(d < 1e-15) + + p = 1.0000000000333333333e-5 + 9.999999999666666667e-6j + d = np.absolute(1-np.arcsinh(z)/p) + assert np.all(d < 1e-15) + + p = 9.999999999333333333e-6j + 1.000000000066666666e-5 + d = np.absolute(1-np.arctan(z)/p) + assert np.all(d < 1e-15) + + p = 1.0000000000333333333e-5j + 9.999999999666666667e-6 + d = np.absolute(1-np.arcsin(z)/p) + assert np.all(d < 1e-15) + + # Check continuity across switchover points + + def check(func, z0, d=1): + z0 = np.asarray(z0, dtype=dtype) + zp = z0 + abs(z0) * d * eps * 2 + zm = z0 - abs(z0) * d * eps * 2 + assert np.all(zp != zm), (zp, zm) + + # NB: the cancellation error at the switchover is at least eps + good = (abs(func(zp) - func(zm)) < 2*eps) + assert np.all(good), (func, z0[~good]) + + for func in (np.arcsinh,np.arcsinh,np.arcsin,np.arctanh,np.arctan): + pts = [rp+1j*ip for rp in (-1e-3,0,1e-3) for ip in(-1e-3,0,1e-3) + if rp != 0 or ip != 0] + check(func, pts, 1) + check(func, pts, 1j) + check(func, pts, 1+1j) + + def test_loss_of_precision(self): + for dtype in [np.complex64, np.complex_, np.longcomplex]: + yield self.check_loss_of_precision, dtype + class TestAttributes(TestCase): def test_attributes(self): add = ncu.add From numpy-svn at scipy.org Mon Mar 2 08:35:17 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 07:35:17 -0600 (CST) Subject: [Numpy-svn] r6521 - trunk/doc/swig Message-ID: <20090302133517.EBCB1C7C015@scipy.org> Author: cdavid Date: 2009-03-02 07:35:13 -0600 (Mon, 02 Mar 2009) New Revision: 6521 Modified: trunk/doc/swig/numpy.i Log: Update numpy.i to fix const char* return warnings issues with later versions of g++ (from Matthieu Brucher). Modified: trunk/doc/swig/numpy.i =================================================================== --- trunk/doc/swig/numpy.i 2009-03-01 17:07:06 UTC (rev 6520) +++ trunk/doc/swig/numpy.i 2009-03-02 13:35:13 UTC (rev 6521) @@ -97,7 +97,7 @@ { /* Given a PyObject, return a string describing its type. */ - char* pytype_string(PyObject* py_obj) { + const char* pytype_string(PyObject* py_obj) { if (py_obj == NULL ) return "C NULL value"; if (py_obj == Py_None ) return "Python None" ; if (PyCallable_Check(py_obj)) return "callable" ; @@ -116,8 +116,8 @@ /* Given a NumPy typecode, return a string describing the type. */ - char* typecode_string(int typecode) { - static char* type_names[25] = {"bool", "byte", "unsigned byte", + const char* typecode_string(int typecode) { + static const char* type_names[25] = {"bool", "byte", "unsigned byte", "short", "unsigned short", "int", "unsigned int", "long", "unsigned long", "long long", "unsigned long long", @@ -159,8 +159,8 @@ } else if is_array(input) { - char* desired_type = typecode_string(typecode); - char* actual_type = typecode_string(array_type(input)); + const char* desired_type = typecode_string(typecode); + const char* actual_type = typecode_string(array_type(input)); PyErr_Format(PyExc_TypeError, "Array of type '%s' required. Array of type '%s' given", desired_type, actual_type); @@ -168,8 +168,8 @@ } else { - char * desired_type = typecode_string(typecode); - char * actual_type = pytype_string(input); + const char * desired_type = typecode_string(typecode); + const char * actual_type = pytype_string(input); PyErr_Format(PyExc_TypeError, "Array of type '%s' required. A '%s' was given", desired_type, actual_type); From numpy-svn at scipy.org Mon Mar 2 09:17:50 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 08:17:50 -0600 (CST) Subject: [Numpy-svn] r6522 - trunk/numpy/linalg/tests Message-ID: <20090302141750.2FF58C7C015@scipy.org> Author: cdavid Date: 2009-03-02 08:17:43 -0600 (Mon, 02 Mar 2009) New Revision: 6522 Modified: trunk/numpy/linalg/tests/test_linalg.py Log: TEST: add tests for norm from #763. Modified: trunk/numpy/linalg/tests/test_linalg.py =================================================================== --- trunk/numpy/linalg/tests/test_linalg.py 2009-03-02 13:35:13 UTC (rev 6521) +++ trunk/numpy/linalg/tests/test_linalg.py 2009-03-02 14:17:43 UTC (rev 6522) @@ -5,7 +5,7 @@ from numpy import array, single, double, csingle, cdouble, dot, identity from numpy import multiply, atleast_2d, inf, asarray, matrix from numpy import linalg -from numpy.linalg import matrix_power +from numpy.linalg import matrix_power, norm def ifthen(a, b): return not a or b @@ -257,5 +257,45 @@ evalues, evectors = linalg.eig(a) assert_almost_equal(ev, evalues) +class TestNorm(TestCase): + def check_empty(self): + assert_equal(norm([]), 0.0) + assert_equal(norm(array([], dtype = double)), 0.0) + assert_equal(norm(atleast_2d(array([], dtype = double))), 0.0) + + def test_vector(self): + a = [1.0,2.0,3.0,4.0] + b = [-1.0,-2.0,-3.0,-4.0] + c = [-1.0, 2.0,-3.0, 4.0] + for v in (a,array(a),b,array(b),c,array(c)): + assert_almost_equal(norm(v), 30**0.5) + assert_almost_equal(norm(v,inf), 4.0) + assert_almost_equal(norm(v,-inf), 1.0) + assert_almost_equal(norm(v,1), 10.0) + assert_almost_equal(norm(v,-1), 12.0/25) + assert_almost_equal(norm(v,2), 30**0.5) + assert_almost_equal(norm(v,-2), (205./144)**-0.5) + + @dec.knownfailureif(True, "#786: FIXME") + def test_vector_badarg(self): + """Regression for #786: Froebenius norm for vectors raises + TypeError.""" + self.assertRaises(ValueError, norm, array([1., 2., 3.]), 'fro') + + def test_matrix(self): + A = matrix([[1.,3.],[5.,7.]], dtype=single) + A = matrix([[1.,3.],[5.,7.]], dtype=single) + assert_almost_equal(norm(A), 84**0.5) + assert_almost_equal(norm(A,'fro'), 84**0.5) + assert_almost_equal(norm(A,inf), 12.0) + assert_almost_equal(norm(A,-inf), 4.0) + assert_almost_equal(norm(A,1), 10.0) + assert_almost_equal(norm(A,-1), 6.0) + assert_almost_equal(norm(A,2), 9.12310563) + assert_almost_equal(norm(A,-2), 0.87689437) + + self.assertRaises(ValueError, norm, A, 'nofro') + self.assertRaises(ValueError, norm, A, -3) + if __name__ == "__main__": run_module_suite() From numpy-svn at scipy.org Mon Mar 2 09:18:05 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 08:18:05 -0600 (CST) Subject: [Numpy-svn] r6523 - trunk/numpy/linalg/tests Message-ID: <20090302141805.7C5B7C7C015@scipy.org> Author: cdavid Date: 2009-03-02 08:18:01 -0600 (Mon, 02 Mar 2009) New Revision: 6523 Modified: trunk/numpy/linalg/tests/test_linalg.py Log: rename check_empty method to test_, so that is is picked up by nose. Modified: trunk/numpy/linalg/tests/test_linalg.py =================================================================== --- trunk/numpy/linalg/tests/test_linalg.py 2009-03-02 14:17:43 UTC (rev 6522) +++ trunk/numpy/linalg/tests/test_linalg.py 2009-03-02 14:18:01 UTC (rev 6523) @@ -258,7 +258,7 @@ assert_almost_equal(ev, evalues) class TestNorm(TestCase): - def check_empty(self): + def test_empty(self): assert_equal(norm([]), 0.0) assert_equal(norm(array([], dtype = double)), 0.0) assert_equal(norm(atleast_2d(array([], dtype = double))), 0.0) From numpy-svn at scipy.org Mon Mar 2 09:18:19 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 08:18:19 -0600 (CST) Subject: [Numpy-svn] r6524 - trunk/numpy/linalg/tests Message-ID: <20090302141819.B1591C7C015@scipy.org> Author: cdavid Date: 2009-03-02 08:18:15 -0600 (Mon, 02 Mar 2009) New Revision: 6524 Modified: trunk/numpy/linalg/tests/test_linalg.py Log: Abstract away dtype for norm test. Modified: trunk/numpy/linalg/tests/test_linalg.py =================================================================== --- trunk/numpy/linalg/tests/test_linalg.py 2009-03-02 14:18:01 UTC (rev 6523) +++ trunk/numpy/linalg/tests/test_linalg.py 2009-03-02 14:18:15 UTC (rev 6524) @@ -1,6 +1,7 @@ """ Test functions for linalg module """ +import numpy as np from numpy.testing import * from numpy import array, single, double, csingle, cdouble, dot, identity from numpy import multiply, atleast_2d, inf, asarray, matrix @@ -257,17 +258,19 @@ evalues, evectors = linalg.eig(a) assert_almost_equal(ev, evalues) -class TestNorm(TestCase): +class _TestNorm(TestCase): + dt = None def test_empty(self): assert_equal(norm([]), 0.0) - assert_equal(norm(array([], dtype = double)), 0.0) - assert_equal(norm(atleast_2d(array([], dtype = double))), 0.0) + assert_equal(norm(array([], dtype=self.dt)), 0.0) + assert_equal(norm(atleast_2d(array([], dtype=self.dt))), 0.0) def test_vector(self): a = [1.0,2.0,3.0,4.0] b = [-1.0,-2.0,-3.0,-4.0] c = [-1.0, 2.0,-3.0, 4.0] - for v in (a,array(a),b,array(b),c,array(c)): + for v in (a,array(a, dtype=self.dt),b,array(b, dtype=self.dt),c,array(c, + dtype=self.dt)): assert_almost_equal(norm(v), 30**0.5) assert_almost_equal(norm(v,inf), 4.0) assert_almost_equal(norm(v,-inf), 1.0) @@ -283,19 +286,22 @@ self.assertRaises(ValueError, norm, array([1., 2., 3.]), 'fro') def test_matrix(self): - A = matrix([[1.,3.],[5.,7.]], dtype=single) - A = matrix([[1.,3.],[5.,7.]], dtype=single) + A = matrix([[1.,3.],[5.,7.]], dtype=self.dt) + A = matrix([[1.,3.],[5.,7.]], dtype=self.dt) assert_almost_equal(norm(A), 84**0.5) assert_almost_equal(norm(A,'fro'), 84**0.5) assert_almost_equal(norm(A,inf), 12.0) assert_almost_equal(norm(A,-inf), 4.0) assert_almost_equal(norm(A,1), 10.0) assert_almost_equal(norm(A,-1), 6.0) - assert_almost_equal(norm(A,2), 9.12310563) - assert_almost_equal(norm(A,-2), 0.87689437) + assert_almost_equal(norm(A,2), 9.1231056256176615) + assert_almost_equal(norm(A,-2), 0.87689437438234041) self.assertRaises(ValueError, norm, A, 'nofro') self.assertRaises(ValueError, norm, A, -3) +class TestNormDouble(_TestNorm): + dt = np.double + if __name__ == "__main__": run_module_suite() From numpy-svn at scipy.org Mon Mar 2 09:18:33 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 08:18:33 -0600 (CST) Subject: [Numpy-svn] r6525 - trunk/numpy/linalg/tests Message-ID: <20090302141833.0F6D1C7C015@scipy.org> Author: cdavid Date: 2009-03-02 08:18:29 -0600 (Mon, 02 Mar 2009) New Revision: 6525 Modified: trunk/numpy/linalg/tests/test_linalg.py Log: Fix norm tests for single prec. Modified: trunk/numpy/linalg/tests/test_linalg.py =================================================================== --- trunk/numpy/linalg/tests/test_linalg.py 2009-03-02 14:18:15 UTC (rev 6524) +++ trunk/numpy/linalg/tests/test_linalg.py 2009-03-02 14:18:29 UTC (rev 6525) @@ -260,6 +260,7 @@ class _TestNorm(TestCase): dt = None + dec = None def test_empty(self): assert_equal(norm([]), 0.0) assert_equal(norm(array([], dtype=self.dt)), 0.0) @@ -269,17 +270,27 @@ a = [1.0,2.0,3.0,4.0] b = [-1.0,-2.0,-3.0,-4.0] c = [-1.0, 2.0,-3.0, 4.0] - for v in (a,array(a, dtype=self.dt),b,array(b, dtype=self.dt),c,array(c, - dtype=self.dt)): - assert_almost_equal(norm(v), 30**0.5) - assert_almost_equal(norm(v,inf), 4.0) - assert_almost_equal(norm(v,-inf), 1.0) - assert_almost_equal(norm(v,1), 10.0) - assert_almost_equal(norm(v,-1), 12.0/25) - assert_almost_equal(norm(v,2), 30**0.5) - assert_almost_equal(norm(v,-2), (205./144)**-0.5) - @dec.knownfailureif(True, "#786: FIXME") + def _test(v): + np.testing.assert_almost_equal(norm(v), 30**0.5, decimal=self.dec) + np.testing.assert_almost_equal(norm(v,inf), 4.0, decimal=self.dec) + np.testing.assert_almost_equal(norm(v,-inf), 1.0, decimal=self.dec) + np.testing.assert_almost_equal(norm(v,1), 10.0, decimal=self.dec) + np.testing.assert_almost_equal(norm(v,-1), 12.0/25, + decimal=self.dec) + np.testing.assert_almost_equal(norm(v,2), 30**0.5, + decimal=self.dec) + np.testing.assert_almost_equal(norm(v,-2), ((205./144)**-0.5), + decimal=self.dec) + + for v in (a, b, c,): + _test(v) + + for v in (array(a, dtype=self.dt), array(b, dtype=self.dt), + array(c, dtype=self.dt)): + _test(v) + + @np.testing.dec.knownfailureif(True, "#786: FIXME") def test_vector_badarg(self): """Regression for #786: Froebenius norm for vectors raises TypeError.""" @@ -302,6 +313,11 @@ class TestNormDouble(_TestNorm): dt = np.double + dec= 12 +class TestNormSingle(_TestNorm): + dt = np.float32 + dec = 6 + if __name__ == "__main__": run_module_suite() From numpy-svn at scipy.org Mon Mar 2 09:26:56 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 08:26:56 -0600 (CST) Subject: [Numpy-svn] r6526 - in trunk/numpy/linalg: . tests Message-ID: <20090302142656.73731C7C015@scipy.org> Author: cdavid Date: 2009-03-02 08:26:50 -0600 (Mon, 02 Mar 2009) New Revision: 6526 Modified: trunk/numpy/linalg/linalg.py trunk/numpy/linalg/tests/test_linalg.py trunk/numpy/linalg/tests/test_regression.py Log: BUG: fix #786, bad exception for wrong order for linalg.norm. Modified: trunk/numpy/linalg/linalg.py =================================================================== --- trunk/numpy/linalg/linalg.py 2009-03-02 14:18:29 UTC (rev 6525) +++ trunk/numpy/linalg/linalg.py 2009-03-02 14:26:50 UTC (rev 6526) @@ -1378,6 +1378,10 @@ elif ord == 2: return sqrt(((x.conj()*x).real).sum()) # special case for speedup else: + try: + ord + 1 + except TypeError: + raise ValueError, "Invalid norm order for vectors." return ((abs(x)**ord).sum())**(1.0/ord) elif nd == 2: if ord == 2: Modified: trunk/numpy/linalg/tests/test_linalg.py =================================================================== --- trunk/numpy/linalg/tests/test_linalg.py 2009-03-02 14:18:29 UTC (rev 6525) +++ trunk/numpy/linalg/tests/test_linalg.py 2009-03-02 14:26:50 UTC (rev 6526) @@ -290,12 +290,6 @@ array(c, dtype=self.dt)): _test(v) - @np.testing.dec.knownfailureif(True, "#786: FIXME") - def test_vector_badarg(self): - """Regression for #786: Froebenius norm for vectors raises - TypeError.""" - self.assertRaises(ValueError, norm, array([1., 2., 3.]), 'fro') - def test_matrix(self): A = matrix([[1.,3.],[5.,7.]], dtype=self.dt) A = matrix([[1.,3.],[5.,7.]], dtype=self.dt) Modified: trunk/numpy/linalg/tests/test_regression.py =================================================================== --- trunk/numpy/linalg/tests/test_regression.py 2009-03-02 14:18:29 UTC (rev 6525) +++ trunk/numpy/linalg/tests/test_regression.py 2009-03-02 14:26:50 UTC (rev 6526) @@ -52,6 +52,11 @@ assert_array_almost_equal(b, np.zeros((2, 2))) + def test_norm_vector_badarg(self): + """Regression for #786: Froebenius norm for vectors raises + TypeError.""" + self.assertRaises(ValueError, linalg.norm, array([1., 2., 3.]), 'fro') + if __name__ == '__main__': run_module_suite() From numpy-svn at scipy.org Mon Mar 2 09:46:24 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 08:46:24 -0600 (CST) Subject: [Numpy-svn] r6527 - in trunk/numpy/core: . tests Message-ID: <20090302144624.E9CDDC7C015@scipy.org> Author: cdavid Date: 2009-03-02 08:46:20 -0600 (Mon, 02 Mar 2009) New Revision: 6527 Modified: trunk/numpy/core/defmatrix.py trunk/numpy/core/tests/test_defmatrix.py Log: Add in-place power raising for matrices (#787). Modified: trunk/numpy/core/defmatrix.py =================================================================== --- trunk/numpy/core/defmatrix.py 2009-03-02 14:26:50 UTC (rev 6526) +++ trunk/numpy/core/defmatrix.py 2009-03-02 14:46:20 UTC (rev 6527) @@ -302,6 +302,10 @@ def __pow__(self, other): return matrix_power(self, other) + def __ipow__(self, other): + self[:] = self ** other + return self + def __rpow__(self, other): return NotImplemented Modified: trunk/numpy/core/tests/test_defmatrix.py =================================================================== --- trunk/numpy/core/tests/test_defmatrix.py 2009-03-02 14:26:50 UTC (rev 6526) +++ trunk/numpy/core/tests/test_defmatrix.py 2009-03-02 14:46:20 UTC (rev 6527) @@ -207,6 +207,19 @@ mA2 *= 3 assert allclose(mA2.A, 3*A) + def test_pow(self): + """Test raising a matrix to an integer power works as expected.""" + m = matrix("1. 2.; 3. 4.") + m2 = m.copy() + m2 **= 2 + mi = m.copy() + mi **= -1 + m4 = m2.copy() + m4 **= 2 + assert_array_almost_equal(m2, m**2) + assert_array_almost_equal(m4, np.dot(m2, m2)) + assert_array_almost_equal(np.dot(mi, m), np.eye(2)) + def test_notimplemented(self): '''Check that 'not implemented' operations produce a failure.''' A = matrix([[1., 2.], From numpy-svn at scipy.org Mon Mar 2 10:01:31 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 09:01:31 -0600 (CST) Subject: [Numpy-svn] r6528 - trunk/numpy/core/src Message-ID: <20090302150131.E104DC7C015@scipy.org> Author: cdavid Date: 2009-03-02 09:01:21 -0600 (Mon, 02 Mar 2009) New Revision: 6528 Modified: trunk/numpy/core/src/multiarraymodule.c Log: Make sure dest array is aligned for putmask. Modified: trunk/numpy/core/src/multiarraymodule.c =================================================================== --- trunk/numpy/core/src/multiarraymodule.c 2009-03-02 14:46:20 UTC (rev 6527) +++ trunk/numpy/core/src/multiarraymodule.c 2009-03-02 15:01:21 UTC (rev 6528) @@ -4616,7 +4616,7 @@ "be an array"); return NULL; } - if (!PyArray_ISCONTIGUOUS(self)) { + if (!PyArray_ISCONTIGUOUS(self) || !(self->flags & ALIGNED)) { PyArrayObject *obj; int flags = NPY_CARRAY | NPY_UPDATEIFCOPY; From numpy-svn at scipy.org Mon Mar 2 10:08:32 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 09:08:32 -0600 (CST) Subject: [Numpy-svn] r6529 - in trunk/numpy/core: . tests Message-ID: <20090302150832.48D58C7C015@scipy.org> Author: cdavid Date: 2009-03-02 09:08:27 -0600 (Mon, 02 Mar 2009) New Revision: 6529 Modified: trunk/numpy/core/defchararray.py trunk/numpy/core/tests/test_defchararray.py Log: Allow c in dtype for charray (#917). Modified: trunk/numpy/core/defchararray.py =================================================================== --- trunk/numpy/core/defchararray.py 2009-03-02 15:01:21 UTC (rev 6528) +++ trunk/numpy/core/defchararray.py 2009-03-02 15:08:27 UTC (rev 6529) @@ -53,7 +53,7 @@ def __array_finalize__(self, obj): # The b is a special case because it is used for reconstructing. - if not _globalvar and self.dtype.char not in 'SUb': + if not _globalvar and self.dtype.char not in 'SUbc': raise ValueError, "Can only create a chararray from string data." def __getitem__(self, obj): Modified: trunk/numpy/core/tests/test_defchararray.py =================================================================== --- trunk/numpy/core/tests/test_defchararray.py 2009-03-02 15:01:21 UTC (rev 6528) +++ trunk/numpy/core/tests/test_defchararray.py 2009-03-02 15:08:27 UTC (rev 6529) @@ -23,6 +23,15 @@ assert all(self.A == self.B) +class TestChar(TestCase): + def setUp(self): + self.A = np.array('abc1', dtype='c').view(np.chararray) + + def test_it(self): + assert self.A.shape == (4,) + assert self.A.upper()[:2].tostring() == 'AB' + + class TestOperations(TestCase): def setUp(self): self.A = np.array([['abc', '123'], From numpy-svn at scipy.org Mon Mar 2 11:12:49 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 10:12:49 -0600 (CST) Subject: [Numpy-svn] r6530 - trunk/numpy/core/blasdot Message-ID: <20090302161249.0979FC7C015@scipy.org> Author: cdavid Date: 2009-03-02 10:12:45 -0600 (Mon, 02 Mar 2009) New Revision: 6530 Modified: trunk/numpy/core/blasdot/_dotblas.c Log: Do not use old noprefix header in dotblas (#945). Modified: trunk/numpy/core/blasdot/_dotblas.c =================================================================== --- trunk/numpy/core/blasdot/_dotblas.c 2009-03-02 15:08:27 UTC (rev 6529) +++ trunk/numpy/core/blasdot/_dotblas.c 2009-03-02 16:12:45 UTC (rev 6530) @@ -2,7 +2,7 @@ "This module provides a BLAS optimized\nmatrix multiply, inner product and dot for numpy arrays"; #include "Python.h" -#include "numpy/noprefix.h" +#include "numpy/ndarrayobject.h" #ifndef CBLAS_HEADER #define CBLAS_HEADER "cblas.h" #endif @@ -13,8 +13,8 @@ static PyArray_DotFunc *oldFunctions[PyArray_NTYPES]; static void -FLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, - intp n, void *tmp) +FLOAT_dot(void *a, npy_intp stridea, void *b, npy_intp strideb, void *res, + npy_intp n, void *tmp) { register int na = stridea / sizeof(float); register int nb = strideb / sizeof(float); @@ -29,8 +29,8 @@ } static void -DOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, - intp n, void *tmp) +DOUBLE_dot(void *a, npy_intp stridea, void *b, npy_intp strideb, void *res, + npy_intp n, void *tmp) { register int na = stridea / sizeof(double); register int nb = strideb / sizeof(double); @@ -44,15 +44,15 @@ } static void -CFLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, - intp n, void *tmp) +CFLOAT_dot(void *a, npy_intp stridea, void *b, npy_intp strideb, void *res, + npy_intp n, void *tmp) { - register int na = stridea / sizeof(cfloat); - register int nb = strideb / sizeof(cfloat); + register int na = stridea / sizeof(npy_cfloat); + register int nb = strideb / sizeof(npy_cfloat); - if ((sizeof(cfloat) * na == stridea) && - (sizeof(cfloat) * nb == strideb) && + if ((sizeof(npy_cfloat) * na == stridea) && + (sizeof(npy_cfloat) * nb == strideb) && (na >= 0) && (nb >= 0)) cblas_cdotu_sub((int)n, (float *)a, na, (float *)b, nb, (float *)res); else @@ -60,14 +60,14 @@ } static void -CDOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, - intp n, void *tmp) +CDOUBLE_dot(void *a, npy_intp stridea, void *b, npy_intp strideb, void *res, + npy_intp n, void *tmp) { - register int na = stridea / sizeof(cdouble); - register int nb = strideb / sizeof(cdouble); + register int na = stridea / sizeof(npy_cdouble); + register int nb = strideb / sizeof(npy_cdouble); - if ((sizeof(cdouble) * na == stridea) && - (sizeof(cdouble) * nb == strideb) && + if ((sizeof(npy_cdouble) * na == stridea) && + (sizeof(npy_cdouble) * nb == strideb) && (na >= 0) && (nb >= 0)) cblas_zdotu_sub((int)n, (double *)a, na, (double *)b, nb, (double *)res); else @@ -75,7 +75,7 @@ } -static Bool altered=FALSE; +static npy_bool altered=NPY_FALSE; static char doc_alterdot[] = "alterdot() changes all dot functions to use blas."; @@ -105,7 +105,7 @@ oldFunctions[PyArray_CDOUBLE] = descr->f->dotfunc; descr->f->dotfunc = (PyArray_DotFunc *)CDOUBLE_dot; - altered = TRUE; + altered = NPY_TRUE; } Py_INCREF(Py_None); @@ -142,7 +142,7 @@ oldFunctions[PyArray_CDOUBLE] = NULL; Py_XDECREF(descr); - altered = FALSE; + altered = NPY_FALSE; } Py_INCREF(Py_None); @@ -184,9 +184,9 @@ { register int itemsize = PyArray_ITEMSIZE(ap); register int i, N=PyArray_NDIM(ap); - register intp *strides = PyArray_STRIDES(ap); + register npy_intp *strides = PyArray_STRIDES(ap); - if (((intp)(ap->data) % itemsize) != 0) + if (((npy_intp)(ap->data) % itemsize) != 0) return 1; for (i=0; ind == 0 || ap2->nd == 0) { - intp *thisdims; + npy_intp *thisdims; if (ap1->nd == 0) { nd = ap2->nd; thisdims = ap2->dimensions; @@ -460,17 +460,17 @@ } else if (typenum == PyArray_CDOUBLE) { if (l == 1) { - cdouble *ptr1, *ptr2, *res; + npy_cdouble *ptr1, *ptr2, *res; - ptr1 = (cdouble *)ap2->data; - ptr2 = (cdouble *)ap1->data; - res = (cdouble *)ret->data; + ptr1 = (npy_cdouble *)ap2->data; + ptr2 = (npy_cdouble *)ap1->data; + res = (npy_cdouble *)ret->data; res->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag; res->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real; } else if (ap1shape != _matrix) { cblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data, - ap1stride/sizeof(cdouble), (double *)ret->data, 1); + ap1stride/sizeof(npy_cdouble), (double *)ret->data, 1); } else { int maxind, oind, i, a1s, rets; @@ -483,8 +483,8 @@ rptr = ret->data; l = ap1->dimensions[maxind]; pval = (double *)ap2->data; - a1s = ap1->strides[maxind] / sizeof(cdouble); - rets = ret->strides[maxind] / sizeof(cdouble); + a1s = ap1->strides[maxind] / sizeof(npy_cdouble); + rets = ret->strides[maxind] / sizeof(npy_cdouble); for (i = 0; i < ap1->dimensions[oind]; i++) { cblas_zaxpy(l, pval, (double *)ptr, a1s, (double *)rptr, rets); @@ -525,17 +525,17 @@ } else if (typenum == PyArray_CFLOAT) { if (l == 1) { - cfloat *ptr1, *ptr2, *res; + npy_cfloat *ptr1, *ptr2, *res; - ptr1 = (cfloat *)ap2->data; - ptr2 = (cfloat *)ap1->data; - res = (cfloat *)ret->data; + ptr1 = (npy_cfloat *)ap2->data; + ptr2 = (npy_cfloat *)ap1->data; + res = (npy_cfloat *)ret->data; res->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag; res->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real; } else if (ap1shape != _matrix) { cblas_caxpy(l, (float *)ap2->data, (float *)ap1->data, - ap1stride/sizeof(cfloat), (float *)ret->data, 1); + ap1stride/sizeof(npy_cfloat), (float *)ret->data, 1); } else { int maxind, oind, i, a1s, rets; @@ -548,8 +548,8 @@ rptr = ret->data; l = ap1->dimensions[maxind]; pval = (float *)ap2->data; - a1s = ap1->strides[maxind] / sizeof(cfloat); - rets = ret->strides[maxind] / sizeof(cfloat); + a1s = ap1->strides[maxind] / sizeof(npy_cfloat); + rets = ret->strides[maxind] / sizeof(npy_cfloat); for (i = 0; i < ap1->dimensions[oind]; i++) { cblas_caxpy(l, pval, (float *)ptr, a1s, (float *)rptr, rets); @@ -804,7 +804,7 @@ PyArrayObject *ap1, *ap2, *ret; int j, l, lda, ldb, ldc; int typenum, nd; - intp dimensions[MAX_DIMS]; + npy_intp dimensions[NPY_MAXDIMS]; static const float oneF[2] = {1.0, 0.0}; static const float zeroF[2] = {0.0, 0.0}; static const double oneD[2] = {1.0, 0.0}; @@ -1051,7 +1051,7 @@ PyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL; int l; int typenum; - intp dimensions[MAX_DIMS]; + npy_intp dimensions[NPY_MAXDIMS]; PyArray_Descr *type; if (!PyArg_ParseTuple(args, "OO", &op1, &op2)) return NULL; From numpy-svn at scipy.org Mon Mar 2 14:27:38 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 13:27:38 -0600 (CST) Subject: [Numpy-svn] r6531 - trunk/doc/release Message-ID: <20090302192738.405EEC7C0CC@scipy.org> Author: cdavid Date: 2009-03-02 13:27:02 -0600 (Mon, 02 Mar 2009) New Revision: 6531 Modified: trunk/doc/release/1.3.0-notes.rst Log: Mention nan handling in max and co for 1.3.0. in the releases notes. Modified: trunk/doc/release/1.3.0-notes.rst =================================================================== --- trunk/doc/release/1.3.0-notes.rst 2009-03-02 16:12:45 UTC (rev 6530) +++ trunk/doc/release/1.3.0-notes.rst 2009-03-02 19:27:02 UTC (rev 6531) @@ -30,6 +30,11 @@ The previous behavior is still accessible using `new=False`, but is scheduled to be deprecated in the next release (1.3). +Nan handling in max/min/sort +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +TODO + Masked arrays ~~~~~~~~~~~~~ From numpy-svn at scipy.org Mon Mar 2 14:28:05 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 13:28:05 -0600 (CST) Subject: [Numpy-svn] r6532 - trunk/numpy/core/include/numpy Message-ID: <20090302192805.7F1F7C7C0CC@scipy.org> Author: cdavid Date: 2009-03-02 13:27:55 -0600 (Mon, 02 Mar 2009) New Revision: 6532 Modified: trunk/numpy/core/include/numpy/npy_math.h Log: Fix wrong declaration for signbit imp. Modified: trunk/numpy/core/include/numpy/npy_math.h =================================================================== --- trunk/numpy/core/include/numpy/npy_math.h 2009-03-02 19:27:02 UTC (rev 6531) +++ trunk/numpy/core/include/numpy/npy_math.h 2009-03-02 19:27:55 UTC (rev 6532) @@ -104,7 +104,7 @@ #ifndef NPY_HAVE_DECL_SIGNBIT int _npy_signbit_f(float x); - int _npy_signbit(double x); + int _npy_signbit_d(double x); int _npy_signbit_ld(npy_longdouble x); #define npy_signbit(x) \ (sizeof (x) == sizeof (long double) ? _npy_signbit_ld (x) \ From numpy-svn at scipy.org Mon Mar 2 14:28:25 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 13:28:25 -0600 (CST) Subject: [Numpy-svn] r6533 - trunk/numpy/core/src Message-ID: <20090302192825.C0FA7C7C0F9@scipy.org> Author: cdavid Date: 2009-03-02 13:28:17 -0600 (Mon, 02 Mar 2009) New Revision: 6533 Modified: trunk/numpy/core/src/umath_loops.inc.src Log: Some missing spots when using npymath lib instead of raw math C libm in umath. Modified: trunk/numpy/core/src/umath_loops.inc.src =================================================================== --- trunk/numpy/core/src/umath_loops.inc.src 2009-03-02 19:27:55 UTC (rev 6532) +++ trunk/numpy/core/src/umath_loops.inc.src 2009-03-02 19:28:17 UTC (rev 6533) @@ -910,7 +910,7 @@ BINARY_LOOP { const @type@ in1 = *(@type@ *)ip1; const @type@ in2 = *(@type@ *)ip2; - *((@type@ *)op1) = floor at c@(in1/in2); + *((@type@ *)op1) = npy_floor at c@(in1/in2); } } @@ -920,7 +920,7 @@ BINARY_LOOP { const @type@ in1 = *(@type@ *)ip1; const @type@ in2 = *(@type@ *)ip2; - const @type@ res = fmod at c@(in1,in2); + const @type@ res = npy_fmod at c@(in1,in2); if (res && ((in2 < 0) != (res < 0))) { *((@type@ *)op1) = res + in2; } @@ -1000,7 +1000,7 @@ { UNARY_LOOP_TWO_OUT { const @type@ in1 = *(@type@ *)ip1; - *((@type@ *)op1) = modf at c@(in1, (@type@ *)op2); + *((@type@ *)op1) = npy_modf at c@(in1, (@type@ *)op2); } } @@ -1107,7 +1107,7 @@ const @type@ in2r = ((@type@ *)ip2)[0]; const @type@ in2i = ((@type@ *)ip2)[1]; @type@ d = in2r*in2r + in2i*in2i; - ((@type@ *)op1)[0] = floor at c@((in1r*in2r + in1i*in2i)/d); + ((@type@ *)op1)[0] = npy_floor at c@((in1r*in2r + in1i*in2i)/d); ((@type@ *)op1)[1] = 0; } } @@ -1204,7 +1204,7 @@ UNARY_LOOP { const @type@ in1r = ((@type@ *)ip1)[0]; const @type@ in1i = ((@type@ *)ip1)[1]; - if (fabs at c@(in1i) <= fabs at c@(in1r)) { + if (npy_fabs at c@(in1i) <= npy_fabs at c@(in1r)) { const @type@ r = in1i/in1r; const @type@ d = in1r + in1i*r; ((@type@ *)op1)[0] = 1/d; @@ -1243,7 +1243,7 @@ UNARY_LOOP { const @type@ in1r = ((@type@ *)ip1)[0]; const @type@ in1i = ((@type@ *)ip1)[1]; - *((@type@ *)op1) = sqrt at c@(in1r*in1r + in1i*in1i); + *((@type@ *)op1) = npy_sqrt at c@(in1r*in1r + in1i*in1i); } } From numpy-svn at scipy.org Mon Mar 2 15:05:48 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 14:05:48 -0600 (CST) Subject: [Numpy-svn] r6534 - in trunk/numpy/lib: . tests Message-ID: <20090302200548.D1D0FC7C05E@scipy.org> Author: stefan Date: 2009-03-02 14:05:32 -0600 (Mon, 02 Mar 2009) New Revision: 6534 Modified: trunk/numpy/lib/io.py trunk/numpy/lib/tests/test_io.py Log: Correctly handle gzip filenames in loadtxt. Modified: trunk/numpy/lib/io.py =================================================================== --- trunk/numpy/lib/io.py 2009-03-02 19:28:17 UTC (rev 6533) +++ trunk/numpy/lib/io.py 2009-03-02 20:05:32 UTC (rev 6534) @@ -48,6 +48,9 @@ def tell(self): return self.offset + if isinstance(f, str): + f = gzip.GzipFile(f) + f.seek = new.instancemethod(seek, f) f.tell = new.instancemethod(tell, f) Modified: trunk/numpy/lib/tests/test_io.py =================================================================== --- trunk/numpy/lib/tests/test_io.py 2009-03-02 19:28:17 UTC (rev 6533) +++ trunk/numpy/lib/tests/test_io.py 2009-03-02 20:05:32 UTC (rev 6534) @@ -3,6 +3,7 @@ from numpy.ma.testutils import * import StringIO +import gzip from tempfile import NamedTemporaryFile import sys, time @@ -821,6 +822,13 @@ f = gzip.GzipFile(fileobj=s, mode="r") assert_array_equal(np.load(f), a) +def test_gzip_loadtxt(): + f = NamedTemporaryFile(suffix='.gz') + g = gzip.GzipFile(fileobj=f) + g.write('1 2 3\n') + g.close() + f.seek(0) + assert_array_equal(np.loadtxt(f.name), [1, 2, 3]) if __name__ == "__main__": run_module_suite() From numpy-svn at scipy.org Mon Mar 2 16:12:02 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 15:12:02 -0600 (CST) Subject: [Numpy-svn] r6535 - in trunk/numpy: distutils distutils/command f2py lib linalg/lapack_lite Message-ID: <20090302211202.3C69AC7C129@scipy.org> Author: stefan Date: 2009-03-02 15:11:31 -0600 (Mon, 02 Mar 2009) New Revision: 6535 Modified: trunk/numpy/distutils/command/build_src.py trunk/numpy/distutils/misc_util.py trunk/numpy/f2py/crackfortran.py trunk/numpy/lib/function_base.py trunk/numpy/linalg/lapack_lite/make_lite.py Log: Python 3000 fixes for 2to3 [patch by James Watson]. Modified: trunk/numpy/distutils/command/build_src.py =================================================================== --- trunk/numpy/distutils/command/build_src.py 2009-03-02 20:05:32 UTC (rev 6534) +++ trunk/numpy/distutils/command/build_src.py 2009-03-02 21:11:31 UTC (rev 6535) @@ -465,7 +465,8 @@ if not (f2py_sources or f_sources): return new_sources - map(self.mkpath, target_dirs) + for d in target_dirs: + self.mkpath(d) f2py_options = extension.f2py_options + self.f2py_opts @@ -632,7 +633,9 @@ if skip_swig: return new_sources + py_files - map(self.mkpath, target_dirs) + for d in target_dirs: + self.mkpath(d) + swig = self.swig or self.find_swig() swig_cmd = [swig, "-python"] if is_cpp: Modified: trunk/numpy/distutils/misc_util.py =================================================================== --- trunk/numpy/distutils/misc_util.py 2009-03-02 20:05:32 UTC (rev 6534) +++ trunk/numpy/distutils/misc_util.py 2009-03-02 21:11:31 UTC (rev 6535) @@ -204,7 +204,7 @@ new_paths.extend(_fix_paths(n,local_path,include_non_existing)) else: new_paths.append(n) - return map(minrelpath,new_paths) + return [minrelpath(p) for p in new_paths] def gpaths(paths, local_path='', include_non_existing=True): """Apply glob to paths and prepend local_path if needed. @@ -954,7 +954,8 @@ for p,files in self.data_files: if p not in data_dict: data_dict[p] = set() - map(data_dict[p].add,files) + for f in files: + data_dict[p].add(f) self.data_files[:] = [(p,list(files)) for p,files in data_dict.items()] def add_data_files(self,*files): @@ -980,7 +981,8 @@ """ if len(files)>1: - map(self.add_data_files, files) + for f in files: + self.add_data_files(f) return assert len(files)==1 if is_sequence(files[0]): Modified: trunk/numpy/f2py/crackfortran.py =================================================================== --- trunk/numpy/f2py/crackfortran.py 2009-03-02 20:05:32 UTC (rev 6534) +++ trunk/numpy/f2py/crackfortran.py 2009-03-02 21:11:31 UTC (rev 6535) @@ -341,7 +341,9 @@ elif strictf77: if len(l)>72: l=l[:72] if not (l[0] in spacedigits): - raise 'readfortrancode: Found non-(space,digit) char in the first column.\n\tAre you sure that this code is in fix form?\n\tline=%s'%`l` + raise Exception('readfortrancode: Found non-(space,digit) char ' + 'in the first column.\n\tAre you sure that ' + 'this code is in fix form?\n\tline=%s' % `l`) if (not cont or strictf77) and (len(l)>5 and not l[5]==' '): # Continuation of a previous line @@ -596,11 +598,16 @@ groupcounter=groupcounter-1 if skipblocksuntil<=groupcounter: return if groupcounter<=0: - raise 'crackline: groupcounter(=%s) is nonpositive. Check the blocks.'\ - % (groupcounter) + raise Exception('crackline: groupcounter(=%s) is nonpositive. ' + 'Check the blocks.' \ + % (groupcounter)) m1 = beginpattern[0].match((line)) if (m1) and (not m1.group('this')==groupname[groupcounter]): - raise 'crackline: End group %s does not match with previous Begin group %s\n\t%s'%(`m1.group('this')`,`groupname[groupcounter]`,filepositiontext) + raise Exception('crackline: End group %s does not match with ' + 'previous Begin group %s\n\t%s' % \ + (`m1.group('this')`, `groupname[groupcounter]`, + filepositiontext) + ) if skipblocksuntil==groupcounter: skipblocksuntil=-1 grouplist[groupcounter-1].append(groupcache[groupcounter]) @@ -683,7 +690,8 @@ elif k in ['intent','check','dimension','optional','required']: errmess('appenddecl: "%s" not implemented.\n'%k) else: - raise 'appenddecl: Unknown variable definition key:', k + raise Exception('appenddecl: Unknown variable definition key:' + \ + str(k)) return decl selectpattern=re.compile(r'\s*(?P(@\(@.*?@\)@|[*][\d*]+|[*]\s*@\(@.*?@\)@|))(?P.*)\Z',re.I) @@ -1542,7 +1550,8 @@ return uret+gret setmesstext(block) if (not type(block)==types.DictType) and 'block' not in block: - raise 'postcrack: Expected block dictionary instead of ',block + raise Exception('postcrack: Expected block dictionary instead of ' + \ + str(block)) if 'name' in block and not block['name']=='unknown_interface': outmess('%sBlock: %s\n'%(tab,block['name']),0) blocktype=block['block'] Modified: trunk/numpy/lib/function_base.py =================================================================== --- trunk/numpy/lib/function_base.py 2009-03-02 20:05:32 UTC (rev 6534) +++ trunk/numpy/lib/function_base.py 2009-03-02 21:11:31 UTC (rev 6535) @@ -546,7 +546,7 @@ hist /= s if (hist.shape != nbin-2).any(): - raise 'Internal Shape Error' + raise RuntimeError('Internal Shape Error') return hist, edges Modified: trunk/numpy/linalg/lapack_lite/make_lite.py =================================================================== --- trunk/numpy/linalg/lapack_lite/make_lite.py 2009-03-02 20:05:32 UTC (rev 6534) +++ trunk/numpy/linalg/lapack_lite/make_lite.py 2009-03-02 21:11:31 UTC (rev 6535) @@ -141,7 +141,7 @@ class LapackLibrary(FortranLibrary): def _newFortranRoutine(self, rname, filename): routine = FortranLibrary._newFortranRoutine(self, rname, filename) - if 'BLAS' in filename + if 'BLAS' in filename: routine.type = 'blas' elif rname.startswith('z'): routine.type = 'zlapack' From numpy-svn at scipy.org Mon Mar 2 23:59:29 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Mar 2009 22:59:29 -0600 (CST) Subject: [Numpy-svn] r6536 - trunk/numpy/core/include/numpy Message-ID: <20090303045929.E2039C7C011@scipy.org> Author: cdavid Date: 2009-03-02 22:59:18 -0600 (Mon, 02 Mar 2009) New Revision: 6536 Modified: trunk/numpy/core/include/numpy/npy_math.h Log: Add missing npy_modf declaration. Modified: trunk/numpy/core/include/numpy/npy_math.h =================================================================== --- trunk/numpy/core/include/numpy/npy_math.h 2009-03-02 21:11:31 UTC (rev 6535) +++ trunk/numpy/core/include/numpy/npy_math.h 2009-03-03 04:59:18 UTC (rev 6536) @@ -81,6 +81,8 @@ double npy_atan2(double x, double y); double npy_pow(double x, double y); +double npy_modf(double x, double* y); + /* * IEEE 754 fpu handling. Those are guaranteed to be macros */ From numpy-svn at scipy.org Tue Mar 3 04:29:05 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 3 Mar 2009 03:29:05 -0600 (CST) Subject: [Numpy-svn] r6537 - trunk/numpy/core/src Message-ID: <20090303092905.745CDC7C011@scipy.org> Author: cdavid Date: 2009-03-03 03:29:00 -0600 (Tue, 03 Mar 2009) New Revision: 6537 Modified: trunk/numpy/core/src/umath_loops.inc.src Log: Mark unused fptr as unused to avoid spurious warnings flags. Modified: trunk/numpy/core/src/umath_loops.inc.src =================================================================== --- trunk/numpy/core/src/umath_loops.inc.src 2009-03-03 04:59:18 UTC (rev 6536) +++ trunk/numpy/core/src/umath_loops.inc.src 2009-03-03 09:29:00 UTC (rev 6537) @@ -893,7 +893,7 @@ * #OP = >=, <=# **/ static void - at TYPE@_ at kind@(char **args, intp *dimensions, intp *steps, void *func) + at TYPE@_ at kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)) { /* */ BINARY_LOOP { @@ -1289,7 +1289,7 @@ * #OP = CGE, CLE# */ static void -C at TYPE@_ at kind@(char **args, intp *dimensions, intp *steps, void *func) +C at TYPE@_ at kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)) { BINARY_LOOP { const @type@ in1r = ((@type@ *)ip1)[0]; From numpy-svn at scipy.org Tue Mar 3 04:50:09 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 3 Mar 2009 03:50:09 -0600 (CST) Subject: [Numpy-svn] r6538 - trunk/numpy/numarray/numpy Message-ID: <20090303095009.79994C7C00B@scipy.org> Author: cdavid Date: 2009-03-03 03:50:05 -0600 (Tue, 03 Mar 2009) New Revision: 6538 Modified: trunk/numpy/numarray/numpy/arraybase.h Log: Fix wrong typedef for UInt64. Modified: trunk/numpy/numarray/numpy/arraybase.h =================================================================== --- trunk/numpy/numarray/numpy/arraybase.h 2009-03-03 09:29:00 UTC (rev 6537) +++ trunk/numpy/numarray/numpy/arraybase.h 2009-03-03 09:50:05 UTC (rev 6538) @@ -14,7 +14,7 @@ typedef npy_int32 Int32; typedef npy_uint32 UInt32; typedef npy_int64 Int64; -typedef npy_int64 UInt64; +typedef npy_uint64 UInt64; typedef npy_float32 Float32; typedef npy_float64 Float64; From numpy-svn at scipy.org Tue Mar 3 06:57:50 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 3 Mar 2009 05:57:50 -0600 (CST) Subject: [Numpy-svn] r6539 - trunk/doc/release Message-ID: <20090303115750.4D211C7C093@scipy.org> Author: cdavid Date: 2009-03-03 05:57:45 -0600 (Tue, 03 Mar 2009) New Revision: 6539 Modified: trunk/doc/release/1.3.0-notes.rst Log: Update release notes for 1.3.0. Modified: trunk/doc/release/1.3.0-notes.rst =================================================================== --- trunk/doc/release/1.3.0-notes.rst 2009-03-03 09:50:05 UTC (rev 6538) +++ trunk/doc/release/1.3.0-notes.rst 2009-03-03 11:57:45 UTC (rev 6539) @@ -2,14 +2,17 @@ NumPy 1.3.0 Release Notes ========================= -This minor release comes almost four months after the 1.1.0 release. +This minor release comes almost four months after the 1.2.0 release. -New features -============ +Highlights +========== Python 2.6 support ~~~~~~~~~~~~~~~~~~ +Python 2.6 is now supported on all previously supported platforms, including +windows. + http://www.python.org/dev/peps/pep-0361/ Generalized ufuncs @@ -17,19 +20,24 @@ http://projects.scipy.org/scipy/numpy/ticket/887 -Histogram -~~~~~~~~~ +Experimental Windows 64 bits support +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The semantics of histogram has been modified to fix long-standing issues -with outliers handling. The main changes concern +Numpy can now be built on windows 64 bits (amd64 only, not IA64), with both MS +compilers and mingw-w64 compilers: -#. the definition of the bin edges, now including the rightmost edge, and -#. the handling of upper outliers, now ignored rather than tallied in the - rightmost bin. +This is *highly experimental*: DO NOT USE FOR PRODUCTION USE. See INSTALL.txt, +Windows 64 bits section for more information on limitations and how to build it +by yourself. -The previous behavior is still accessible using `new=False`, but is scheduled -to be deprecated in the next release (1.3). +New features +============ +Formatting issues +~~~~~~~~~~~~~~~~~ + +TODO + Nan handling in max/min/sort ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -40,20 +48,37 @@ TODO -gfortran support on windows (32 and 64 bits) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +gfortran support on windows +~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Gfortran can now be used as a fortran compiler for numpy, even when the C -compiler is Visual Studio. +Gfortran can now be used as a fortran compiler for numpy on windows, even when +the C compiler is Visual Studio. Gfortran + Visual studio does not work on +windows 64 bits (but gcc + gfortran does). +Deprecated features +=================== + +Histogram +~~~~~~~~~ + +The semantics of histogram has been modified to fix long-standing issues +with outliers handling. The main changes concern + +#. the definition of the bin edges, now including the rightmost edge, and +#. the handling of upper outliers, now ignored rather than tallied in the + rightmost bin. + +The previous behavior is still accessible using `new=False`, but this is +deprecated, and will be removed entirely in 1.4.0. + Documentation changes ===================== Internal changes ================ -Refactoring numpy.core math configuration -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +numpy.core math configuration revamp +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This should make the porting to new platforms easier, and more robust. In particular, the configuration stage does not need to execute any code on the @@ -61,10 +86,15 @@ http://projects.scipy.org/scipy/numpy/browser/trunk/doc/neps/math_config_clean.txt +umath refactor +~~~~~~~~~~~~~~ + +A lot of code cleanup for umath/ufunc code (charris). + Improvements to build warnings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Numpy can now build with -W -Wall without warnings. +Numpy can now build with -W -Wall without warnings http://projects.scipy.org/scipy/numpy/browser/trunk/doc/neps/warnfix.txt @@ -72,7 +102,9 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~ The core math functions (sin, cos, etc... for basic C types) have been put into -a separate library. The library includes platform-specific fixes for various -maths functions, such as using those versions should be more robust than using -your platform functions directly. The API for existing functions is exactly the -same as the C99 math functions API, except they are prefixed with npy_. +a separate library; it acts as a compatibility layer, to support most C99 maths +functions (real only for now). The library includes platform-specific fixes for +various maths functions, such as using those versions should be more robust +than using your platform functions directly. The API for existing functions is +exactly the same as the C99 math functions API; the only difference is the npy +prefix (npy_cos vs cos). From numpy-svn at scipy.org Tue Mar 3 06:58:03 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 3 Mar 2009 05:58:03 -0600 (CST) Subject: [Numpy-svn] r6540 - trunk Message-ID: <20090303115803.3A956C7C095@scipy.org> Author: cdavid Date: 2009-03-03 05:57:57 -0600 (Tue, 03 Mar 2009) New Revision: 6540 Modified: trunk/INSTALL.txt Log: Add notes on Windows for AMD64. Modified: trunk/INSTALL.txt =================================================================== --- trunk/INSTALL.txt 2009-03-03 11:57:45 UTC (rev 6539) +++ trunk/INSTALL.txt 2009-03-03 11:57:57 UTC (rev 6540) @@ -91,3 +91,44 @@ for SSE2: sudo apt-get install atlas3-sse2 + +Windows 64 bits notes +===================== + +Note: only AMD64 is supported (IA64 is not) - AMD64 is the version most people +want. + +Free compilers (mingw-w64) +-------------------------- + +http://mingw-w64.sourceforge.net/ + +To use the free compilers (mingw-w64), you need to build your own toolchain, as +the mingw project only distribute cross-compilers (cross-compilation is not +supported by numpy). Since this toolchain is still being worked on, serious +compilers bugs can be expected. binutil 2.19 + gcc 4.3.3 + mingw-w64 runtime +gives you a working C compiler (but the C++ is broken). gcc 4.4 will hopefully +be able to run natively. + +This is the only tested way to get a numpy with a FULL blas/lapack (scipy does +not work because of C++). + +MS compilers +------------ + +If you are familiar with MS tools, that's obviously the easiest path, and the +compilers are hopefully more mature (although in my experience, they are quite +fragile, and often segfault on invalid C code). The main drawback is that no +fortran compiler + MS compiler combination has been tested - mingw-w64 gfortran ++ MS compiler does not work at all (it is unclear whether it ever will). + +For python 2.5, you need VS 2005 (MS compiler version 14) targetting +AMD64 bits, or the Platform SDK v6.0 or below (which gives command +line versions of 64 bits target compilers). The PSDK is free. + +For python 2.6, you need VS 2008. The freely available version does not +contains 64 bits compilers (you also need the PSDK, v6.1). + +It is *crucial* to use the right version: python 2.5 -> version 14, python 2.6, +version 15. You can check the compiler version with cl.exe /?. Note also that +for python 2.5, 64 bits and 32 bits versions use a different compiler version. From numpy-svn at scipy.org Tue Mar 3 07:23:39 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 3 Mar 2009 06:23:39 -0600 (CST) Subject: [Numpy-svn] r6541 - trunk/numpy/core/src Message-ID: <20090303122339.15158C7C098@scipy.org> Author: cdavid Date: 2009-03-03 06:23:36 -0600 (Tue, 03 Mar 2009) New Revision: 6541 Modified: trunk/numpy/core/src/multiarraymodule.c Log: Revert r6528 (crashes on windows). I think the bug is only hidden for now, and there may be a leak somewhere in PyArray_PutMask function; should investigate for 1.3.0. Modified: trunk/numpy/core/src/multiarraymodule.c =================================================================== --- trunk/numpy/core/src/multiarraymodule.c 2009-03-03 11:57:57 UTC (rev 6540) +++ trunk/numpy/core/src/multiarraymodule.c 2009-03-03 12:23:36 UTC (rev 6541) @@ -4616,7 +4616,7 @@ "be an array"); return NULL; } - if (!PyArray_ISCONTIGUOUS(self) || !(self->flags & ALIGNED)) { + if (!PyArray_ISCONTIGUOUS(self)) { PyArrayObject *obj; int flags = NPY_CARRAY | NPY_UPDATEIFCOPY; From numpy-svn at scipy.org Fri Mar 6 04:27:25 2009 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 6 Mar 2009 03:27:25 -0600 Subject: [Numpy-svn] Pharmacy Message 67176467 Message-ID: <200903060927.n269RPb7010130@dr0.enthought.com> Don't be the last one in the queue for good presents. Prestige offers you the best luxury things that are easy to get. Cheaper than ever and there is no need to wait ages in the stores QUANTITIES ARE LIMITED - ORDER NOW http://wlp.op.luqxiwow.cn/?qe From numpy-svn at scipy.org Thu Mar 12 14:22:40 2009 From: numpy-svn at scipy.org (VIAGRA ® Official Site) Date: Thu, 12 Mar 2009 13:22:40 -0500 Subject: [Numpy-svn] Discount Message 238957 Message-ID: <20090312102240.2415.qmail@org-a47199b0882> An HTML attachment was scrubbed... URL: From numpy-svn at scipy.org Fri Mar 13 03:15:49 2009 From: numpy-svn at scipy.org (Today'S Bestsellers) Date: Fri, 13 Mar 2009 02:15:49 -0500 Subject: [Numpy-svn] TT: Discount Message 55% OFF Message-ID: <20090313131601.3241.qmail@NATALI> An HTML attachment was scrubbed... URL: From numpy-svn at scipy.org Tue Mar 17 08:06:19 2009 From: numpy-svn at scipy.org (Jxxxefo Gusner) Date: Tue, 17 Mar 2009 07:06:19 -0500 Subject: [Numpy-svn] We want your comment in our paper Message-ID: <200903171206.n2HC6J9X000890@dr0.enthought.com> An HTML attachment was scrubbed... URL: From numpy-svn at scipy.org Thu Mar 19 05:25:43 2009 From: numpy-svn at scipy.org (VIAGRA ® Official Site) Date: Thu, 19 Mar 2009 04:25:43 -0500 Subject: [Numpy-svn] UK Pharmacy Message 40996 Message-ID: <20090319132543.3918.qmail@acasa> An HTML attachment was scrubbed... URL: From numpy-svn at scipy.org Sun Mar 29 09:11:20 2009 From: numpy-svn at scipy.org (Uumeqsep) Date: Sun, 29 Mar 2009 08:11:20 -0500 Subject: [Numpy-svn] Your portfolio needed Message-ID: <200903291311.n2TDBJql031423@dr0.enthought.com> An HTML attachment was scrubbed... URL: From numpy-svn at scipy.org Mon Mar 30 05:42:08 2009 From: numpy-svn at scipy.org (Power 96684) Date: Mon, 30 Mar 2009 04:42:08 -0500 Subject: [Numpy-svn] dysb Do you know my secret of success with women? Pheromones! defd Message-ID: <200903300942.n2U9g8RX007694@dr0.enthought.com> numpy-svn at scipy.org Acai Power berry is your key to losing weight. This Amazon forest secret has been around hollywood circles for years now . Take advantage of our free trial and start losing weight now QUANTITIES ARE LIMITED - ORDER NOW http://ibu.we.ACTUALBODY.COM Satisfaction Guaranteed If within 30 days of receiving your purchase you're not completely satisfied, return it for the price you paid for, or we will gladly replace it.