summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/convert_datatype.c13
-rw-r--r--numpy/core/src/multiarray/getset.c19
-rw-r--r--numpy/core/src/multiarray/methods.c17
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c14
-rw-r--r--numpy/ma/core.py4
5 files changed, 32 insertions, 35 deletions
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c
index c22e6a0b7..6cd4e7a79 100644
--- a/numpy/core/src/multiarray/convert_datatype.c
+++ b/numpy/core/src/multiarray/convert_datatype.c
@@ -22,6 +22,9 @@
*
* Cast an array using typecode structure.
* steals reference to at --- cannot be NULL
+ *
+ * This function always makes a copy of mp, even if the dtype
+ * doesn't change.
*/
NPY_NO_EXPORT PyObject *
PyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)
@@ -32,16 +35,6 @@ PyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)
mpd = mp->descr;
- if (((mpd == at) ||
- ((mpd->type_num == at->type_num) &&
- PyArray_EquivByteorders(mpd->byteorder, at->byteorder) &&
- ((mpd->elsize == at->elsize) || (at->elsize==0)))) &&
- PyArray_ISBEHAVED_RO(mp)) {
- Py_DECREF(at);
- Py_INCREF(mp);
- return (PyObject *)mp;
- }
-
if (at->elsize == 0) {
PyArray_DESCR_REPLACE(at);
if (at == NULL) {
diff --git a/numpy/core/src/multiarray/getset.c b/numpy/core/src/multiarray/getset.c
index a636383a6..8367329d1 100644
--- a/numpy/core/src/multiarray/getset.c
+++ b/numpy/core/src/multiarray/getset.c
@@ -418,10 +418,21 @@ array_descr_set(PyArrayObject *self, PyObject *arg)
}
if (newtype->elsize == 0) {
- PyErr_SetString(PyExc_TypeError,
- "data-type must not be 0-sized");
- Py_DECREF(newtype);
- return -1;
+ /* Allow a void view */
+ if (newtype->type_num == NPY_VOID) {
+ PyArray_DESCR_REPLACE(newtype);
+ if (newtype == NULL) {
+ return -1;
+ }
+ newtype->elsize = self->descr->elsize;
+ }
+ /* But no other flexible types */
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "data-type must not be 0-sized");
+ Py_DECREF(newtype);
+ return -1;
+ }
}
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c
index e2ccb3f80..28b57c8ce 100644
--- a/numpy/core/src/multiarray/methods.c
+++ b/numpy/core/src/multiarray/methods.c
@@ -770,7 +770,7 @@ array_setasflat(PyArrayObject *self, PyObject *args)
}
static PyObject *
-array_cast(PyArrayObject *self, PyObject *args)
+array_astype(PyArrayObject *self, PyObject *args)
{
PyArray_Descr *descr = NULL;
PyObject *obj;
@@ -781,19 +781,6 @@ array_cast(PyArrayObject *self, PyObject *args)
return NULL;
}
- if (PyArray_EquivTypes(descr, self->descr)) {
- obj = _ARET(PyArray_NewCopy(self,NPY_ANYORDER));
- Py_XDECREF(descr);
- return obj;
- }
- if (descr->names != NULL) {
- int flags;
- flags = NPY_FORCECAST;
- if (PyArray_ISFORTRAN(self)) {
- flags |= NPY_FORTRAN;
- }
- return PyArray_FromArray(self, descr, flags);
- }
return PyArray_CastToType(self, descr, PyArray_ISFORTRAN(self));
}
@@ -2205,7 +2192,7 @@ NPY_NO_EXPORT PyMethodDef array_methods[] = {
(PyCFunction)array_argsort,
METH_VARARGS | METH_KEYWORDS, NULL},
{"astype",
- (PyCFunction)array_cast,
+ (PyCFunction)array_astype,
METH_VARARGS, NULL},
{"byteswap",
(PyCFunction)array_byteswap,
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index 2d1a75423..96118acaf 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -1410,10 +1410,16 @@ _equivalent_subarrays(PyArray_ArrayDescr *sub1, PyArray_ArrayDescr *sub2)
NPY_NO_EXPORT unsigned char
PyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)
{
- int typenum1 = typ1->type_num;
- int typenum2 = typ2->type_num;
- int size1 = typ1->elsize;
- int size2 = typ2->elsize;
+ int typenum1, typenum2, size1, size2;
+
+ if (typ1 == typ2) {
+ return TRUE;
+ }
+
+ typenum1 = typ1->type_num;
+ typenum2 = typ2->type_num;
+ size1 = typ1->elsize;
+ size2 = typ2->elsize;
if (size1 != size2) {
return FALSE;
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 6873bef6c..98100621e 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -5552,8 +5552,8 @@ class mvoid(MaskedArray):
def __getitem__(self, indx):
"Get the index..."
- _mask = self._mask.astype(np.void)
- if _mask is not nomask and _mask[indx]:
+ m = self._mask
+ if m is not nomask and m[indx]:
return masked
return self._data[indx]