summaryrefslogtreecommitdiff
path: root/numpy/numarray/_capi.c
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-08-24 22:50:26 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-08-24 22:50:26 +0000
commit960e67401202793e22f27742fe6ef8b7b1e38433 (patch)
tree1e8e61d09102c409a665333e31d6e4fde701d6a5 /numpy/numarray/_capi.c
parent63b2e7394465c5d165821f5188b87b7740dc978c (diff)
downloadnumpy-960e67401202793e22f27742fe6ef8b7b1e38433.tar.gz
Fix NA_NewAllFromBuffer when shape is given
Diffstat (limited to 'numpy/numarray/_capi.c')
-rw-r--r--numpy/numarray/_capi.c51
1 files changed, 30 insertions, 21 deletions
diff --git a/numpy/numarray/_capi.c b/numpy/numarray/_capi.c
index f28e90fc0..f99e88bf1 100644
--- a/numpy/numarray/_capi.c
+++ b/numpy/numarray/_capi.c
@@ -2738,40 +2738,49 @@ NA_NewAllFromBuffer(int ndim, maybelong *shape, NumarrayType type,
int byteorder, int aligned, int writeable)
{
PyArrayObject *self = NULL;
- PyArray_Descr *dtype;
+ PyArray_Descr *dtype;
if (type == tAny)
type = tDefault;
- dtype = PyArray_DescrFromType(type);
- if (dtype == NULL) return NULL;
+ dtype = PyArray_DescrFromType(type);
+ if (dtype == NULL) return NULL;
- if (byteorder != NA_ByteOrder()) {
- PyArray_Descr *temp;
- temp = PyArray_DescrNewByteorder(dtype, PyArray_SWAP);
- Py_DECREF(dtype);
- if (temp == NULL) return NULL;
- dtype = temp;
- }
+ if (byteorder != NA_ByteOrder()) {
+ PyArray_Descr *temp;
+ temp = PyArray_DescrNewByteorder(dtype, PyArray_SWAP);
+ Py_DECREF(dtype);
+ if (temp == NULL) return NULL;
+ dtype = temp;
+ }
- if (bufferObject == Py_None || bufferObject == NULL) {
- self = (PyArrayObject *) \
+ if (bufferObject == Py_None || bufferObject == NULL) {
+ self = (PyArrayObject *) \
PyArray_NewFromDescr(&PyArray_Type, dtype,
ndim, shape, NULL, NULL,
0, NULL);
- }
- else {
- npy_intp size = dtype->elsize;
- int i;
- for(i=0; i<self->nd; i++) {
- size *= self->dimensions[i];
+ }
+ else {
+ npy_intp size = 1;
+ int i;
+ PyArrayObject *newself;
+ PyArray_Dims newdims;
+ for(i=0; i<ndim; i++) {
+ size *= shape[i];
}
- self = (PyArrayObject *)\
+ self = (PyArrayObject *)\
PyArray_FromBuffer(bufferObject, dtype,
size, byteoffset);
- }
+
+ if (self == NULL) return self;
+ newdims.len = ndim;
+ newdims.ptr = shape;
+ newself = PyArray_Newshape(self, &newdims, PyArray_CORDER);
+ Py_DECREF(self);
+ self = newself;
+ }
- return self;
+ return self;
}
static void