Skip to content

Commit

Permalink
Fix Ticket numpy#352
Browse files Browse the repository at this point in the history
  • Loading branch information
teoliphant committed Oct 18, 2006
1 parent ed7b368 commit 2e7c822
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
3 changes: 2 additions & 1 deletion THANKS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ Francesc Altet for unicode and nested record tests
and much help with rooting out nested record array bugs.
Tim Hochberg for getting the build working on MSVC, optimization
improvements, and code review
Charles Harris for the sorting code originally written for Numarray and for improvements to polyfit, many bug fixes, and documentation strings.
Charles Harris for the sorting code originally written for Numarray and
for improvements to polyfit, many bug fixes, and documentation strings.
39 changes: 21 additions & 18 deletions numpy/core/src/arrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4749,41 +4749,44 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
static PyObject *
_check_axis(PyArrayObject *arr, int *axis, int flags)
{
PyObject *temp;
PyObject *temp1, *temp2;
int n = arr->nd;

if ((*axis >= MAX_DIMS) || (n==0)) {
if (n != 1) {
temp = PyArray_Ravel(arr,0);
if (temp) *axis = PyArray_NDIM(temp)-1;
else *axis = 0;
temp1 = PyArray_Ravel(arr,0);
if (temp1 == NULL) {*axis=0; return NULL;}
*axis = PyArray_NDIM(temp1)-1;
}
else {
temp = (PyObject *)arr;
Py_INCREF(temp);
temp1 = (PyObject *)arr;
Py_INCREF(temp1);
*axis = 0;
}
return temp;
if (!flags) return temp1;
}
else {
if (flags) {
temp = PyArray_CheckFromAny((PyObject *)arr, NULL,
0, 0, flags, NULL);
if (temp == NULL) return NULL;
}
else {
Py_INCREF(arr);
temp = (PyObject *)arr;
}
temp1 = (PyObject *)arr;
Py_INCREF(temp1);
}
if (flags) {
temp2 = PyArray_CheckFromAny((PyObject *)temp1, NULL,
0, 0, flags, NULL);
Py_DECREF(temp1);
if (temp2 == NULL) return NULL;
}
else {
temp2 = (PyObject *)temp1;
}
n = PyArray_NDIM(temp2);
if (*axis < 0) *axis += n;
if ((*axis < 0) || (*axis >= n)) {
PyErr_Format(PyExc_ValueError,
"axis(=%d) out of bounds", *axis);
Py_DECREF(temp);
Py_DECREF(temp2);
return NULL;
}
return temp;
return temp2;
}

#include "arraymethods.c"
Expand Down
6 changes: 6 additions & 0 deletions numpy/core/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,12 @@ def check_reshape_order(self, level=rlevel):
a = N.array([[1,2],[3,4],[5,6],[7,8]])
b = a[:,1]
assert_equal(b.reshape(2,2,order='F'), [[2,6],[4,8]])

def check_repeat_discont(self, level=rlevel):
"""Ticket #352"""
a = N.arange(12).reshape(4,3)[:,2]
assert_equal(a.repeat(3), [2,2,2,5,5,5,8,8,8,11,11,11])


if __name__ == "__main__":
NumpyTest().run()

0 comments on commit 2e7c822

Please sign in to comment.