-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
reshape for numpy arrays #984
Changes from all commits
6f8f47c
a08f012
36ed3a1
5fa0335
49a3b74
fdf05e6
afe7e75
2c11c12
0fb238d
9366583
d1ffc0f
612e01e
4b31ca7
2a486f5
56663b5
5e93212
7685e21
32c0cef
521a261
b4d2094
cf143ae
fb92dc4
127b400
487404b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,6 +198,8 @@ struct npy_api { | |
// Unused. Not removed because that affects ABI of the class. | ||
int (*PyArray_SetBaseObject_)(PyObject *, PyObject *); | ||
PyObject* (*PyArray_Resize_)(PyObject*, PyArray_Dims*, int, int); | ||
PyObject* (*PyArray_Newshape_)(PyObject*, PyArray_Dims*, int); | ||
|
||
private: | ||
enum functions { | ||
API_PyArray_GetNDArrayCFeatureVersion = 211, | ||
|
@@ -212,10 +214,11 @@ struct npy_api { | |
API_PyArray_NewCopy = 85, | ||
API_PyArray_NewFromDescr = 94, | ||
API_PyArray_DescrNewFromType = 96, | ||
API_PyArray_Newshape = 135, | ||
API_PyArray_Squeeze = 136, | ||
API_PyArray_DescrConverter = 174, | ||
API_PyArray_EquivTypes = 182, | ||
API_PyArray_GetArrayParamsFromObject = 278, | ||
API_PyArray_Squeeze = 136, | ||
API_PyArray_SetBaseObject = 282 | ||
}; | ||
|
||
|
@@ -243,11 +246,13 @@ struct npy_api { | |
DECL_NPY_API(PyArray_NewCopy); | ||
DECL_NPY_API(PyArray_NewFromDescr); | ||
DECL_NPY_API(PyArray_DescrNewFromType); | ||
DECL_NPY_API(PyArray_Newshape); | ||
DECL_NPY_API(PyArray_Squeeze); | ||
DECL_NPY_API(PyArray_DescrConverter); | ||
DECL_NPY_API(PyArray_EquivTypes); | ||
DECL_NPY_API(PyArray_GetArrayParamsFromObject); | ||
DECL_NPY_API(PyArray_Squeeze); | ||
DECL_NPY_API(PyArray_SetBaseObject); | ||
|
||
#undef DECL_NPY_API | ||
return api; | ||
} | ||
|
@@ -785,6 +790,18 @@ class array : public buffer { | |
if (isinstance<array>(new_array)) { *this = std::move(new_array); } | ||
} | ||
|
||
/// Optional `order` parameter omitted, to be added as needed. | ||
array reshape(ShapeContainer new_shape) { | ||
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. while we're at it, I'd also plumb through 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. @rwgk We would need to add support for it as a function arg, which we currently don't. That can be added in a followup PR. 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.
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. There is an NORDER Enum that it takes, but I am not sure how to expose that properly. We probably should leave it as is now. 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. sounds good, thanks for looking into it! |
||
detail::npy_api::PyArray_Dims d | ||
= {reinterpret_cast<Py_intptr_t *>(new_shape->data()), int(new_shape->size())}; | ||
auto new_array | ||
= reinterpret_steal<array>(detail::npy_api::get().PyArray_Newshape_(m_ptr, &d, 0)); | ||
if (!new_array) { | ||
throw error_already_set(); | ||
} | ||
return new_array; | ||
} | ||
|
||
/// Ensure that the argument is a NumPy array | ||
/// In case of an error, nullptr is returned and the Python error is cleared. | ||
static array ensure(handle h, int ExtraFlags = 0) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes an ABI break?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@henryiii shrugs @rwgk thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any
virtual
here. If there is no vtable, how does adding or removing member functions change the ABI? I'm having doubts about the correctness of the comment in line 203. I could imagine maybe getting into trouble removing a function, but adding? If a newer extension knows about it, the machine code for it will be in that extension for sure. No?