Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

RF: fix for squeezing 0d scalars from ticket 1230 #252

Merged
merged 1 commit into from

2 participants

@matthew-brett
Collaborator

With test.

@rgommers rgommers merged commit 3199911 into from
@ClemensFMN ClemensFMN referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 10, 2012
  1. @matthew-brett
This page is out of date. Refresh to see the latest.
View
221 scipy/io/matlab/mio_utils.c
@@ -1,4 +1,4 @@
-/* Generated by Cython 0.15 on Tue Nov 1 18:18:44 2011 */
+/* Generated by Cython 0.15.1 on Sun Jun 10 11:32:23 2012 */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
@@ -266,7 +266,7 @@
# else
# define CYTHON_UNUSED
# endif
-# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
+# elif defined(__ICC) || defined(__INTEL_COMPILER)
# define CYTHON_UNUSED __attribute__ ((__unused__))
# else
# define CYTHON_UNUSED
@@ -728,6 +728,18 @@ static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); /*proto*/
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/
+#include <string.h>
+
+static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/
+
+static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/
+
+#if PY_MAJOR_VERSION >= 3
+#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals
+#else
+#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
+#endif
+
static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_Py_intptr_t(Py_intptr_t);
#if CYTHON_CCOMPLEX
@@ -926,6 +938,7 @@ static char __pyx_k__I[] = "I";
static char __pyx_k__L[] = "L";
static char __pyx_k__O[] = "O";
static char __pyx_k__Q[] = "Q";
+static char __pyx_k__V[] = "V";
static char __pyx_k__b[] = "b";
static char __pyx_k__d[] = "d";
static char __pyx_k__f[] = "f";
@@ -940,6 +953,7 @@ static char __pyx_k__Zg[] = "Zg";
static char __pyx_k__np[] = "np";
static char __pyx_k__str[] = "str";
static char __pyx_k__item[] = "item";
+static char __pyx_k__kind[] = "kind";
static char __pyx_k__size[] = "size";
static char __pyx_k__view[] = "view";
static char __pyx_k__array[] = "array";
@@ -951,7 +965,6 @@ static char __pyx_k__reshape[] = "reshape";
static char __pyx_k__squeeze[] = "squeeze";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
-static char __pyx_k__isbuiltin[] = "isbuiltin";
static char __pyx_k__ValueError[] = "ValueError";
static char __pyx_k__RuntimeError[] = "RuntimeError";
static char __pyx_k__ascontiguousarray[] = "ascontiguousarray";
@@ -962,14 +975,15 @@ static PyObject *__pyx_kp_u_5;
static PyObject *__pyx_kp_u_7;
static PyObject *__pyx_kp_u_9;
static PyObject *__pyx_n_s__RuntimeError;
+static PyObject *__pyx_n_s__V;
static PyObject *__pyx_n_s__ValueError;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s__array;
static PyObject *__pyx_n_s__ascontiguousarray;
static PyObject *__pyx_n_s__dtype;
-static PyObject *__pyx_n_s__isbuiltin;
static PyObject *__pyx_n_s__item;
+static PyObject *__pyx_n_s__kind;
static PyObject *__pyx_n_s__np;
static PyObject *__pyx_n_s__numpy;
static PyObject *__pyx_n_s__range;
@@ -1158,7 +1172,7 @@ static PyObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_squeeze_element(PyArrayOb
* if not arr.size:
* return np.array([]) # <<<<<<<<<<<<<<
* arr2 = np.squeeze(arr)
- * if (not arr2.shape) and arr2.dtype.isbuiltin: # 0d coverted to scalar
+ * # We want to squeeze 0d arrays, unless they are record arrays
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
@@ -1188,8 +1202,8 @@ static PyObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_squeeze_element(PyArrayOb
* if not arr.size:
* return np.array([])
* arr2 = np.squeeze(arr) # <<<<<<<<<<<<<<
- * if (not arr2.shape) and arr2.dtype.isbuiltin: # 0d coverted to scalar
- * return arr2.item()
+ * # We want to squeeze 0d arrays, unless they are record arrays
+ * if (not arr2.shape) and arr2.dtype.kind != 'V':
*/
__pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
@@ -1208,25 +1222,25 @@ static PyObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_squeeze_element(PyArrayOb
__pyx_v_arr2 = __pyx_t_4;
__pyx_t_4 = 0;
- /* "scipy/io/matlab/mio_utils.pyx":25
- * return np.array([])
+ /* "scipy/io/matlab/mio_utils.pyx":26
* arr2 = np.squeeze(arr)
- * if (not arr2.shape) and arr2.dtype.isbuiltin: # 0d coverted to scalar # <<<<<<<<<<<<<<
+ * # We want to squeeze 0d arrays, unless they are record arrays
+ * if (not arr2.shape) and arr2.dtype.kind != 'V': # <<<<<<<<<<<<<<
* return arr2.item()
* return arr2
*/
- __pyx_t_4 = PyObject_GetAttr(__pyx_v_arr2, __pyx_n_s__shape); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_v_arr2, __pyx_n_s__shape); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_2 = (!__pyx_t_3);
if (__pyx_t_2) {
- __pyx_t_4 = PyObject_GetAttr(__pyx_v_arr2, __pyx_n_s__dtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_v_arr2, __pyx_n_s__dtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__isbuiltin); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__kind); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PyString_Equals(__pyx_t_1, ((PyObject *)__pyx_n_s__V), Py_NE); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_6 = __pyx_t_3;
} else {
@@ -1234,17 +1248,17 @@ static PyObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_squeeze_element(PyArrayOb
}
if (__pyx_t_6) {
- /* "scipy/io/matlab/mio_utils.pyx":26
- * arr2 = np.squeeze(arr)
- * if (not arr2.shape) and arr2.dtype.isbuiltin: # 0d coverted to scalar
+ /* "scipy/io/matlab/mio_utils.pyx":27
+ * # We want to squeeze 0d arrays, unless they are record arrays
+ * if (not arr2.shape) and arr2.dtype.kind != 'V':
* return arr2.item() # <<<<<<<<<<<<<<
* return arr2
*
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyObject_GetAttr(__pyx_v_arr2, __pyx_n_s__item); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_v_arr2, __pyx_n_s__item); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_4;
@@ -1254,8 +1268,8 @@ static PyObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_squeeze_element(PyArrayOb
}
__pyx_L4:;
- /* "scipy/io/matlab/mio_utils.pyx":27
- * if (not arr2.shape) and arr2.dtype.isbuiltin: # 0d coverted to scalar
+ /* "scipy/io/matlab/mio_utils.pyx":28
+ * if (not arr2.shape) and arr2.dtype.kind != 'V':
* return arr2.item()
* return arr2 # <<<<<<<<<<<<<<
*
@@ -1320,7 +1334,7 @@ static PyObject *__pyx_pf_5scipy_2io_6matlab_9mio_utils_1squeeze_element(PyObjec
return __pyx_r;
}
-/* "scipy/io/matlab/mio_utils.pyx":30
+/* "scipy/io/matlab/mio_utils.pyx":31
*
*
* cpdef cnp.ndarray chars_to_strings(in_arr): # <<<<<<<<<<<<<<
@@ -1347,18 +1361,18 @@ static PyArrayObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_chars_to_strings(PyO
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("chars_to_strings");
- /* "scipy/io/matlab/mio_utils.pyx":44
+ /* "scipy/io/matlab/mio_utils.pyx":45
* ``arr``
* '''
* cdef cnp.ndarray arr = in_arr # <<<<<<<<<<<<<<
* cdef int ndim = arr.ndim
* cdef cnp.npy_intp *dims = arr.shape
*/
- if (!(likely(((__pyx_v_in_arr) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_in_arr, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(((__pyx_v_in_arr) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_in_arr, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_INCREF(__pyx_v_in_arr);
__pyx_v_arr = ((PyArrayObject *)__pyx_v_in_arr);
- /* "scipy/io/matlab/mio_utils.pyx":45
+ /* "scipy/io/matlab/mio_utils.pyx":46
* '''
* cdef cnp.ndarray arr = in_arr
* cdef int ndim = arr.ndim # <<<<<<<<<<<<<<
@@ -1367,7 +1381,7 @@ static PyArrayObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_chars_to_strings(PyO
*/
__pyx_v_ndim = __pyx_v_arr->nd;
- /* "scipy/io/matlab/mio_utils.pyx":46
+ /* "scipy/io/matlab/mio_utils.pyx":47
* cdef cnp.ndarray arr = in_arr
* cdef int ndim = arr.ndim
* cdef cnp.npy_intp *dims = arr.shape # <<<<<<<<<<<<<<
@@ -1376,7 +1390,7 @@ static PyArrayObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_chars_to_strings(PyO
*/
__pyx_v_dims = __pyx_v_arr->dimensions;
- /* "scipy/io/matlab/mio_utils.pyx":47
+ /* "scipy/io/matlab/mio_utils.pyx":48
* cdef int ndim = arr.ndim
* cdef cnp.npy_intp *dims = arr.shape
* cdef cnp.npy_intp last_dim = dims[ndim-1] # <<<<<<<<<<<<<<
@@ -1385,7 +1399,7 @@ static PyArrayObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_chars_to_strings(PyO
*/
__pyx_v_last_dim = (__pyx_v_dims[(__pyx_v_ndim - 1)]);
- /* "scipy/io/matlab/mio_utils.pyx":49
+ /* "scipy/io/matlab/mio_utils.pyx":50
* cdef cnp.npy_intp last_dim = dims[ndim-1]
* cdef object new_dt_str, out_shape
* if last_dim == 0: # deal with empty array case # <<<<<<<<<<<<<<
@@ -1395,22 +1409,22 @@ static PyArrayObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_chars_to_strings(PyO
__pyx_t_1 = (__pyx_v_last_dim == 0);
if (__pyx_t_1) {
- /* "scipy/io/matlab/mio_utils.pyx":51
+ /* "scipy/io/matlab/mio_utils.pyx":52
* if last_dim == 0: # deal with empty array case
* # Started with U1 - which is OK for us
* new_dt_str = arr.dtype.str # <<<<<<<<<<<<<<
* # So far we only know this is an empty array and that the last length is
* # 0. The other dimensions could be non-zero. We set the next to last
*/
- __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_arr), __pyx_n_s__dtype); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_arr), __pyx_n_s__dtype); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__str); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__str); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_new_dt_str = __pyx_t_3;
__pyx_t_3 = 0;
- /* "scipy/io/matlab/mio_utils.pyx":55
+ /* "scipy/io/matlab/mio_utils.pyx":56
* # 0. The other dimensions could be non-zero. We set the next to last
* # dimension to zero to signal emptiness
* if ndim == 2: # <<<<<<<<<<<<<<
@@ -1420,7 +1434,7 @@ static PyArrayObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_chars_to_strings(PyO
__pyx_t_1 = (__pyx_v_ndim == 2);
if (__pyx_t_1) {
- /* "scipy/io/matlab/mio_utils.pyx":56
+ /* "scipy/io/matlab/mio_utils.pyx":57
* # dimension to zero to signal emptiness
* if ndim == 2:
* out_shape = (0,) # <<<<<<<<<<<<<<
@@ -1433,19 +1447,19 @@ static PyArrayObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_chars_to_strings(PyO
}
/*else*/ {
- /* "scipy/io/matlab/mio_utils.pyx":58
+ /* "scipy/io/matlab/mio_utils.pyx":59
* out_shape = (0,)
* else:
* out_shape = in_arr.shape[:-2] + (0,) # <<<<<<<<<<<<<<
* else: # make new dtype string with N appended
* new_dt_str = arr.dtype.str[:-1] + str(last_dim)
*/
- __pyx_t_3 = PyObject_GetAttr(__pyx_v_in_arr, __pyx_n_s__shape); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_v_in_arr, __pyx_n_s__shape); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = __Pyx_PySequence_GetSlice(__pyx_t_3, 0, -2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PySequence_GetSlice(__pyx_t_3, 0, -2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyNumber_Add(__pyx_t_2, ((PyObject *)__pyx_k_tuple_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyNumber_Add(__pyx_t_2, ((PyObject *)__pyx_k_tuple_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_out_shape = __pyx_t_3;
@@ -1456,48 +1470,48 @@ static PyArrayObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_chars_to_strings(PyO
}
/*else*/ {
- /* "scipy/io/matlab/mio_utils.pyx":60
+ /* "scipy/io/matlab/mio_utils.pyx":61
* out_shape = in_arr.shape[:-2] + (0,)
* else: # make new dtype string with N appended
* new_dt_str = arr.dtype.str[:-1] + str(last_dim) # <<<<<<<<<<<<<<
* out_shape = in_arr.shape[:-1]
* # Copy to deal with F ordered arrays
*/
- __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_arr), __pyx_n_s__dtype); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_arr), __pyx_n_s__dtype); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__str); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__str); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_PySequence_GetSlice(__pyx_t_2, 0, -1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PySequence_GetSlice(__pyx_t_2, 0, -1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = __Pyx_PyInt_to_py_Py_intptr_t(__pyx_v_last_dim); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyInt_to_py_Py_intptr_t(__pyx_v_last_dim); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_4));
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
- __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_new_dt_str = __pyx_t_4;
__pyx_t_4 = 0;
- /* "scipy/io/matlab/mio_utils.pyx":61
+ /* "scipy/io/matlab/mio_utils.pyx":62
* else: # make new dtype string with N appended
* new_dt_str = arr.dtype.str[:-1] + str(last_dim)
* out_shape = in_arr.shape[:-1] # <<<<<<<<<<<<<<
* # Copy to deal with F ordered arrays
* arr = np.ascontiguousarray(arr)
*/
- __pyx_t_4 = PyObject_GetAttr(__pyx_v_in_arr, __pyx_n_s__shape); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_v_in_arr, __pyx_n_s__shape); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_2 = __Pyx_PySequence_GetSlice(__pyx_t_4, 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PySequence_GetSlice(__pyx_t_4, 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_v_out_shape = __pyx_t_2;
@@ -1505,72 +1519,72 @@ static PyArrayObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_chars_to_strings(PyO
}
__pyx_L3:;
- /* "scipy/io/matlab/mio_utils.pyx":63
+ /* "scipy/io/matlab/mio_utils.pyx":64
* out_shape = in_arr.shape[:-1]
* # Copy to deal with F ordered arrays
* arr = np.ascontiguousarray(arr) # <<<<<<<<<<<<<<
* arr = arr.view(new_dt_str)
* return arr.reshape(out_shape)
*/
- __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__ascontiguousarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__ascontiguousarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(((PyObject *)__pyx_v_arr));
PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_arr));
__Pyx_GIVEREF(((PyObject *)__pyx_v_arr));
- __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(((PyObject *)__pyx_v_arr));
__pyx_v_arr = ((PyArrayObject *)__pyx_t_3);
__pyx_t_3 = 0;
- /* "scipy/io/matlab/mio_utils.pyx":64
+ /* "scipy/io/matlab/mio_utils.pyx":65
* # Copy to deal with F ordered arrays
* arr = np.ascontiguousarray(arr)
* arr = arr.view(new_dt_str) # <<<<<<<<<<<<<<
* return arr.reshape(out_shape)
*/
- __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_arr), __pyx_n_s__view); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_arr), __pyx_n_s__view); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_new_dt_str);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_new_dt_str);
__Pyx_GIVEREF(__pyx_v_new_dt_str);
- __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
- if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(((PyObject *)__pyx_v_arr));
__pyx_v_arr = ((PyArrayObject *)__pyx_t_4);
__pyx_t_4 = 0;
- /* "scipy/io/matlab/mio_utils.pyx":65
+ /* "scipy/io/matlab/mio_utils.pyx":66
* arr = np.ascontiguousarray(arr)
* arr = arr.view(new_dt_str)
* return arr.reshape(out_shape) # <<<<<<<<<<<<<<
*/
__Pyx_XDECREF(((PyObject *)__pyx_r));
- __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_arr), __pyx_n_s__reshape); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_arr), __pyx_n_s__reshape); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_out_shape);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_out_shape);
__Pyx_GIVEREF(__pyx_v_out_shape);
- __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_r = ((PyArrayObject *)__pyx_t_3);
__pyx_t_3 = 0;
goto __pyx_L0;
@@ -1592,7 +1606,7 @@ static PyArrayObject *__pyx_f_5scipy_2io_6matlab_9mio_utils_chars_to_strings(PyO
return __pyx_r;
}
-/* "scipy/io/matlab/mio_utils.pyx":30
+/* "scipy/io/matlab/mio_utils.pyx":31
*
*
* cpdef cnp.ndarray chars_to_strings(in_arr): # <<<<<<<<<<<<<<
@@ -1612,7 +1626,7 @@ static PyObject *__pyx_pf_5scipy_2io_6matlab_9mio_utils_2chars_to_strings(PyObje
__Pyx_RefNannySetupContext("chars_to_strings");
__pyx_self = __pyx_self;
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = ((PyObject *)__pyx_f_5scipy_2io_6matlab_9mio_utils_chars_to_strings(__pyx_v_in_arr, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = ((PyObject *)__pyx_f_5scipy_2io_6matlab_9mio_utils_chars_to_strings(__pyx_v_in_arr, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
@@ -3595,14 +3609,15 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_kp_u_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 1, 0, 0},
{&__pyx_kp_u_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 1, 0, 0},
{&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1},
+ {&__pyx_n_s__V, __pyx_k__V, sizeof(__pyx_k__V), 0, 0, 1, 1},
{&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
{&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
{&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
{&__pyx_n_s__array, __pyx_k__array, sizeof(__pyx_k__array), 0, 0, 1, 1},
{&__pyx_n_s__ascontiguousarray, __pyx_k__ascontiguousarray, sizeof(__pyx_k__ascontiguousarray), 0, 0, 1, 1},
{&__pyx_n_s__dtype, __pyx_k__dtype, sizeof(__pyx_k__dtype), 0, 0, 1, 1},
- {&__pyx_n_s__isbuiltin, __pyx_k__isbuiltin, sizeof(__pyx_k__isbuiltin), 0, 0, 1, 1},
{&__pyx_n_s__item, __pyx_k__item, sizeof(__pyx_k__item), 0, 0, 1, 1},
+ {&__pyx_n_s__kind, __pyx_k__kind, sizeof(__pyx_k__kind), 0, 0, 1, 1},
{&__pyx_n_s__np, __pyx_k__np, sizeof(__pyx_k__np), 0, 0, 1, 1},
{&__pyx_n_s__numpy, __pyx_k__numpy, sizeof(__pyx_k__numpy), 0, 0, 1, 1},
{&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1},
@@ -3627,28 +3642,28 @@ static int __Pyx_InitCachedConstants(void) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_InitCachedConstants");
- /* "scipy/io/matlab/mio_utils.pyx":56
+ /* "scipy/io/matlab/mio_utils.pyx":57
* # dimension to zero to signal emptiness
* if ndim == 2:
* out_shape = (0,) # <<<<<<<<<<<<<<
* else:
* out_shape = in_arr.shape[:-2] + (0,)
*/
- __pyx_k_tuple_1 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_k_tuple_1 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_k_tuple_1));
__Pyx_INCREF(__pyx_int_0);
PyTuple_SET_ITEM(__pyx_k_tuple_1, 0, __pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
__Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_1));
- /* "scipy/io/matlab/mio_utils.pyx":58
+ /* "scipy/io/matlab/mio_utils.pyx":59
* out_shape = (0,)
* else:
* out_shape = in_arr.shape[:-2] + (0,) # <<<<<<<<<<<<<<
* else: # make new dtype string with N appended
* new_dt_str = arr.dtype.str[:-1] + str(last_dim)
*/
- __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_k_tuple_2));
__Pyx_INCREF(__pyx_int_0);
PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, __pyx_int_0);
@@ -4170,6 +4185,68 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) {
return module;
}
+static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
+ if (s1 == s2) { /* as done by PyObject_RichCompareBool(); also catches the (interned) empty string */
+ return (equals == Py_EQ);
+ } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
+ if (PyBytes_GET_SIZE(s1) != PyBytes_GET_SIZE(s2)) {
+ return (equals == Py_NE);
+ } else if (PyBytes_GET_SIZE(s1) == 1) {
+ if (equals == Py_EQ)
+ return (PyBytes_AS_STRING(s1)[0] == PyBytes_AS_STRING(s2)[0]);
+ else
+ return (PyBytes_AS_STRING(s1)[0] != PyBytes_AS_STRING(s2)[0]);
+ } else {
+ int result = memcmp(PyBytes_AS_STRING(s1), PyBytes_AS_STRING(s2), (size_t)PyBytes_GET_SIZE(s1));
+ return (equals == Py_EQ) ? (result == 0) : (result != 0);
+ }
+ } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
+ return (equals == Py_NE);
+ } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
+ return (equals == Py_NE);
+ } else {
+ int result;
+ PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
+ if (!py_result)
+ return -1;
+ result = __Pyx_PyObject_IsTrue(py_result);
+ Py_DECREF(py_result);
+ return result;
+ }
+}
+
+static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
+ if (s1 == s2) { /* as done by PyObject_RichCompareBool(); also catches the (interned) empty string */
+ return (equals == Py_EQ);
+ } else if (PyUnicode_CheckExact(s1) & PyUnicode_CheckExact(s2)) {
+ if (PyUnicode_GET_SIZE(s1) != PyUnicode_GET_SIZE(s2)) {
+ return (equals == Py_NE);
+ } else if (PyUnicode_GET_SIZE(s1) == 1) {
+ if (equals == Py_EQ)
+ return (PyUnicode_AS_UNICODE(s1)[0] == PyUnicode_AS_UNICODE(s2)[0]);
+ else
+ return (PyUnicode_AS_UNICODE(s1)[0] != PyUnicode_AS_UNICODE(s2)[0]);
+ } else {
+ int result = PyUnicode_Compare(s1, s2);
+ if ((result == -1) && unlikely(PyErr_Occurred()))
+ return -1;
+ return (equals == Py_EQ) ? (result == 0) : (result != 0);
+ }
+ } else if ((s1 == Py_None) & PyUnicode_CheckExact(s2)) {
+ return (equals == Py_NE);
+ } else if ((s2 == Py_None) & PyUnicode_CheckExact(s1)) {
+ return (equals == Py_NE);
+ } else {
+ int result;
+ PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
+ if (!py_result)
+ return -1;
+ result = __Pyx_PyObject_IsTrue(py_result);
+ Py_DECREF(py_result);
+ return result;
+ }
+}
+
static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_Py_intptr_t(Py_intptr_t val) {
const Py_intptr_t neg_one = (Py_intptr_t)-1, const_zero = (Py_intptr_t)0;
const int is_unsigned = const_zero < neg_one;
View
3  scipy/io/matlab/mio_utils.pyx
@@ -22,7 +22,8 @@ cpdef object squeeze_element(cnp.ndarray arr):
if not arr.size:
return np.array([])
arr2 = np.squeeze(arr)
- if (not arr2.shape) and arr2.dtype.isbuiltin: # 0d coverted to scalar
+ # We want to squeeze 0d arrays, unless they are record arrays
+ if (not arr2.shape) and arr2.dtype.kind != 'V':
return arr2.item()
return arr2
View
10 scipy/io/matlab/tests/test_mio.py
@@ -829,6 +829,16 @@ def test_mat_struct_squeeze():
)
+def test_scalar_squeeze():
+ stream = BytesIO()
+ in_d = {'scalar': [[0.1]], 'string': 'my name', 'st':{'one':1, 'two':2}}
+ savemat_future(stream, in_d)
+ out_d = loadmat(stream, squeeze_me=True)
+ assert_true(isinstance(out_d['scalar'], float))
+ assert_true(isinstance(out_d['string'], basestring))
+ assert_true(isinstance(out_d['st'], np.ndarray))
+
+
def test_str_round():
# from report by Angus McMorland on mailing list 3 May 2010
stream = BytesIO()
Something went wrong with that request. Please try again.