Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

implement same_value casting for numpy <-> quadtype#161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mattip wants to merge7 commits intonumpy:main
base:main
Choose a base branch
Loading
frommattip:same_value_cast

Conversation

mattip
Copy link
Member

Closes#153 to implementsame_value casting.

I did not look at quad <-> quad casting. CC@seberg for visibility, as far as I can tell theNPY_SAME_VALUE_CASTING_FLAG was sufficient to percolate correctly through the can_cast mechanism.


template<typename T>
staticNPY_CASTING
staticint
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Hmm... I think this is OK? I didn't see any new warnings, but there are thousands of build warnings when using sleef and I might have missed it.

.casting = NPY_SAME_VALUE_CASTING,
#else
.casting = NPY_UNSAFE_CASTING,
#endif
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I am not clear how this is used, doesn't the resolver actually state which casting is supported?


#ifndef DISABLE_QUADBLAS
#include"../subprojects/qblas/include/quadblas/quadblas.hpp"
#include"quadblas/quadblas.hpp"
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I needed this to build with-e, i.e.pip install -Csetup-args="-Dbuildtype=debug" -e . --no-build-isolation 2>&1 | tee /tmp/build.txt. Otherwise the build failed.

@mattip
Copy link
MemberAuthor

Ahh, this needs a nightly numpy build for CI. How is the best way to do that?

@ngoldbaum
Copy link
Member

Hmm, that's a good point that we need to wait for numpy releases go add features here when often we want to work on both in tandem.

I'd be for adding a new CI job that depends on numpymain. We also want to test against the last stable release too, I think.

I think ideally also you should be able to write this with conditional compilation so it works on older numpy versions, but maybe that's hard in practice. I don't think it's ahuge deal to raise the minimum requires numpy version here but also I think it's worth looking to see if we can avoid that.

*ret = from_quad<typename NpyType<T>::TYPE>(x, backend);
quad_value check = to_quad<typename NpyType<T>::TYPE>(*ret, backend);
if (backend == BACKEND_SLEEF) {
if (check.sleef_value == x.sleef_value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just compare sleef values here? Should this use equality with NaN = NaN?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Can we just compare sleef values here?

I was following the pattern from elsewhere. Is it guaranteed that the sleef backend is used?

Should this use equality with NaN = NaN?

Good point!

Copy link
Contributor

Choose a reason for hiding this comment

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

In the SLEEF branch, I was thinking ofSleef_icmpeqq1(a, b) | (Sleef_iunordq1(a, a) & Sleef_iunordq1(b, b))



deftest_same_value_cast():
# This will fail if compiled with NPY_TARGET_VERSION NPY<2_4_API_VERSION
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this text check the numpy version and be ignored for <2.4?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It needs both installednumpy.__version__ >=2.23 and that numpy_quadtype is built with the 2.24+ C-API

#defineNPY_NO_DEPRECATED_APINPY_2_0_API_VERSION
#defineNPY_TARGET_VERSIONNPY_2_0_API_VERSION
#defineNPY_NO_DEPRECATED_APINPY_2_4_API_VERSION
#defineNPY_TARGET_VERSIONNPY_2_4_API_VERSION
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit trickier unless you don't care about supporting NumPy <2.4. But if you don't, make sure that the target version is defined in (and matches up) with the file that does the actual NumPy import/loading. (Because that will check runtime compatibility.)

You can lie (I really don't mind), but you cannot use the flag at runtime unless you also checkPyArray_RUNTIME_VERSION at runtime and not at compile time.
As is, if you compile with NumPy 2.4 (which you should!), the casts will be broken on 2.3.

(could also just define the flag here manually. Wecould include thePyArray_RUNTIME_CHECK into the numpy headers as well if you prefer -- to basically simplify exactly this type of code that wants to use it if available. The compat headers have a lot of examples for such code.)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

make sure that the target version is defined in (and matches up) with the file that does the actual NumPy import/loading

Good point, that isquaddtype_main.c.

but you cannot use the flag at runtime unless you also check PyArray_RUNTIME_VERSION at runtime

Did you meanPyArray_GetNDArrayCFeatureVersion() >= NPY_2_4_API_VERSION?

Copy link
Member

Choose a reason for hiding this comment

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

I meanPyArray_RUNTIME_VERSION >= NPY_2_4_API_VERSION.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

How does that work at runtime? It is not exported as a constant from_multiarray_umath.so

Copy link
Member

Choose a reason for hiding this comment

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

It's injected as a constant into your library, next to the API table. Dunno if that was the right choice, but there we are :).

Copy link
Member

Choose a reason for hiding this comment

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

PyArray_RUNTIME_VERSION isruntime! Not a pre-processor macro.

@mattip

This comment was marked as off-topic.

@mattip
Copy link
MemberAuthor

Boosting the comment about taking NAN into account when comparing float values which is still TBD. Also testing is not that extensive for edge cases.

In the SLEEF branch, I was thinking ofSleef_icmpeqq1(a, b) | (Sleef_iunordq1(a, a) & Sleef_iunordq1(b, b))

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

@sebergsebergseberg left review comments

+1 more reviewer

@juntyrjuntyrjuntyr left review comments

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Use same_value casting in astype
4 participants
@mattip@ngoldbaum@seberg@juntyr

[8]ページ先頭

©2009-2025 Movatter.jp