summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2005-09-26 21:11:11 +0000
committerTravis Oliphant <oliphant@enthought.com>2005-09-26 21:11:11 +0000
commit306fc5d6e715f51a3a568a34dccd39c44af757fe (patch)
tree6ce38d8eb9b63725ef355889f7e05fe37ad02a40
parent64c9050515e3cfa7ad095299f9648ebc5530a823 (diff)
downloadnumpy-306fc5d6e715f51a3a568a34dccd39c44af757fe.tar.gz
Fixed nasty shape setting bug.
-rw-r--r--scipy/base/src/arrayobject.c2
-rw-r--r--scipy/base/src/multiarraymodule.c21
-rw-r--r--scipy/stats/random_lite.py13
3 files changed, 19 insertions, 17 deletions
diff --git a/scipy/base/src/arrayobject.c b/scipy/base/src/arrayobject.c
index 9490961fc..2ee6197a1 100644
--- a/scipy/base/src/arrayobject.c
+++ b/scipy/base/src/arrayobject.c
@@ -771,7 +771,7 @@ PyArray_FromDims(int nd, int *d, int type)
for (i=0; i<nd; i++) newd[i] = (intp) d[i];
return PyArray_New(&PyArray_Type, nd, newd, type,
- NULL, NULL, 0, 0, NULL);
+ NULL, NULL, 0, CARRAY_FLAGS, NULL);
}
/* end */
diff --git a/scipy/base/src/multiarraymodule.c b/scipy/base/src/multiarraymodule.c
index b887c1130..dda737722 100644
--- a/scipy/base/src/multiarraymodule.c
+++ b/scipy/base/src/multiarraymodule.c
@@ -88,7 +88,11 @@ PyArray_View(PyArrayObject *self, PyArray_Typecode *type)
{
PyObject *new=NULL;
PyObject *v=NULL;
- int type_num = type->type_num;
+ int type_num = PyArray_NOTYPE;
+
+ if (type) {
+ type_num = type->type_num;
+ }
new = PyArray_New(self->ob_type,
self->nd, self->dimensions,
@@ -200,6 +204,10 @@ PyArray_Reshape(PyArrayObject *self, PyObject *shape)
return ret;
}
+/* Returns a new array
+ with the a new shape from the data
+ in the old array
+*/
static PyObject *
PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims)
@@ -220,10 +228,7 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims)
same=false;
i++;
}
- if (same) {
- Py_INCREF(self);
- return (PyObject *)self;
- }
+ if (same) return PyArray_View(self, NULL);
}
if (!PyArray_ISCONTIGUOUS(self)) {
@@ -1100,6 +1105,7 @@ PyArray_Concatenate(PyObject *op, int axis)
char *data;
PyTypeObject *subtype;
double prior1, prior2;
+ intp numbytes;
n = PySequence_Length(op);
if (n == -1) {
@@ -1201,8 +1207,9 @@ PyArray_Concatenate(PyObject *op, int axis)
data = ret->data;
for(i=0; i<n; i++) {
- memcpy(data, mps[i]->data, PyArray_NBYTES(mps[i]));
- data += PyArray_NBYTES(mps[i]);
+ numbytes = PyArray_NBYTES(mps[i]);
+ memcpy(data, mps[i]->data, numbytes);
+ data += numbytes;
}
PyArray_INCREF(ret);
diff --git a/scipy/stats/random_lite.py b/scipy/stats/random_lite.py
index 9b0e49d2a..3e6c12705 100644
--- a/scipy/stats/random_lite.py
+++ b/scipy/stats/random_lite.py
@@ -41,15 +41,10 @@ def _build_random_array(fun, args, shape=[]):
# Allows an integer shape n as a shorthand for (n,).
if isinstance(shape, IntType):
shape = [shape]
- if len(shape) != 0:
- n = Numeric.multiply.reduce(shape)
- s = apply(fun, args + (n,))
- s.shape = shape
- return s
- else:
- n = 1
- s = apply(fun, args + (n,))
- return s[0]
+ n = Numeric.multiply.reduce(shape)
+ s = apply(fun, args + (n,))
+ print s.shape
+ return s.reshape(shape)
def random(shape=[]):
"random(n) or random([n, m, ...]) returns array of random numbers"