"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "numpy/core/src/multiarray/convert_datatype.c" between
numpy-1.21.0.tar.gz and numpy-1.21.1.tar.gz

About: NumPy is the fundamental package for scientific computing with Python.

convert_datatype.c  (numpy-1.21.0):convert_datatype.c  (numpy-1.21.1)
skipping to change at line 449 skipping to change at line 449
* (I.e. if `object_arr.astype("S")` did _not_ inspect the objects, and the * (I.e. if `object_arr.astype("S")` did _not_ inspect the objects, and the
* user would have to guess the string length.) * user would have to guess the string length.)
* *
* @param casting the requested casting safety. * @param casting the requested casting safety.
* @param from * @param from
* @param to The descriptor to cast to (may be NULL) * @param to The descriptor to cast to (may be NULL)
* @param to_dtype If `to` is NULL, must pass the to_dtype (otherwise this * @param to_dtype If `to` is NULL, must pass the to_dtype (otherwise this
* is ignored). * is ignored).
* @return 0 for an invalid cast, 1 for a valid and -1 for an error. * @return 0 for an invalid cast, 1 for a valid and -1 for an error.
*/ */
static int NPY_NO_EXPORT int
PyArray_CheckCastSafety(NPY_CASTING casting, PyArray_CheckCastSafety(NPY_CASTING casting,
PyArray_Descr *from, PyArray_Descr *to, PyArray_DTypeMeta *to_dtype) PyArray_Descr *from, PyArray_Descr *to, PyArray_DTypeMeta *to_dtype)
{ {
if (to != NULL) { if (to != NULL) {
to_dtype = NPY_DTYPE(to); to_dtype = NPY_DTYPE(to);
} }
PyObject *meth = PyArray_GetCastingImpl(NPY_DTYPE(from), to_dtype); PyObject *meth = PyArray_GetCastingImpl(NPY_DTYPE(from), to_dtype);
if (meth == NULL) { if (meth == NULL) {
return -1; return -1;
} }
skipping to change at line 2801 skipping to change at line 2801
PyArray_Descr **given_descrs, PyArray_Descr **loop_descrs) PyArray_Descr **given_descrs, PyArray_Descr **loop_descrs)
{ {
/* `dtype="V"` means unstructured currently (compare final path) */ /* `dtype="V"` means unstructured currently (compare final path) */
loop_descrs[1] = PyArray_DescrNewFromType(NPY_VOID); loop_descrs[1] = PyArray_DescrNewFromType(NPY_VOID);
if (loop_descrs[1] == NULL) { if (loop_descrs[1] == NULL) {
return -1; return -1;
} }
loop_descrs[1]->elsize = given_descrs[0]->elsize; loop_descrs[1]->elsize = given_descrs[0]->elsize;
Py_INCREF(given_descrs[0]); Py_INCREF(given_descrs[0]);
loop_descrs[0] = given_descrs[0]; loop_descrs[0] = given_descrs[0];
if (loop_descrs[0]->type_num == NPY_VOID &&
loop_descrs[0]->subarray == NULL && loop_descrs[1]->names == NULL) {
return NPY_NO_CASTING | _NPY_CAST_IS_VIEW;
}
return NPY_SAFE_CASTING | _NPY_CAST_IS_VIEW; return NPY_SAFE_CASTING | _NPY_CAST_IS_VIEW;
} }
static NPY_CASTING static NPY_CASTING
nonstructured_to_structured_resolve_descriptors( nonstructured_to_structured_resolve_descriptors(
PyArrayMethodObject *NPY_UNUSED(self), PyArrayMethodObject *NPY_UNUSED(self),
PyArray_DTypeMeta *NPY_UNUSED(dtypes[2]), PyArray_DTypeMeta *NPY_UNUSED(dtypes[2]),
PyArray_Descr *given_descrs[2], PyArray_Descr *given_descrs[2],
PyArray_Descr *loop_descrs[2]) PyArray_Descr *loop_descrs[2])
{ {
skipping to change at line 3244 skipping to change at line 3248
if (from_sub && to_sub) { if (from_sub && to_sub) {
int res = PyObject_RichCompareBool(from_sub->shape, to_sub->shape, P y_EQ); int res = PyObject_RichCompareBool(from_sub->shape, to_sub->shape, P y_EQ);
if (res < 0) { if (res < 0) {
return -1; return -1;
} }
else if (res) { else if (res) {
/* Both are subarrays and the shape matches */ /* Both are subarrays and the shape matches */
casting = NPY_NO_CASTING | _NPY_CAST_IS_VIEW; casting = NPY_NO_CASTING | _NPY_CAST_IS_VIEW;
} }
} }
NPY_CASTING field_casting = PyArray_GetCastSafety(
given_descrs[0]->subarray->base, given_descrs[1]->subarray->base PyArray_Descr *from_base = (from_sub == NULL) ? given_descrs[0] : from_s
, NULL); ub->base;
PyArray_Descr *to_base = (to_sub == NULL) ? given_descrs[1] : to_sub->ba
se;
NPY_CASTING field_casting = PyArray_GetCastSafety(from_base, to_base, NU
LL);
if (field_casting < 0) { if (field_casting < 0) {
return -1; return -1;
} }
casting = PyArray_MinCastSafety(casting, field_casting); casting = PyArray_MinCastSafety(casting, field_casting);
} }
/* Void dtypes always do the full cast. */ /* Void dtypes always do the full cast. */
Py_INCREF(given_descrs[0]); Py_INCREF(given_descrs[0]);
loop_descrs[0] = given_descrs[0]; loop_descrs[0] = given_descrs[0];
Py_INCREF(given_descrs[1]); Py_INCREF(given_descrs[1]);
 End of changes. 3 change blocks. 
4 lines changed or deleted 12 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)