Skip to content

Unify promoter implementations and align behavior with NumPy - #120

Merged
ngoldbaum merged 5 commits into
numpy:mainfrom
ngoldbaum:fix-promoter-overlap
Sep 15, 2026
Merged

ngoldbaum merged 5 commits into
numpy:mainfrom
ngoldbaum:fix-promoter-overlap

Conversation

@ngoldbaum

@ngoldbaum ngoldbaum commented Sep 11, 2026

Copy link
Copy Markdown
Member

Fixes issues I noticed while looking over PR #118 today.

First, it unifies the promoter implementations to use a shared helper. Second, it updates the promoter logic to be more consistent with NumPy.

Currently, one can trigger errors due to ambiguous promotion. It's also not currently possible to do e.g. np.add(quad, quad, dtype='float64'). This fixes both issues. See the tests. I also deleted the existing promoter tests because they're duplicative with the new tests.

I used an AI model for help with this.

@SwayamInSync SwayamInSync left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is great, I liked the refactor done.
Some nit-picks I mentioned in comments which isn't a blocker and I will handle them in the follow-ups.
Said that comparisons, logical_not, ldexp and frexp still fail when an output dtype is requested. They also go in a follow-up.

Comment thread src/csrc/umath/matmul.cpp Outdated
Py_DECREF(ufunc);

return 0;
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
}
}

adding trailing newline

Comment thread src/csrc/scalar.c Outdated
return Py_NewRef(self);
}

// TODO: Use PyArray_Conjugate when NumPy >= 2.5 is required. NumPy 2.4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the real reason for the conj override, which is that NumPy 2.4's inherited generic.conjugate corrupts longdouble-backend scalars.
This was fixed in numpy/numpy#31067 and I think your PR which added the fix for byteswapping to error instead of segfault is also 2.5, so we should update the numpy-quaddtype's dependency from 2.4 to 2.5 (Otherwise have to create the override for all the scalar functions here, undesirable)

Also I think as we update the dependency of Numpy to >= 2.5, we can entirely delete this override as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Small correction: I checked the release tags, and the byteswap fix isn't in 2.5.0. Your #32151 backport (#32221) landed in 2.5.2 and the scalar fix (#32254 → #32290) in 2.5.3. On 2.5.0, QuadPrecision(1.5).byteswap() still segfaults; on 2.5.2 it raises TypeError. So the floor should be numpy>=2.5.2 (or >=2.5.3 to include #32254), not just >=2.5.

@ngoldbaum

Copy link
Copy Markdown
Member Author

I think the last commit responds to your comments. Thanks for the simplification. I also updated the CI config to match the updated minimum Python version from NumPy.

@SwayamInSync SwayamInSync left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great and I think we should ideally update the NPY_TARGET_VERSION in C files as well? I can also handle this in the follow-ups.

And users on Python 3.11 or NumPy below 2.5.3 will stop receiving new numpy-quaddtype releases, so the next changelog should mention it.

We don't do anything like .rst files here hmmm... would it be worth it @ngoldbaum ?

@ngoldbaum

Copy link
Copy Markdown
Member Author

CI failure is an unrelated flake. In it goes. Thanks for taking care of the followups!

@ngoldbaum
ngoldbaum merged commit c24eafc into numpy:main Sep 15, 2026
13 of 14 checks passed
@ngoldbaum

Copy link
Copy Markdown
Member Author

We don't do anything like .rst files here hmmm... would it be worth it @ngoldbaum ?

IMO towncrier is overkill for a project that's not very active. I'd say just add a section to the readme until you start getting annoyed by merge conflicts.

@SwayamInSync

Copy link
Copy Markdown
Member

or a project that's not very active

🙂 (smiling in pain)

I'd say just add a section to the readme until you start getting annoyed by merge conflicts.

Yup will keep this in follow-up too

@ngoldbaum

Copy link
Copy Markdown
Member Author

Here "not very active" means the github issue/PR counter is below 10,000! At least IMO...

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