Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb0ceff

Browse files
committed
Fixes by Eric Firing..
1 parent 0e1c0c0 commit fb0ceff

8 files changed

Lines changed: 46 additions & 23 deletions

File tree

THANKS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Fernando Perez for code snippets and ideas
88
John Hunter for code snippets (from matplotlib)
99
Chris Hanley for help with records.py, testing, and bug fixes.
1010
Travis Vaught and Joe Cooper for administration of scipy.org web site and SVN
11+
Eric Firing for bugfixes.

scipy/base/function_base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,31 +553,31 @@ def nanmin(x,axis=-1):
553553
"""
554554
y = array(x)
555555
if not issubclass(y.dtype, _nx.integer):
556-
y[isnan(x)] = nx.inf
556+
y[isnan(x)] = _nx.inf
557557
return y.min(axis)
558558

559559
def nanargmin(x,axis=-1):
560560
"""Find the indices of the minimium over the given axis ignoring nans.
561561
"""
562562
y = array(x)
563563
if not issubclass(y.dtype, _nx.integer):
564-
y[isnan(x)] = nx.inf
564+
y[isnan(x)] = _nx.inf
565565
return y.argmin(axis)
566566

567567
def nanmax(x,axis=-1):
568568
"""Find the maximum over the given axis ignoring nans.
569569
"""
570570
y = array(x)
571571
if not issubclass(y.dtype, _nx.integer):
572-
y[isnan(x)] = -nx.inf
572+
y[isnan(x)] = -_nx.inf
573573
return y.max(axis)
574574

575575
def nanargmax(x,axis=-1):
576576
"""Find the maximum over the given axis ignoring nans.
577577
"""
578578
y = array(x)
579579
if not issubclass(y.dtype, _nx.integer):
580-
y[isnan(x)] = -nx.inf
580+
y[isnan(x)] = -_nx.inf
581581
return y.argmax(axis)
582582

583583
def disp(mesg, device=None, linefeed=1):

scipy/base/matrix.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import numeric as N
33
from numeric import ArrayType, concatenate, integer
4+
from type_check import isscalar
45
from function_base import binary_repr
56
import types
67
import string as str_
@@ -103,20 +104,24 @@ def _update_meta(self, obj):
103104
return
104105

105106
def __getitem__(self, index):
106-
out = (self.A)[index]
107-
# Need to swap if slice is on first index
107+
out = N.ndarray.__getitem__(self, index)
108+
# Need to swap if slice is on first inde
109+
retscal = False
108110
try:
109111
n = len(index)
110-
if (n > 1) and isinstance(index[0], types.SliceType):
111-
if (isinstance(index[1], types.IntType) or
112-
isinstance(index[1], types.LongType) or
113-
isinstance(index[1], integer)):
114-
sh = out.shape
115-
out.shape = (sh[1], sh[0])
116-
return matrix(out)
117-
return out
112+
if (n==2):
113+
if isinstance(index[0], types.SliceType):
114+
if (isscalar(index[1])):
115+
sh = out.shape
116+
out.shape = (sh[1], sh[0])
117+
else:
118+
if (isscalar(index[0])) and (isscalar(index[1])):
119+
retscal = True
118120
except TypeError:
119-
return matrix(out)
121+
pass
122+
if retscal and out.shape == (1,1): # convert scalars
123+
return out.A[0,0]
124+
return out
120125

121126
def __mul__(self, other):
122127
if isinstance(other, N.ndarray) and other.ndim == 0:

scipy/base/numeric.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def convolve(a,v,mode='full'):
9898
return correlate(a,asarray(v)[::-1],mode)
9999

100100
ndarray = multiarray.ndarray
101+
ndbigarray = multiarray.ndbigarray
101102
ufunc = type(sin)
102103

103104
inner = multiarray.inner

scipy/base/numerictypes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ def __getitem__(self, obj):
333333
return dict.__getitem__(self, obj2dtype(obj))
334334

335335
cast = _castdict()
336-
ScalarType = [_types.IntType, _types.LongType, _types.FloatType,
337-
_types.StringType, _types.UnicodeType, _types.ComplexType,
338-
_types.BufferType]
336+
ScalarType = [_types.IntType, _types.FloatType,
337+
_types.ComplexType, _types.LongType, _types.BooleanType,
338+
_types.StringType, _types.UnicodeType, _types.BufferType]
339339
ScalarType.extend(_dtype2char_dict.keys())
340340
for key in _dtype2char_dict.keys():
341341
cast[key] = lambda x, k=key : array(x,copy=0).astype(k)

scipy/base/oldnumeric.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ def resize(a, new_shape):
188188
"""resize(a,new_shape) returns a new array with the specified shape.
189189
The original array's total size can be any size. It
190190
fills the new array with repeated copies of a.
191+
192+
Note that a.resize(new_shape) will fill array with 0's
193+
beyond current definition of a.
191194
"""
192195

193196
a = ravel(a)

scipy/base/src/arraymethods.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ _reverse_shape(PyArray_Dims *newshape)
6969
}
7070
}
7171

72-
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.";
72+
static char doc_reshape[] = \
73+
"self.reshape(d1, d2, ..., dn) Return a new array from this one. \n" \
74+
"\n The new array must have the same number of elements as self. "\
75+
"Also\n a copy of the data only occurs if necessary.";
7376

7477
static PyObject *
7578
array_reshape(PyArrayObject *self, PyObject *args)
@@ -463,9 +466,10 @@ array_copy(PyArrayObject *self, PyObject *args)
463466
return _ARET(PyArray_Copy(self));
464467
}
465468

466-
static char doc_resize[] = "m.resize(new_shape). Return a resized version "\
467-
"of the array.\n\nMust own its own memory be single segment and not be referenced by "\
468-
"other arrays.";
469+
static char doc_resize[] = "self.resize(new_shape). "\
470+
"Change size and shape of self inplace.\n"\
471+
"\n Array must own its own memory and not be referenced by other " \
472+
"arrays\n Returns None.";
469473

470474
static PyObject *
471475
array_resize(PyArrayObject *self, PyObject *args)
@@ -490,7 +494,9 @@ array_resize(PyArrayObject *self, PyObject *args)
490494
}
491495
ret = PyArray_Resize(self, &newshape);
492496
PyDimMem_FREE(newshape.ptr);
493-
return _ARET(ret);
497+
Py_DECREF(ret);
498+
Py_INCREF(Py_None);
499+
return Py_None;
494500
}
495501

496502
static char doc_repeat[] = "a.repeat(repeats=, axis=None)";

scipy/base/src/multiarraymodule.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,6 +3910,13 @@ DL_EXPORT(void) initmultiarray(void) {
39103910
return;
39113911

39123912
PyArray_Type.tp_base = &PyBigArray_Type;
3913+
3914+
PyArray_Type.tp_as_mapping = &array_as_mapping;
3915+
/* Even though, this would be inherited, it needs to be set now
3916+
so that the __getitem__ will map to the as_mapping descriptor
3917+
*/
3918+
PyArray_Type.tp_as_number = &array_as_number;
3919+
/* For good measure */
39133920
PyArray_Type.tp_as_sequence = &array_as_sequence;
39143921
PyArray_Type.tp_as_buffer = &array_as_buffer;
39153922
PyArray_Type.tp_flags = (Py_TPFLAGS_DEFAULT

0 commit comments

Comments
 (0)