summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2005-10-02 03:51:44 +0000
committerTravis Oliphant <oliphant@enthought.com>2005-10-02 03:51:44 +0000
commitfb0ceff29f606d51c396521f8bee36d414e1cca4 (patch)
treefaaa6aef79ea6ddeb4ad6ee9ee8b96ee20223c67
parent0e1c0c01b93cfd521dbce975b1cd28517d2f151f (diff)
downloadnumpy-fb0ceff29f606d51c396521f8bee36d414e1cca4.tar.gz
Fixes by Eric Firing..
-rw-r--r--THANKS.txt1
-rw-r--r--scipy/base/function_base.py8
-rw-r--r--scipy/base/matrix.py27
-rw-r--r--scipy/base/numeric.py1
-rw-r--r--scipy/base/numerictypes.py6
-rw-r--r--scipy/base/oldnumeric.py3
-rw-r--r--scipy/base/src/arraymethods.c16
-rw-r--r--scipy/base/src/multiarraymodule.c7
8 files changed, 46 insertions, 23 deletions
diff --git a/THANKS.txt b/THANKS.txt
index a14ebb0b1..6342264f2 100644
--- a/THANKS.txt
+++ b/THANKS.txt
@@ -8,3 +8,4 @@ Fernando Perez for code snippets and ideas
John Hunter for code snippets (from matplotlib)
Chris Hanley for help with records.py, testing, and bug fixes.
Travis Vaught and Joe Cooper for administration of scipy.org web site and SVN
+Eric Firing for bugfixes.
diff --git a/scipy/base/function_base.py b/scipy/base/function_base.py
index db6d703e4..1171da49a 100644
--- a/scipy/base/function_base.py
+++ b/scipy/base/function_base.py
@@ -553,7 +553,7 @@ def nanmin(x,axis=-1):
"""
y = array(x)
if not issubclass(y.dtype, _nx.integer):
- y[isnan(x)] = nx.inf
+ y[isnan(x)] = _nx.inf
return y.min(axis)
def nanargmin(x,axis=-1):
@@ -561,7 +561,7 @@ def nanargmin(x,axis=-1):
"""
y = array(x)
if not issubclass(y.dtype, _nx.integer):
- y[isnan(x)] = nx.inf
+ y[isnan(x)] = _nx.inf
return y.argmin(axis)
def nanmax(x,axis=-1):
@@ -569,7 +569,7 @@ def nanmax(x,axis=-1):
"""
y = array(x)
if not issubclass(y.dtype, _nx.integer):
- y[isnan(x)] = -nx.inf
+ y[isnan(x)] = -_nx.inf
return y.max(axis)
def nanargmax(x,axis=-1):
@@ -577,7 +577,7 @@ def nanargmax(x,axis=-1):
"""
y = array(x)
if not issubclass(y.dtype, _nx.integer):
- y[isnan(x)] = -nx.inf
+ y[isnan(x)] = -_nx.inf
return y.argmax(axis)
def disp(mesg, device=None, linefeed=1):
diff --git a/scipy/base/matrix.py b/scipy/base/matrix.py
index dfe3cc0a3..59d844a4c 100644
--- a/scipy/base/matrix.py
+++ b/scipy/base/matrix.py
@@ -1,6 +1,7 @@
import numeric as N
from numeric import ArrayType, concatenate, integer
+from type_check import isscalar
from function_base import binary_repr
import types
import string as str_
@@ -103,20 +104,24 @@ class matrix(N.ndarray):
return
def __getitem__(self, index):
- out = (self.A)[index]
- # Need to swap if slice is on first index
+ out = N.ndarray.__getitem__(self, index)
+ # Need to swap if slice is on first inde
+ retscal = False
try:
n = len(index)
- if (n > 1) and isinstance(index[0], types.SliceType):
- if (isinstance(index[1], types.IntType) or
- isinstance(index[1], types.LongType) or
- isinstance(index[1], integer)):
- sh = out.shape
- out.shape = (sh[1], sh[0])
- return matrix(out)
- return out
+ if (n==2):
+ if isinstance(index[0], types.SliceType):
+ if (isscalar(index[1])):
+ sh = out.shape
+ out.shape = (sh[1], sh[0])
+ else:
+ if (isscalar(index[0])) and (isscalar(index[1])):
+ retscal = True
except TypeError:
- return matrix(out)
+ pass
+ if retscal and out.shape == (1,1): # convert scalars
+ return out.A[0,0]
+ return out
def __mul__(self, other):
if isinstance(other, N.ndarray) and other.ndim == 0:
diff --git a/scipy/base/numeric.py b/scipy/base/numeric.py
index b32aea512..a80940bca 100644
--- a/scipy/base/numeric.py
+++ b/scipy/base/numeric.py
@@ -98,6 +98,7 @@ def convolve(a,v,mode='full'):
return correlate(a,asarray(v)[::-1],mode)
ndarray = multiarray.ndarray
+ndbigarray = multiarray.ndbigarray
ufunc = type(sin)
inner = multiarray.inner
diff --git a/scipy/base/numerictypes.py b/scipy/base/numerictypes.py
index b77946f3e..6e4213eed 100644
--- a/scipy/base/numerictypes.py
+++ b/scipy/base/numerictypes.py
@@ -333,9 +333,9 @@ class _castdict(dict):
return dict.__getitem__(self, obj2dtype(obj))
cast = _castdict()
-ScalarType = [_types.IntType, _types.LongType, _types.FloatType,
- _types.StringType, _types.UnicodeType, _types.ComplexType,
- _types.BufferType]
+ScalarType = [_types.IntType, _types.FloatType,
+ _types.ComplexType, _types.LongType, _types.BooleanType,
+ _types.StringType, _types.UnicodeType, _types.BufferType]
ScalarType.extend(_dtype2char_dict.keys())
for key in _dtype2char_dict.keys():
cast[key] = lambda x, k=key : array(x,copy=0).astype(k)
diff --git a/scipy/base/oldnumeric.py b/scipy/base/oldnumeric.py
index 3831143e6..6f821e88b 100644
--- a/scipy/base/oldnumeric.py
+++ b/scipy/base/oldnumeric.py
@@ -188,6 +188,9 @@ def resize(a, new_shape):
"""resize(a,new_shape) returns a new array with the specified shape.
The original array's total size can be any size. It
fills the new array with repeated copies of a.
+
+ Note that a.resize(new_shape) will fill array with 0's
+ beyond current definition of a.
"""
a = ravel(a)
diff --git a/scipy/base/src/arraymethods.c b/scipy/base/src/arraymethods.c
index 3928fa50a..84a7578f0 100644
--- a/scipy/base/src/arraymethods.c
+++ b/scipy/base/src/arraymethods.c
@@ -69,7 +69,10 @@ _reverse_shape(PyArray_Dims *newshape)
}
}
-static char doc_reshape[] = "a.reshape(d1, d2, ..., dn). Change the shape of a to be an n-dimensional array with dimensions given by d1...dn. Note: the size specified for the new array must be exactly equal to the size of the old one or an error will occur.";
+static char doc_reshape[] = \
+ "self.reshape(d1, d2, ..., dn) Return a new array from this one. \n" \
+ "\n The new array must have the same number of elements as self. "\
+ "Also\n a copy of the data only occurs if necessary.";
static PyObject *
array_reshape(PyArrayObject *self, PyObject *args)
@@ -463,9 +466,10 @@ array_copy(PyArrayObject *self, PyObject *args)
return _ARET(PyArray_Copy(self));
}
-static char doc_resize[] = "m.resize(new_shape). Return a resized version "\
- "of the array.\n\nMust own its own memory be single segment and not be referenced by "\
- "other arrays.";
+static char doc_resize[] = "self.resize(new_shape). "\
+ "Change size and shape of self inplace.\n"\
+ "\n Array must own its own memory and not be referenced by other " \
+ "arrays\n Returns None.";
static PyObject *
array_resize(PyArrayObject *self, PyObject *args)
@@ -490,7 +494,9 @@ array_resize(PyArrayObject *self, PyObject *args)
}
ret = PyArray_Resize(self, &newshape);
PyDimMem_FREE(newshape.ptr);
- return _ARET(ret);
+ Py_DECREF(ret);
+ Py_INCREF(Py_None);
+ return Py_None;
}
static char doc_repeat[] = "a.repeat(repeats=, axis=None)";
diff --git a/scipy/base/src/multiarraymodule.c b/scipy/base/src/multiarraymodule.c
index 10edf0631..7343abd1c 100644
--- a/scipy/base/src/multiarraymodule.c
+++ b/scipy/base/src/multiarraymodule.c
@@ -3910,6 +3910,13 @@ DL_EXPORT(void) initmultiarray(void) {
return;
PyArray_Type.tp_base = &PyBigArray_Type;
+
+ PyArray_Type.tp_as_mapping = &array_as_mapping;
+ /* Even though, this would be inherited, it needs to be set now
+ so that the __getitem__ will map to the as_mapping descriptor
+ */
+ PyArray_Type.tp_as_number = &array_as_number;
+ /* For good measure */
PyArray_Type.tp_as_sequence = &array_as_sequence;
PyArray_Type.tp_as_buffer = &array_as_buffer;
PyArray_Type.tp_flags = (Py_TPFLAGS_DEFAULT