summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-01-04 22:37:16 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-01-04 22:37:16 +0000
commit5cfcf93bf09c3a78654099ddcb3b7b184e8d4615 (patch)
tree2ba7ac321aa765f08bc2413f178fd74d4eb8c1ff /numpy
parent490712cd35dcecfc9423de4bde0b29cb012dda25 (diff)
downloadnumpy-5cfcf93bf09c3a78654099ddcb3b7b184e8d4615.tar.gz
More fixes...
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/code_generators/generate_umath.py3
-rw-r--r--numpy/core/oldnumeric.py2
-rw-r--r--numpy/core/src/arraymethods.c3
-rw-r--r--numpy/core/src/arrayobject.c2
-rw-r--r--numpy/core/src/scalartypes.inc.src2
-rw-r--r--numpy/core/src/umathmodule.c.src65
-rw-r--r--numpy/core/tests/test_ma.py4
-rw-r--r--numpy/core/tests/test_records.py5
-rw-r--r--numpy/core/tests/test_umath.py2
-rw-r--r--numpy/dft/tests/test_helper.py2
-rw-r--r--numpy/lib/__init__.py2
-rw-r--r--numpy/lib/function_base.py1
-rw-r--r--numpy/lib/tests/test_function_base.py5
-rw-r--r--numpy/lib/tests/test_getlimits.py4
-rw-r--r--numpy/lib/tests/test_index_tricks.py4
-rw-r--r--numpy/lib/tests/test_polynomial.py4
-rw-r--r--numpy/lib/tests/test_shape_base.py5
-rw-r--r--numpy/lib/tests/test_twodim_base.py4
-rw-r--r--numpy/lib/tests/test_type_check.py5
-rw-r--r--numpy/lib/tests/test_ufunclike.py10
-rw-r--r--numpy/lib/type_check.py7
-rw-r--r--numpy/lib/ufunclike.py22
22 files changed, 101 insertions, 62 deletions
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py
index 16945d256..4cf804c2f 100644
--- a/numpy/core/code_generators/generate_umath.py
+++ b/numpy/core/code_generators/generate_umath.py
@@ -96,6 +96,9 @@ defdict = {
(1,1), None,
"determines -x elementwise",
],
+'sign' : [nobool,'',(),(1,1),None,
+ "returns -1 if x < 0 and 0 if x==0 and 1 if x > 0"
+ ],
'greater' : [all,'',(),(2,1), None,
"returns elementwise x1 > x2 in a bool array.",
'?'*len(all)
diff --git a/numpy/core/oldnumeric.py b/numpy/core/oldnumeric.py
index 833a2176e..3773af6cc 100644
--- a/numpy/core/oldnumeric.py
+++ b/numpy/core/oldnumeric.py
@@ -31,6 +31,8 @@ import multiarray as mu
import umath as um
import numerictypes as nt
from numeric import asarray, array, correlate, outer, concatenate
+from umath import sign, absolute, multiply
+import numeric as _nx
import sys
_dt_ = nt.dtype2char
diff --git a/numpy/core/src/arraymethods.c b/numpy/core/src/arraymethods.c
index 2e5ea4ee4..7814f1096 100644
--- a/numpy/core/src/arraymethods.c
+++ b/numpy/core/src/arraymethods.c
@@ -848,7 +848,6 @@ _setobject_pkl(PyArrayObject *self, PyObject *list)
return 0;
}
-
static char doc_reduce[] = "a.__reduce__() for pickling.";
static PyObject *
@@ -864,7 +863,7 @@ array_reduce(PyArrayObject *self, PyObject *args)
ret = PyTuple_New(3);
if (ret == NULL) return NULL;
- mod = PyImport_ImportModule("numpy.base._internal");
+ mod = PyImport_ImportModule("numpy.core._internal");
if (mod == NULL) {Py_DECREF(ret); return NULL;}
obj = PyObject_GetAttrString(mod, "_reconstruct");
Py_DECREF(mod);
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 1d9e15976..1f23e77e1 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -8134,7 +8134,7 @@ arraydescr_reduce(PyArray_Descr *self, PyObject *args)
ret = PyTuple_New(3);
if (ret == NULL) return NULL;
- mod = PyImport_ImportModule("numpy.base.multiarray");
+ mod = PyImport_ImportModule("numpy.core.multiarray");
if (mod == NULL) {Py_DECREF(ret); return NULL;}
obj = PyObject_GetAttrString(mod, "dtypedescr");
Py_DECREF(mod);
diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src
index 4d3c4cd28..a47819913 100644
--- a/numpy/core/src/scalartypes.inc.src
+++ b/numpy/core/src/scalartypes.inc.src
@@ -1194,7 +1194,7 @@ gentype_reduce(PyObject *self, PyObject *args)
if (PyObject_AsReadBuffer(self, (const void **)&buffer, &buflen)<0) {
Py_DECREF(ret); return NULL;
}
- mod = PyImport_ImportModule("numpy.base.multiarray");
+ mod = PyImport_ImportModule("numpy.core.multiarray");
if (mod == NULL) return NULL;
obj = PyObject_GetAttrString(mod, "scalar");
Py_DECREF(mod);
diff --git a/numpy/core/src/umathmodule.c.src b/numpy/core/src/umathmodule.c.src
index dd140354b..8945821e3 100644
--- a/numpy/core/src/umathmodule.c.src
+++ b/numpy/core/src/umathmodule.c.src
@@ -693,7 +693,6 @@ static void
#OP=+*3,-*3#
#kind=add*3,subtract*3#
#typ=(float, double, longdouble)*2#
-
*/
static void
@@ -1267,7 +1266,7 @@ OBJECT_@kind@(char **args, intp *dimensions, intp *steps, void *func) {
#TYPE=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#
#typ=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#
*/
-static void
+ static void
@TYPE@_negative(char **args, intp *dimensions, intp *steps, void *func)
{
register intp i;
@@ -1281,6 +1280,68 @@ static void
#define BOOL_negative BOOL_logical_not
+#define _SIGN1(x) ((x) > 0 ? 1 : ((x) < 0 ? -1 : 0))
+#define _SIGN2(x) ((x) == 0 ? 0 : 1)
+#define _SIGNC(x) (((x).real > 0) ? 1 : ((x).real < 0 ? -1 : ((x).imag > 0 ? 1 : ((x).imag < 0) ? -1 : 0)))
+/**begin repeat
+#TYPE=BYTE,SHORT,INT,LONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE,UBYTE,USHORT,UINT,ULONG,ULONGLONG#
+#typ=byte,short,int,long,longlong,float,double,longdouble,ubyte,ushort,uint,ulong,ulonglong#
+#func=_SIGN1*8,_SIGN2*5#
+ */
+static void
+@TYPE@_sign(char **args, intp *dimensions, intp *steps, void *func)
+{
+ register intp i;
+ intp is1=steps[0],os=steps[1], n=dimensions[0];
+ char *i1=args[0], *op=args[1];
+ @typ@ t1;
+ for(i=0; i<n; i++, i1+=is1, op+=os) {
+ t1 = *((@typ@ *)i1);
+ *((@typ@ *)op) = (@typ@) @func@(t1);
+ }
+}
+/**end repeat**/
+
+/**begin repeat
+#TYPE=CFLOAT,CDOUBLE,CLONGDOUBLE#
+#typ=cfloat,cdouble,clongdouble#
+ */
+static void
+@TYPE@_sign(char **args, intp *dimensions, intp *steps, void *func)
+{
+ register intp i;
+ intp is1=steps[0],os=steps[1], n=dimensions[0];
+ char *i1=args[0], *op=args[1];
+ @typ@ t1;
+ for(i=0; i<n; i++, i1+=is1, op+=os) {
+ t1 = *((@typ@ *)i1);
+ (*((@typ@ *)op)).real = _SIGNC(t1);
+ (*((@typ@ *)op)).imag = 0;
+ }
+}
+/**end repeat**/
+
+#undef _SIGN1
+#undef _SIGN2
+#undef _SIGNC
+
+
+static void
+OBJECT_sign(char **args, intp *dimensions, intp *steps, void *func)
+{
+ register intp i;
+ intp is1=steps[0],os=steps[1], n=dimensions[0];
+ char *i1=args[0], *op=args[1];
+ PyObject *t1, *zero, *res;
+ zero = PyInt_FromLong(0);
+ for(i=0; i<n; i++, i1+=is1, op+=os) {
+ t1 = *((PyObject **)i1);
+ res = PyInt_FromLong((long) PyObject_Compare(t1, zero));
+ *((PyObject **)op) = res;
+ }
+ Py_DECREF(zero);
+}
+
/**begin repeat
#TYPE=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#
diff --git a/numpy/core/tests/test_ma.py b/numpy/core/tests/test_ma.py
index 5a6c95533..aa052ca26 100644
--- a/numpy/core/tests/test_ma.py
+++ b/numpy/core/tests/test_ma.py
@@ -1,6 +1,6 @@
import numpy
import types, time
-from numpy.base.ma import *
+from numpy.core.ma import *
from numpy.testing import ScipyTestCase, ScipyTest
def eq(v,w):
result = allclose(v,w)
@@ -633,5 +633,5 @@ def testinplace(x):
testinplace.test_name = 'Inplace operations'
if __name__ == "__main__":
- ScipyTest('numpy.base.ma').run()
+ ScipyTest('numpy.core.ma').run()
#timingTest()
diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py
index cfdb2e9e3..4cdbcb59c 100644
--- a/numpy/core/tests/test_records.py
+++ b/numpy/core/tests/test_records.py
@@ -2,9 +2,8 @@
from numpy.testing import *
set_package_path()
import os as _os
-import numpy.base;reload(numpy.base)
-from numpy.base import *
-from numpy.base import records as rec
+import numpy.core;reload(numpy.core)
+from numpy.core import *
restore_path()
class test_fromrecords(ScipyTestCase):
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 6b4aa3221..aa5074f23 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -1,7 +1,7 @@
from numpy.testing import *
set_package_path()
-from numpy.base.umath import minimum, maximum
+from numpy.core.umath import minimum, maximum
restore_path()
diff --git a/numpy/dft/tests/test_helper.py b/numpy/dft/tests/test_helper.py
index e8dd36165..3742966c8 100644
--- a/numpy/dft/tests/test_helper.py
+++ b/numpy/dft/tests/test_helper.py
@@ -6,7 +6,7 @@
import sys
from numpy.testing import *
set_package_path()
-from numpy.corefft import fftshift,ifftshift,fftfreq
+from numpy.dft import fftshift,ifftshift,fftfreq
del sys.path[0]
from numpy import pi
diff --git a/numpy/lib/__init__.py b/numpy/lib/__init__.py
index b77d85a96..13c5ec10b 100644
--- a/numpy/lib/__init__.py
+++ b/numpy/lib/__init__.py
@@ -14,8 +14,6 @@ from polynomial import *
from machar import *
from getlimits import *
import convertcode
-del nt
-
from utils import *
__all__ = filter(lambda s:not s.startswith('_'),dir())
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index bfaa90a94..71d46e843 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -24,7 +24,6 @@ from type_check import ScalarType
from shape_base import atleast_1d
from twodim_base import diag
from _compiled_base import digitize, bincount, _insert
-from ufunclike import sign
#end Fernando's utilities
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 37d3db1bf..41cdf45b4 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -3,8 +3,9 @@ import sys
from numpy.testing import *
set_package_path()
-import numpy.base;reload(numpy.base)
-from numpy.base import *
+import numpy.lib;reload(numpy.lib)
+from numpy.lib import *
+from numpy.core import *
del sys.path[0]
class test_any(ScipyTestCase):
diff --git a/numpy/lib/tests/test_getlimits.py b/numpy/lib/tests/test_getlimits.py
index 5e8706895..f70081518 100644
--- a/numpy/lib/tests/test_getlimits.py
+++ b/numpy/lib/tests/test_getlimits.py
@@ -3,8 +3,8 @@
from numpy.testing import *
set_package_path()
-import numpy.base;reload(numpy.base)
-from numpy.base.getlimits import finfo
+import numpy.lib;reload(numpy.lib)
+from numpy.lib.getlimits import finfo
from numpy import single,double,longdouble
restore_path()
diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py
index c5091909e..13d565b4c 100644
--- a/numpy/lib/tests/test_index_tricks.py
+++ b/numpy/lib/tests/test_index_tricks.py
@@ -1,8 +1,8 @@
from numpy.testing import *
set_package_path()
-import numpy.base;reload(numpy.base)
-from numpy.base import *
+import numpy.lib;reload(numpy.lib)
+from numpy.lib import *
restore_path()
class test_grid(ScipyTestCase):
diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py
index d37e8b6b9..dac4d866f 100644
--- a/numpy/lib/tests/test_polynomial.py
+++ b/numpy/lib/tests/test_polynomial.py
@@ -1,6 +1,6 @@
"""
->>> import numpy.base as nx
->>> from numpy.base.polynomial import poly1d, polydiv
+>>> import numpy.core as nx
+>>> from numpy.lib.polynomial import poly1d, polydiv
>>> p = poly1d([1.,2,3])
>>> p
diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py
index 175bc8584..11cf8fc91 100644
--- a/numpy/lib/tests/test_shape_base.py
+++ b/numpy/lib/tests/test_shape_base.py
@@ -1,8 +1,9 @@
from numpy.testing import *
set_package_path()
-import numpy.base;
-from numpy.base import *
+import numpy.lib;
+from numpy.lib import *
+from numpy.core import *
restore_path()
class test_apply_along_axis(ScipyTestCase):
diff --git a/numpy/lib/tests/test_twodim_base.py b/numpy/lib/tests/test_twodim_base.py
index 329a23f5b..1ed309f7c 100644
--- a/numpy/lib/tests/test_twodim_base.py
+++ b/numpy/lib/tests/test_twodim_base.py
@@ -4,8 +4,8 @@
from numpy.testing import *
set_package_path()
-import numpy.base;reload(numpy.base)
-from numpy.base import *
+import numpy.lib;reload(numpy.lib)
+from numpy.lib import *
restore_path()
##################################################
diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py
index e84d86e0c..5d026a9f9 100644
--- a/numpy/lib/tests/test_type_check.py
+++ b/numpy/lib/tests/test_type_check.py
@@ -3,8 +3,9 @@ import sys
from numpy.testing import *
set_package_path()
-import numpy.base;reload(numpy.base);reload(numpy.base.type_check)
-from numpy.base import *
+import numpy.lib;reload(numpy.lib);reload(numpy.lib.type_check)
+from numpy.lib import *
+from numpy.core import *
restore_path()
def assert_all(x):
diff --git a/numpy/lib/tests/test_ufunclike.py b/numpy/lib/tests/test_ufunclike.py
index f7313526d..5934aa23d 100644
--- a/numpy/lib/tests/test_ufunclike.py
+++ b/numpy/lib/tests/test_ufunclike.py
@@ -1,6 +1,6 @@
"""
->>> import numpy.base as nx
->>> import numpy.base.ufunclike as U
+>>> import numpy.core as nx
+>>> import numpy.lib.ufunclike as U
Test fix:
>>> a = nx.array([[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]])
@@ -21,8 +21,8 @@ Test isposinf, isneginf, sign
array([True, False, False, False, False, False], dtype=bool)
>>> U.isneginf(a)
array([False, True, False, False, False, False], dtype=bool)
->>> U.sign(a)
-array([ 1, -1, 0, 0, 1, -1])
+>>> nx.sign(a)
+array([ 1., -1., 0., 0., 1., -1.])
Same thing with an output array:
>>> y = nx.zeros(a.shape, bool)
@@ -34,7 +34,7 @@ array([True, False, False, False, False, False], dtype=bool)
array([False, True, False, False, False, False], dtype=bool)
>>> y
array([False, True, False, False, False, False], dtype=bool)
->>> U.sign(a, y)
+>>> nx.sign(a, y)
array([True, True, False, False, True, True], dtype=bool)
>>> y
array([True, True, False, False, True, True], dtype=bool)
diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py
index 214e3504a..28f01cbc7 100644
--- a/numpy/lib/type_check.py
+++ b/numpy/lib/type_check.py
@@ -1,7 +1,6 @@
## Automatically adapted for numpy Sep 19, 2005 by convertcode.py
__all__ = ['iscomplexobj','isrealobj','imag','iscomplex',
- 'isscalar',
'isreal','nan_to_num','real','real_if_close',
'typename','asfarray','mintypecode','asscalar',
'common_type']
@@ -51,12 +50,6 @@ def asfarray(a, dtype=_nx.float_):
a = asarray(a,dtype=dtype)
return a
-def isscalar(num):
- if isinstance(num, _nx.generic):
- return True
- else:
- return type(num) in ScalarType
-
def real(val):
return asarray(val).real
diff --git a/numpy/lib/ufunclike.py b/numpy/lib/ufunclike.py
index ee5d918d6..c291c7e9c 100644
--- a/numpy/lib/ufunclike.py
+++ b/numpy/lib/ufunclike.py
@@ -2,11 +2,11 @@
Module of functions that are like ufuncs in acting on arrays and optionally
storing results in an output array.
"""
-__all__ = ['fix', 'isneginf', 'isposinf', 'sign', 'log2']
+__all__ = ['fix', 'isneginf', 'isposinf', 'log2']
import numpy.core.numeric as nx
from numpy.core.numeric import asarray, empty, empty_like, isinf, signbit, zeros
-import umath
+import numpy.core.umath as umath
def fix(x, y=None):
""" Round x to nearest integer towards zero.
@@ -43,24 +43,6 @@ def isneginf(x, y=None):
umath.logical_and(isinf(x), signbit(x), y)
return y
-def sign(x, y=None):
- """sign(x) gives an array with shape of x with elexents defined by sign
- function: where x is less than 0 return -1, where x greater than 0, a=1,
- elsewhere a=0.
- """
- x = asarray(x)
- if y is None:
- y = zeros(x.shape, dtype=nx.int_)
- if x.ndim == 0:
- if x < 0:
- y -= 1
- elif x > 0:
- y += 1
- else:
- y[x<0] = -1
- y[x>0] = 1
- return y
-
_log2 = umath.log(2)
def log2(x, y=None):
"""Returns the base 2 logarithm of x