Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[WIP] MAINT: get rid of np.int #5032

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

Closed
wants to merge 1 commit into from

Conversation

larsmans
Copy link
Member

np.int is a confusing synonym for __builtin__.int; it maps to C long, the size of which is platform-dependent and not necessarily the same as that of C int. The NumPy devs are speaking of deprecating np.int, and all uses of it in SciPy have just been removed (scipy/scipy@10ca036).

Don't merge yet: these are not all occurrences, and np.float needs the same treatment.

See also numpy/numpy#6103.

np.int is a confusing synonym for __builtin__.int; it maps to C long,
the size of which is platform-dependent. The NumPy devs are speaking of
deprecating np.int, and all uses of it in SciPy have been replaced.

Notably, this makes sample_without_replacement 64-bit clean; previously
it used np.int_t, which is a C long (32 bits wide on Windows).

See also http://github.com/numpy/numpy#6103.
@TomDLT
Copy link
Member

TomDLT commented Jul 27, 2015

Is int to be preferred over a more explicit np.int32 ?

@larsmans
Copy link
Member Author

Are you referring to a specific part of the PR, or in general?

@TomDLT
Copy link
Member

TomDLT commented Jul 27, 2015

In general. Or np.int8 and np.int16 if need be.

@larsmans
Copy link
Member Author

For indices, np.intp should be used, because C's long isn't long enough on Windows 64. For class/cluster labels, I'm not sure and in this PR, I decided to only remove np.int mentions, not try to rationalize the entire codebase.

@amueller
Copy link
Member

I think we removed all appearances of float in favour of float64.

@amueller
Copy link
Member

I am also wondering why not np.int64?

@larsmans
Copy link
Member Author

I think we removed all appearances of float in favour of float64.

$ git grep 'np\.float[^0-9]' -- '*.py' | wc -l
111

@amueller
Copy link
Member

meh. Ok. maybe not. but that is just a single command to fix ;)

@amueller
Copy link
Member

the question is whether we want to use numpy types or python types, right?

@larsmans
Copy link
Member Author

I'm in favor of using np.intp for all integers that are being used as indexes since any other type might force a conversion (I'm not intimately familiar with NumPy's indexing code, so I don't know if they are happening). I don't really know the ramifications of using int on Windows. I do suppose that using int64 will waste space on 32-bit boxes.

@amueller
Copy link
Member

It's a bit hard to know whether something will be used as index, right? I guess we don't generally pass integers around, though, apart from the cross-validation module, where they will be used as indices.
What does unique return?

samples_range = np.linspace(2, 1000, 4).astype(np.int)
features_range = np.linspace(2, 1000, 4).astype(np.int)
samples_range = np.linspace(2, 1000, 4).astype(int)
features_range = np.linspace(2, 1000, 4).astype(int)

Choose a reason for hiding this comment

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

These should all be linspace(..., dtype=int) to avoid a copy

@amueller
Copy link
Member

too many conflicts. If we want to do this we should start from scratch.

@amueller amueller closed this Jun 13, 2019
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.

4 participants