diff options
author | Travis Oliphant <oliphant@enthought.com> | 2005-09-20 05:40:52 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2005-09-20 05:40:52 +0000 |
commit | 182a8c3fc8a6d827c878b9749af668e41cc0257d (patch) | |
tree | 97172c9620eba0df4a28982688358f53c424df4f /scipy/base/src | |
parent | 70edf5c9acbc231c9ce9078942fe210d8888305a (diff) | |
download | numpy-182a8c3fc8a6d827c878b9749af668e41cc0257d.tar.gz |
Found problem with reshape.
Diffstat (limited to 'scipy/base/src')
-rw-r--r-- | scipy/base/src/arrayobject.c | 3 | ||||
-rw-r--r-- | scipy/base/src/multiarraymodule.c | 8 | ||||
-rw-r--r-- | scipy/base/src/scalartypes.inc.src | 92 |
3 files changed, 70 insertions, 33 deletions
diff --git a/scipy/base/src/arrayobject.c b/scipy/base/src/arrayobject.c index edb875439..368c04f62 100644 --- a/scipy/base/src/arrayobject.c +++ b/scipy/base/src/arrayobject.c @@ -3525,7 +3525,7 @@ array_shape_set(PyArrayObject *self, PyObject *val) ret = PyArray_Reshape(self, val); if (ret == NULL) return -1; - if (self->nd > 0) { /* Free dimensions and strides */ + if (self->nd > 0) { /* Free old dimensions and strides */ PyDimMem_FREE(self->dimensions); } nd = PyArray_NDIM(ret); @@ -3543,6 +3543,7 @@ array_shape_set(PyArrayObject *self, PyObject *val) memcpy(self->strides, PyArray_STRIDES(ret), nd*sizeof(intp)); } + else self->dimensions=NULL; Py_DECREF(ret); return 0; } diff --git a/scipy/base/src/multiarraymodule.c b/scipy/base/src/multiarraymodule.c index 6bf8fc53c..19e3f0a61 100644 --- a/scipy/base/src/multiarraymodule.c +++ b/scipy/base/src/multiarraymodule.c @@ -3718,9 +3718,6 @@ PyArray_Where(PyObject *condition, PyObject *x, PyObject *y) return ret; } - - - zero = PyInt_FromLong((long) 0); obj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, n_ops.not_equal)); @@ -3853,10 +3850,9 @@ setup_scalartypes(PyObject *dict) "Could not initialize Py%sArrType_Type", \ #child); \ return -1; \ - } \ - Py##child##ArrType_Type.tp_new = Py##parent1##_Type.tp_new; + } - DUAL_INHERIT(Bool, Bool, Generic); + SINGLE_INHERIT(Bool, Generic); SINGLE_INHERIT(Byte, SignedInteger); SINGLE_INHERIT(Short, SignedInteger); #if SIZEOF_INT == SIZEOF_LONG diff --git a/scipy/base/src/scalartypes.inc.src b/scipy/base/src/scalartypes.inc.src index 280bf3b39..b7ac8c4a7 100644 --- a/scipy/base/src/scalartypes.inc.src +++ b/scipy/base/src/scalartypes.inc.src @@ -3,7 +3,7 @@ /**begin repeat #name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,# -#type=int, signed char, short, int, long, longlong, unsigned char, unsigned short, unsigned int, unsigned long, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, PyObject *,char# +#type=bool, signed char, short, int, long, longlong, unsigned char, unsigned short, unsigned int, unsigned long, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, PyObject *,char# */ typedef struct { PyObject_HEAD; @@ -361,6 +361,7 @@ gentype_str(PyObject *self) PyObject *ret; arr = (PyArrayObject *)PyArray_FromScalar(self, NULL); + if (arr==NULL) return NULL; ret = PyObject_Str(arr->descr->getitem(arr->data, arr)); Py_DECREF(arr); return ret; @@ -373,6 +374,7 @@ gentype_repr(PyObject *self) PyObject *ret; arr = (PyArrayObject *)PyArray_FromScalar(self, NULL); + if (arr==NULL) return NULL; ret = PyObject_Repr(arr->descr->getitem(arr->data, arr)); Py_DECREF(arr); return ret; @@ -1158,18 +1160,28 @@ object_arrtype_dealloc(PyObject *v) } - - /**begin repeat -#name=byte, short, longlong, ubyte, ushort, uint, ulong, ulonglong, float, longdouble, cfloat, clongdouble, void, object# -#TYPE=BYTE, SHORT, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, LONGDOUBLE, CFLOAT, CLONGDOUBLE, VOID, OBJECT# +#name=byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, object# +#TYPE=BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, STRING, UNICODE, OBJECT# */ static PyObject * @name@_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *obj=NULL; PyObject *arr; - PyArray_Typecode typecode; + PyArray_Typecode typecode = {PyArray_NOTYPE, 0, 0}; + + if (type->tp_bases && (PyTuple_GET_SIZE(type->tp_bases)==2)) { + PyTypeObject *sup; + PyObject *ret; + /* We are inheriting from a Python type as well so + give it first dibs on conversion */ + sup = (PyTypeObject *)PyTuple_GET_ITEM(type->tp_bases, 1); + ret = sup->tp_new(type, args, kwds); + if (ret) return ret; + PyErr_Clear(); + /* now do default conversion */ + } if (!PyArg_ParseTuple(args, "O", &obj)) return NULL; @@ -1179,25 +1191,67 @@ static PyObject * } /**end repeat**/ - -#if SIZEOF_INT != SIZEOF_LONG +/* bool->tp_new only return Py_True or Py_False */ static PyObject * -int_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +bool_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *obj=NULL; PyObject *arr; - PyArray_Typecode typecode; + PyArray_Typecode typecode = {PyArray_BOOL, 0, 0}; if (!PyArg_ParseTuple(args, "O", &obj)) return NULL; - typecode.type_num = PyArray_INT; arr = PyArray_FromAny(obj, &typecode, 0, 0, FORCECAST); return PyArray_Return((PyArrayObject *)arr); } -#endif +static PyObject * +void_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *obj, *arr; + ulonglong memu=1; + PyObject *new=NULL; + PyArray_Typecode typecode = {PyArray_VOID, 0, 0}; + char *destptr; + if (!PyArg_ParseTuple(args, "O", &obj)) return NULL; + /* For a VOID scalar first see if obj is an integer or long + and create new memory of that size (filled with 0) for the scalar + */ + if (PyLong_Check(obj) || PyInt_Check(obj) || \ + PyArray_IsScalar(obj, Integer) || + (PyArray_Check(obj) && PyArray_NDIM(obj)==0 && \ + PyArray_ISINTEGER(obj))) { + new = obj->ob_type->tp_as_number->nb_long(obj); + } + if (new && PyLong_Check(new)) { + PyObject *ret; + memu = PyLong_AsUnsignedLongLong(new); + Py_DECREF(new); + if (PyErr_Occurred() || (memu > MAX_INT)) { + PyErr_Clear(); + PyErr_Format(PyExc_OverflowError, + "size must be smaller than %d", + (int) MAX_INT); + return NULL; + } + destptr = PyDataMem_NEW((int) memu); + if (destptr == NULL) return PyErr_NoMemory(); + ret = type->tp_alloc(type, 0); + if (ret == NULL) { + PyDataMem_FREE(destptr); + return PyErr_NoMemory(); + } + ((PyVoidScalarObject *)ret)->obval = destptr; + ((PyVoidScalarObject *)ret)->ob_size = (int) memu; + memset(destptr, '\0', (size_t) memu); + return ret; + } + + arr = PyArray_FromAny(obj, &typecode, 0, 0, FORCECAST); + return PyArray_Return((PyArrayObject *)arr); +} /**begin repeat #name=bool, string, unicode, void, object# @@ -1258,23 +1312,9 @@ ComplexFloating, Flexible, Character# #NAME=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, String, Unicode, Void, Object# */ Py@NAME@ArrType_Type.tp_flags = LEAFFLAGS; - /**end repeat**/ - - - /* use default subtype new for types that inherit */ - - /**begin repeat -#name=byte, short, longlong, ubyte, ushort, uint, ulong, ulonglong, float, longdouble, cfloat, clongdouble, void, object# -#NAME=Byte, Short, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, LongDouble, CFloat, CLongDouble, Void, Object# - */ Py@NAME@ArrType_Type.tp_new = @name@_arrtype_new; /**end repeat**/ - /* only define this if INT will not inherit from Python integer */ -#if SIZEOF_INT != SIZEOF_LONG - PyIntArrType_Type.tp_new = int_arrtype_new; -#endif - /* These need to be coded specially because getitem does not return a normal Python type */ |