Skip to content

Commit cb2183e

Browse files
committed
Fix tests
1 parent fec2bea commit cb2183e

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

‎src/csrc/scalar.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,21 +440,34 @@ QuadPrecision_conjugate(QuadPrecisionObject *self, PyObject *args)
440440
return Py_NewRef(self);
441441
}
442442

443+
// TODO: Use PyArray_Conjugate when NumPy >= 2.5 is required. NumPy 2.4
444+
// can dispatch Quad through a ufunc instead of copying its unchanged value.
445+
if (PyArray_FailUnlessWriteable(out, "output array") < 0) {
446+
return NULL;
447+
}
443448
PyArray_Descr *dtype = (PyArray_Descr *)new_quaddtype_instance(self->backend);
444449
if (dtype == NULL) {
445450
return NULL;
446451
}
452+
if (!PyArray_CanCastTypeTo(dtype, PyArray_DESCR(out), NPY_SAME_KIND_CASTING)) {
453+
PyErr_Format(PyExc_TypeError,
454+
"Cannot cast conjugate result from %R to %R with casting='same_kind'",
455+
dtype, PyArray_DESCR(out));
456+
Py_DECREF(dtype);
457+
return NULL;
458+
}
447459
PyArrayObject *array = (PyArrayObject *)PyArray_SimpleNewFromDescr(0, NULL, dtype);
448460
if (array == NULL) {
449461
return NULL;
450462
}
451463
quad_value_store(PyArray_BYTES(array), &self->value, self->backend);
452-
PyObject *result = PyArray_Conjugate(array, out);
464+
int copy_result = PyArray_CopyInto(out, array);
453465
Py_DECREF(array);
454-
if (result == NULL || !PyArray_Check(result)) {
455-
return result;
466+
if (copy_result < 0) {
467+
return NULL;
456468
}
457-
return PyArray_Return((PyArrayObject *)result);
469+
Py_INCREF(out);
470+
return PyArray_Return(out);
458471
}
459472

460473
// Method implementations for float compatibility

0 commit comments

Comments
 (0)