-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
ENH: Add support for copy modes to NumPy #19173
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
Changes from 1 commit
496bd1a
3a3d31b
be5823f
e16f3ff
645fadb
8538720
8c00223
4e59da1
6f0f6ac
6bff3dd
a90880a
5481a8a
f2e7a81
e828f15
1a92ae9
91d6693
7b53a02
eedb300
bc8903d
3268a48
ab01330
782d823
342e0c5
a09929b
30e3472
a6caf9c
3dcf3a9
321e028
844883c
d995ecc
0f8d4c5
698fb6d
b341e4c
781d0a7
45dbdc9
a39312c
c2acd5b
56647dd
c04509e
790f927
2677788
d9a9785
5cb2d64
8b939c9
7658ad9
2cf561b
37cd05e
9f9a348
946ab24
2c51b0a
5ede7eb
d1cb662
6c01915
5f1965f
05ff102
68dfa4b
2db65c9
d0d75f3
eccb8df
4b2cd27
84951a6
f31c4a6
dea4055
9fee0f8
f058aea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -174,15 +174,29 @@ PyArray_CopyConverter(PyObject *obj, PyNpCopyMode_Enum *copymode) { | |||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
int int_copymode = -1; | ||||||||||||||||||||||||||||||||||||||
PyArray_PythonPyIntFromInt(obj, &int_copymode); | ||||||||||||||||||||||||||||||||||||||
PyObject* numpy_CopyMode = NULL; | ||||||||||||||||||||||||||||||||||||||
npy_cache_import("numpy._globals", "CopyMode", &numpy_CopyMode); | ||||||||||||||||||||||||||||||||||||||
if( numpy_CopyMode != NULL ) { | ||||||||||||||||||||||||||||||||||||||
if(PyObject_IsInstance(obj, numpy_CopyMode)) { | ||||||||||||||||||||||||||||||||||||||
PyObject* mode_value = PyObject_GetAttrString(obj, "value"); | ||||||||||||||||||||||||||||||||||||||
PyArray_PythonPyIntFromInt(mode_value, &int_copymode); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there reasons against treating them as singletons?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, what happens in the above code is, first we try to verify if the copy argument is an instance of Now, in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the last should just have been There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One another way to simplify the checks would be to first import, |
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// If obj is not an instance of numpy.CopyMode then follow | ||||||||||||||||||||||||||||||||||||||
// the conventional assumption that it must be value that | ||||||||||||||||||||||||||||||||||||||
// can be converted to an integer. | ||||||||||||||||||||||||||||||||||||||
if( int_copymode < 0 ) { | ||||||||||||||||||||||||||||||||||||||
czgdp1807 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
PyArray_PythonPyIntFromInt(obj, &int_copymode); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
if( int_copymode != NPY_ALWAYS && | ||||||||||||||||||||||||||||||||||||||
int_copymode != NPY_IF_NEEDED && | ||||||||||||||||||||||||||||||||||||||
int_copymode != NPY_NEVER ) { | ||||||||||||||||||||||||||||||||||||||
PyErr_Format(PyExc_ValueError, | ||||||||||||||||||||||||||||||||||||||
"Unrecognized copy mode %d. Please choose one of " | ||||||||||||||||||||||||||||||||||||||
"np.CopyMode.ALWAYS, np.CopyMode.IF_NEEDED, np.CopyMode.NEVER.", | ||||||||||||||||||||||||||||||||||||||
int_copymode); | ||||||||||||||||||||||||||||||||||||||
PyErr_SetString(PyExc_ValueError, | ||||||||||||||||||||||||||||||||||||||
"Unrecognized copy mode. Please choose one of " | ||||||||||||||||||||||||||||||||||||||
"np.CopyMode.ALWAYS, np.CopyMode.IF_NEEDED, np.CopyMode.NEVER, " | ||||||||||||||||||||||||||||||||||||||
"True/np.True_, False/np.False_"); | ||||||||||||||||||||||||||||||||||||||
return NPY_FAIL; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.