Skip to content

Commit 34e2117

Browse files
committed
promote + register loop with intp
1 parent 3412657 commit 34e2117

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/csrc/umath/binary_ops.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ quad_ldexp_resolve_descriptors(PyObject *self, PyArray_DTypeMeta *const dtypes[]
296296
Py_INCREF(given_descrs[0]);
297297
loop_descrs[0] = given_descrs[0];
298298

299-
// Input 1: Use NPY_INTP (int64 on 64-bit, int32 on 32-bit) to match platform integer size
300-
// This ensures we can handle the full range of PyArray_PyLongDType without data loss
299+
// Input 1: Use NPY_INTP to match the registered PyArray_IntpDType
301300
loop_descrs[1] = PyArray_DescrFromType(NPY_INTP);
302301

303302
// Output: QuadPrecDType with same backend as input
@@ -408,7 +407,7 @@ create_quad_ldexp_ufunc(PyObject *numpy, const char *ufunc_name)
408407
return -1;
409408
}
410409

411-
PyArray_DTypeMeta *dtypes[3] = {&QuadPrecDType, &PyArray_PyLongDType, &QuadPrecDType};
410+
PyArray_DTypeMeta *dtypes[3] = {&QuadPrecDType, &PyArray_IntpDType, &QuadPrecDType};
412411

413412
PyType_Slot slots[] = {
414413
{NPY_METH_resolve_descriptors, (void *)&quad_ldexp_resolve_descriptors},

src/include/umath/promoters.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,15 @@ quad_ldexp_promoter(PyUFuncObject *ufunc, PyArray_DTypeMeta *op_dtypes[],
9494
Py_INCREF(&QuadPrecDType);
9595
new_op_dtypes[0] = &QuadPrecDType;
9696

97-
// Preserve the integer type for the exponent (slot 1)
98-
Py_INCREF(op_dtypes[1]);
99-
new_op_dtypes[1] = op_dtypes[1];
97+
// Promote the exponent to PyLongDType (unless signature specifies otherwise)
98+
if (signature[1] != NULL) {
99+
Py_INCREF(signature[1]);
100+
new_op_dtypes[1] = signature[1];
101+
}
102+
else {
103+
Py_INCREF(&PyArray_IntpDType);
104+
new_op_dtypes[1] = &PyArray_IntpDType;
105+
}
100106

101107
Py_INCREF(&QuadPrecDType);
102108
new_op_dtypes[2] = &QuadPrecDType;

0 commit comments

Comments
 (0)