Skip to content

Commit 5842105

Browse files
committed
BUG: Fixup and add tests for logical ufuncs
1 parent 2aeaa44 commit 5842105

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

numpy/core/src/umath/dispatching.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,12 @@ logical_ufunc_promoter(PyUFuncObject *NPY_UNUSED(ufunc),
831831
PyArray_DTypeMeta *op_dtypes[], PyArray_DTypeMeta *signature[],
832832
PyArray_DTypeMeta *new_op_dtypes[])
833833
{
834-
/* If we find any object at all, we currently force to object */
834+
/*
835+
* If we find any object DType at all, we currently force to object.
836+
* However, if the output is specified and not object, there is no point,
837+
* it should be just as well to cast the input rather than doing the
838+
* unsafe out cast.
839+
*/
835840
int force_object = 0;
836841

837842
for (int i = 0; i < 3; i++) {
@@ -852,7 +857,9 @@ logical_ufunc_promoter(PyUFuncObject *NPY_UNUSED(ufunc),
852857
}
853858
new_op_dtypes[i] = item;
854859
}
855-
if (!force_object) {
860+
861+
if (!force_object || (op_dtypes[2] != NULL
862+
&& op_dtypes[2]->type_num != NPY_OBJECT)) {
856863
return 0;
857864
}
858865
/* Actually, we have to use the OBJECT loop after all, set all we can

0 commit comments

Comments
 (0)