Skip to content

ENH: add a casting option 'same_value' and use it in np.astype #29129

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cb8ea97
start implementing same_value casting
mattip Feb 17, 2025
3859a73
work through more places that check 'cast', add a TODO
Feb 17, 2025
9dc63a5
add a test, percolate casting closer to inner loops
mattip May 15, 2025
7cad6af
use SAME_VALUE_CAST flag for one inner loop variant
mattip May 29, 2025
03e9ceb
aligned test of same_value passes. Need more tests
mattip Jun 1, 2025
93b8bce
handle unaligned casting with 'same_value'
mattip Jun 1, 2025
87e2487
extend tests to use source-is-complex
mattip Jun 1, 2025
9aa1e5a
fix more interfaces to pass casting around, disallow using 'same_valu…
mattip Jun 2, 2025
953714e
raise in places that have a kwarg casting, besides np.astype
mattip Jun 2, 2025
cd3e144
refactor based on review comments
mattip Jun 9, 2025
6d6b045
CHAR_MAX,MIN -> SCHAR_MAX,MIN
mattip Jul 21, 2025
1293657
copy context flags
mattip Jul 22, 2025
d151c91
add 'same_value' to typing stubs
mattip Jul 23, 2025
6254ae5
document new feature
mattip Jul 24, 2025
6922b35
test, check exact float->int casting: refactor same_value check into …
mattip Jul 24, 2025
a323a4b
enable astype same_value casting for scalars
mattip Jul 24, 2025
aec8ea1
typo
mattip Jul 24, 2025
26c0fa1
fix ptr-to-src_value -> value casting errors
mattip Jul 25, 2025
0846081
fix linting and docs, ignore warning better
mattip Jul 25, 2025
76e01c1
gcc warning is different
mattip Jul 25, 2025
963ea05
fixes from review, typos
mattip Jul 26, 2025
4a9a498
fix compile warning ignore and make filter in tests more specific, di…
mattip Jul 27, 2025
10c4493
fix warning filters
mattip Jul 28, 2025
58a0a09
emit PyErr inside the loop
mattip Jul 31, 2025
64b8747
macOS can emit FPEs when touching NAN
mattip Jul 31, 2025
9d55847
Fix can-cast logic everywhere for same-value casts (only allow numeric)
seberg Jun 13, 2025
a800154
reorder and simplify, from review
mattip Aug 5, 2025
70d92bc
revert last commit and remove redundant checks
mattip Aug 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
typo
  • Loading branch information
mattip committed Jul 24, 2025
commit aec8ea1dc15d01497bfb78dbb760f653e910df8a
4 changes: 2 additions & 2 deletions numpy/_core/src/multiarray/lowlevel_strided_loops.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,10 @@ NPY_NO_EXPORT PyArrayMethod_StridedLoop *

# if @is_float1@
# define _CONVERT_FN(x) npy_floatbits_to_halfbits(x)
# define _ROUND_TRIP(x) npy_halfbits_to_floatbits(_CONVERTFN(x))
# define _ROUND_TRIP(x) npy_halfbits_to_floatbits(_CONVERT_FN(x))
# elif @is_double1@
# define _CONVERT_FN(x) npy_doublebits_to_halfbits(x)
# define _ROUND_TRIP(x) npy_halfbits_to_doublebits(_CONVERTFN(x))
# define _ROUND_TRIP(x) npy_halfbits_to_doublebits(_CONVERT_FN(x))
# elif @is_emu_half1@
# define _CONVERT_FN(x) (x)
# define _ROUND_TRIP(x) (x)
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy