Skip to content

[BUG, REFAC]: Simplifies quad_ufunc_promoter + fixes reduction bug in comparison_ufunc_promoter#79

Open
SwayamInSync wants to merge 3 commits intonumpy:mainfrom
SwayamInSync:promoter-logic-fix
Open

[BUG, REFAC]: Simplifies quad_ufunc_promoter + fixes reduction bug in comparison_ufunc_promoter#79
SwayamInSync wants to merge 3 commits intonumpy:mainfrom
SwayamInSync:promoter-logic-fix

Conversation

@SwayamInSync
Copy link
Copy Markdown
Member

@SwayamInSync SwayamInSync commented Apr 1, 2026

Successor of #78
Recommend to check after closing the #78 (for better diff) otherwise the updated sections are listed below

- Fix quad_ufunc_promoter, quad_ldexp_promoter, and comparison_ufunc_promoter
  signatures to match PyArrayMethod_PromoterFunction typedef:
  (PyObject *, PyArray_DTypeMeta *const[], PyArray_DTypeMeta *const[],
   PyArray_DTypeMeta *[])
- Add missing Py_DECREF(ufunc) in all create_quad_*_ufunc error/success
  return paths (binary_ops, comparison_ops, unary_ops, unary_props)
- Add missing Py_INCREF before Py_XSETREF in comparison_ufunc_promoter
- quad_ufunc_promoter: Remove dead has_quad/common/PyArray_PromoteDTypeSequence
  machinery. Since this promoter is only registered for patterns where at
  least one input is QuadPrecDType, we always promote to QuadPrecDType
  directly. The old fallback paths were unreachable and had a refcount bug
  (Py_XDECREF on a borrowed pointer when has_quad was true).
- comparison_ufunc_promoter: Rewrite with self-contained logic instead of
  delegating to quad_ufunc_promoter. Fixes reduction path which incorrectly
  set accumulator to QuadPrecDType instead of BoolDType (the registered
  reduce loop expects Bool, Quad, Bool).
Copy link
Copy Markdown
Member Author

@SwayamInSync SwayamInSync left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the only functions updated in this PR

inline int
quad_ufunc_promoter(PyUFuncObject *ufunc, PyArray_DTypeMeta *op_dtypes[],
PyArray_DTypeMeta *signature[], PyArray_DTypeMeta *new_op_dtypes[])
quad_ufunc_promoter(PyObject *ufunc_obj, PyArray_DTypeMeta *const op_dtypes[],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1st update

NPY_NO_EXPORT int
comparison_ufunc_promoter(PyUFuncObject *ufunc, PyArray_DTypeMeta *op_dtypes[],
PyArray_DTypeMeta *signature[], PyArray_DTypeMeta *new_op_dtypes[])
comparison_ufunc_promoter(PyObject *ufunc_obj, PyArray_DTypeMeta *const op_dtypes[],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2nd update

@ngoldbaum
Copy link
Copy Markdown
Member

Sorry, not quite clear from the description here and in the other PR: this is an alternative to #78 and we shouldn't merge both, right?

@ngoldbaum
Copy link
Copy Markdown
Member

Oh no never mind, this just depends on the other one.

@SwayamInSync
Copy link
Copy Markdown
Member Author

No its first merge the #78 and then this one
Basically there (in #78 ) I fixed the de-referencing of ufunc object and promoter signature. I saw that promoter's logic has dead code since we changed the registration method to always include QuadDType and there was one bug in comparison_promoter

So I thought to keep these changes in isolation in a new PR (here)

@ngoldbaum
Copy link
Copy Markdown
Member

This needs an update now that the PR is merged.

@SwayamInSync
Copy link
Copy Markdown
Member Author

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants