summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scipy/base/function_base.py4
-rw-r--r--scipy/base/index_tricks.py4
-rw-r--r--scipy/base/numeric.py5
-rw-r--r--scipy/base/shape_base.py9
-rw-r--r--scipy/base/tests/test_function_base.py11
-rw-r--r--scipy/base/tests/test_twodim_base.py (renamed from scipy/base/tests/test_matrix_base.py)12
-rw-r--r--scipy/base/twodim_base.py2
-rw-r--r--scipy/base/type_check.py8
8 files changed, 29 insertions, 26 deletions
diff --git a/scipy/base/function_base.py b/scipy/base/function_base.py
index 4f7e76d82..6e55b6521 100644
--- a/scipy/base/function_base.py
+++ b/scipy/base/function_base.py
@@ -447,12 +447,14 @@ def diff(x, n=1,axis=-1):
return x
if n<0:
raise ValueError,'Order must be non-negative but got ' + `n`
- x = x.ravel()
+ x = asarray(x)
nd = len(x.shape)
slice1 = [slice(None)]*nd
slice2 = [slice(None)]*nd
slice1[axis] = slice(1,None)
slice2[axis] = slice(None,-1)
+ slice1 = tuple(slice1)
+ slice2 = tuple(slice2)
if n > 1:
return diff(x[slice1]-x[slice2], n-1, axis=axis)
else:
diff --git a/scipy/base/index_tricks.py b/scipy/base/index_tricks.py
index e780bae68..101472777 100644
--- a/scipy/base/index_tricks.py
+++ b/scipy/base/index_tricks.py
@@ -3,7 +3,7 @@
import types
import numeric as _nx
from numeric import asarray
-__all__ = ['mgrid','ogrid','r_', 'index_exp', 'ix_']
+__all__ = ['mgrid','ogrid','r_', 'c_', 'index_exp', 'ix_']
from type_check import ScalarType
import function_base
@@ -212,7 +212,7 @@ class concatenator:
return 0
r_=concatenator(0)
-#c_=concatenator(-1)
+c_=concatenator(-1)
#row = concatenator(0,1)
#col = concatenator(-1,1)
diff --git a/scipy/base/numeric.py b/scipy/base/numeric.py
index 8d7f0aad3..d3d5470d1 100644
--- a/scipy/base/numeric.py
+++ b/scipy/base/numeric.py
@@ -1,11 +1,12 @@
import sys
+import types, math
+
import multiarray
import umath
from umath import *
from numerictypes import *
-
-import types, math
+from _compiled_base import _insert
newaxis = None
diff --git a/scipy/base/shape_base.py b/scipy/base/shape_base.py
index e4269dc55..f2a26885f 100644
--- a/scipy/base/shape_base.py
+++ b/scipy/base/shape_base.py
@@ -15,10 +15,11 @@ def apply_along_axis(func1d,axis,arr,*args):
"""
arr = asarray(arr)
nd = arr.ndim
- if axis < 0: axis += nd
+ if axis < 0:
+ axis += nd
if (axis >= nd):
- raise ValueError, "axis must be less than arr.ndim; "+\
- "axis=%d, rank=%d." % (axis,nd)
+ raise ValueError("axis must be less than arr.ndim; axis=%d, rank=%d."
+ % (axis,nd))
ind = [0]*(nd-1)
dims = arr.shape
i = zeros(nd,'O')
@@ -26,7 +27,7 @@ def apply_along_axis(func1d,axis,arr,*args):
indlist.remove(axis)
i[axis] = slice(None,None)
outshape = take(shape(arr),indlist)
- i.put(indlist, v)
+ i.put(indlist, ind)
res = func1d(arr[tuple(i)],*args)
# if res is a number, then we have a smaller output array
if isscalar(res):
diff --git a/scipy/base/tests/test_function_base.py b/scipy/base/tests/test_function_base.py
index c202640f8..6ce4ccc79 100644
--- a/scipy/base/tests/test_function_base.py
+++ b/scipy/base/tests/test_function_base.py
@@ -96,7 +96,8 @@ class test_cumsum(unittest.TestCase):
def check_basic(self):
ba = [1,2,10,11,6,5,4]
ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]
- for ctype in ['1','b','s','i','l','f','d','F','D']:
+ for ctype in [int8,uint8,int16,uint16,int32,uint32,
+ float32,float64,complex64,complex128]:
a = array(ba,ctype)
a2 = array(ba2,ctype)
assert_array_equal(cumsum(a), array([1,3,13,24,30,35,39],ctype))
@@ -111,14 +112,15 @@ class test_prod(unittest.TestCase):
def check_basic(self):
ba = [1,2,10,11,6,5,4]
ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]
- for ctype in ['1','b','s','i','l','f','d','F','D']:
+ for ctype in [int16,uint16,int32,uint32,
+ float32,float64,complex64,complex128]:
a = array(ba,ctype)
a2 = array(ba2,ctype)
if ctype in ['1', 'b']:
self.failUnlessRaises(ArithmeticError, prod, a)
self.failUnlessRaises(ArithmeticError, prod, a2, 1)
self.failUnlessRaises(ArithmeticError, prod, a)
- else:
+ else:
assert_equal(prod(a),26400)
assert_array_equal(prod(a2,axis=0),
array([50,36,84,180],ctype))
@@ -128,7 +130,8 @@ class test_cumprod(unittest.TestCase):
def check_basic(self):
ba = [1,2,10,11,6,5,4]
ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]
- for ctype in ['1','b','s','i','l','f','d','F','D']:
+ for ctype in [int16,uint16,int32,uint32,
+ float32,float64,complex64,complex128]:
a = array(ba,ctype)
a2 = array(ba2,ctype)
if ctype in ['1', 'b']:
diff --git a/scipy/base/tests/test_matrix_base.py b/scipy/base/tests/test_twodim_base.py
index 5d9c23805..60a6c1673 100644
--- a/scipy/base/tests/test_matrix_base.py
+++ b/scipy/base/tests/test_twodim_base.py
@@ -13,8 +13,6 @@ del sys.path[0]
##################################################
-val = limits.double_resolution
-
def get_mat(n):
data = arange(n)
@@ -27,7 +25,7 @@ class test_eye(unittest.TestCase):
[0,1,0,0],
[0,0,1,0],
[0,0,0,1]]))
- assert_equal(eye(4,typecode='f'),array([[1,0,0,0],
+ assert_equal(eye(4,dtype='f'),array([[1,0,0,0],
[0,1,0,0],
[0,0,1,0],
[0,0,0,1]],'f'))
@@ -88,8 +86,7 @@ class test_diag(unittest.TestCase):
class test_fliplr(unittest.TestCase):
def check_basic(self):
- self.failUnlessRaises(ValueError, fliplr, ones(4))
- self.failUnlessRaises(ValueError, fliplr, ones((4,3,2)))
+ self.failUnlessRaises(ValueError, fliplr, ones(4))
a = get_mat(4)
b = a[:,::-1]
assert_equal(fliplr(a),b)
@@ -101,8 +98,6 @@ class test_fliplr(unittest.TestCase):
class test_flipud(unittest.TestCase):
def check_basic(self):
- self.failUnlessRaises(ValueError, flipud, ones(4))
- self.failUnlessRaises(ValueError, flipud, ones((4,3,2)))
a = get_mat(4)
b = a[::-1,:]
assert_equal(flipud(a),b)
@@ -115,7 +110,6 @@ class test_flipud(unittest.TestCase):
class test_rot90(unittest.TestCase):
def check_basic(self):
self.failUnlessRaises(ValueError, rot90, ones(4))
- self.failUnlessRaises(ValueError, rot90, ones((4,3,2)))
a = [[0,1,2],
[3,4,5]]
@@ -140,4 +134,4 @@ class test_rot90(unittest.TestCase):
assert_equal(rot90(a,k=k),b4)
if __name__ == "__main__":
- ScipyTest('scipy.base.matrix').run()
+ ScipyTest('scipy.base.twodim_base').run()
diff --git a/scipy/base/twodim_base.py b/scipy/base/twodim_base.py
index dbe9115e1..acb286c0f 100644
--- a/scipy/base/twodim_base.py
+++ b/scipy/base/twodim_base.py
@@ -32,7 +32,7 @@ def rot90(m, k=1):
dimensions of m.
"""
m = asarray(m)
- if n.ndim < 2:
+ if m.ndim < 2:
raise ValueError, "Input must >= 2-d."
k = k % 4
if k == 0: return m
diff --git a/scipy/base/type_check.py b/scipy/base/type_check.py
index abc9b057f..749126ff8 100644
--- a/scipy/base/type_check.py
+++ b/scipy/base/type_check.py
@@ -2,8 +2,8 @@
import types
import numeric as _nx
-from numeric import ndarray, array, isinf, isnan, isfinite, signbit, \
- ufunc, ScalarType, asarray
+from numeric import ndarray, asarray, array, isinf, isnan, isfinite, signbit, \
+ ufunc, ScalarType, obj2dtype
__all__ = ['iscomplexobj','isrealobj','imag','iscomplex',
'isscalar','isneginf','isposinf',
@@ -57,9 +57,11 @@ def isscalar(num):
def real(val):
return asarray(val).real
+ return aval
def imag(val):
return asarray(val).imag
+ return aval
def iscomplex(x):
return imag(x) != _nx.zeros_like(x)
@@ -116,7 +118,7 @@ def real_if_close(a,tol=100):
return a
if tol > 1:
import getlimits
- f = getlmits.finfo(a.dtypechar.lower())
+ f = getlimits.finfo(a.dtype)
tol = f.epsilon * tol
if _nx.allclose(a.imag, 0, atol=tol):
a = a.real