Skip to content

ENH: Make the default int intp when a flag is set - #16535

Closed
seberg wants to merge 1 commit into
numpy:masterfrom
seberg:default-int-windows
Closed

seberg wants to merge 1 commit into
numpy:masterfrom
seberg:default-int-windows

Conversation

@seberg

@seberg seberg commented Jun 8, 2020

Copy link
Copy Markdown
Member

This will be nice mainly for windows. The only problem here is
right now that we cannot define the macros like this, since they
would be public. They should not be made public (at least like this),
since if someone uses NPY_DEFAULT_INT in their code they should get
the default they are running against, not the one they are compiled
against.


I think we should explore such things and this seems the best first step to me, the changes themselves are easy enough after all. May need someone to test on windows to be sure it works (and likely some test fixups found by CI). Marking as draft, since there are probably fixups necessary when tested on windows...

See also gh-6056 or gh-12332, although this uses the intp option, which seems a bit easier to me, because we return and use intp in a lot of places and many of those might otherwise need to be bumped up as well for a uniform user-experience...
At least with np.intp as default, the rule is smiple 64bit on 64bit systems, 32bit on 32bit.

I think we should change this, but I believe flipping the switch is a pretty big API change (even if it is one that very few users will notice).

This will be nice mainly for windows. The only problem here is
right now that we cannot define the macros like this, since they
would be public.  They should not be made public (at least like this),
since if someone uses NPY_DEFAULT_INT in their code they should get
the default they are running against, not the one they are compiled
against.
@seberg

seberg commented Jun 8, 2020

Copy link
Copy Markdown
Member Author

Oh, nice example of what can go wrong. Legacy random fails because it allocates default integer arrays (with dtype=int) and (until here correctly) assumes they are long.

@seberg

seberg commented Jun 9, 2020

Copy link
Copy Markdown
Member Author

Closing this for now, was mostly curious what fails on windows. The np.long name being int might be one of the bigger traps (aside the general issues such as seen in random).

@seberg seberg closed this Jun 9, 2020
@eric-wieser

Copy link
Copy Markdown
Member

The np.long name being int might be one of the bigger traps

Can we move forward with #14882 to try and resolve that trap?

@seberg

seberg commented Jun 9, 2020

Copy link
Copy Markdown
Member Author

@eric-wieser if you want to review this, I am happy to reopen and just move it forward now. Right now it just adds a flag after all, so the trap is probably even OK (if documented). But yes, that one should move as well.

Fixing up random should be very simple, just replacing a few int with whatever is best to get an actual long (I am wondering if we really should have np.long_ as unfortunate as it is, that seems right?

@eric-wieser

eric-wieser commented Jun 9, 2020 •

Copy link
Copy Markdown
Member

I am wondering if we really should have np.long_ as unfortunate as it is, that seems right?

Are you looking for np.int_, which is an exact replacement for int today, and is a C long?

@seberg

seberg commented Jun 9, 2020

Copy link
Copy Markdown
Member Author

@eric-wieser I suppose so, although it is a bit annoying that with this change, you would have np.array(..., dtype=np.int_) give you long while np.array(..., dtype=int) gives you intp...

@eric-wieser

Copy link
Copy Markdown
Member

I think if you went down this route you'd probably also want to deprecate np.int_ in favor of a better name like np.long_...

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