Skip to content

Commit

Permalink
Fixes by Eric Firing..
Browse files Browse the repository at this point in the history
  • Loading branch information
teoliphant committed Oct 2, 2005
1 parent 0e1c0c0 commit fb0ceff
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 23 deletions.
1 change: 1 addition & 0 deletions THANKS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 4 additions & 4 deletions scipy/base/function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,31 +553,31 @@ 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):
"""Find the indices of the minimium over the given axis ignoring nans.
"""
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):
"""Find the maximum over the given axis ignoring nans.
"""
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):
"""Find the maximum over the given axis ignoring nans.
"""
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):
Expand Down
27 changes: 16 additions & 11 deletions scipy/base/matrix.py
Original file line number Diff line number Diff line change
@@ -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_
Expand Down Expand Up @@ -103,20 +104,24 @@ def _update_meta(self, obj):
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:
Expand Down
1 change: 1 addition & 0 deletions scipy/base/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions scipy/base/numerictypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ def __getitem__(self, obj):
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)
Expand Down
3 changes: 3 additions & 0 deletions scipy/base/oldnumeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 11 additions & 5 deletions scipy/base/src/arraymethods.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)";
Expand Down
7 changes: 7 additions & 0 deletions scipy/base/src/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fb0ceff

Please sign in to comment.