-
-
Notifications
You must be signed in to change notification settings - Fork 12.4k
ENH: Provide a hook for gufuncs to process core dimensions. #26908
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a3f61e1
ENH: Provide a hook for gufuncs to process core dimensions.
WarrenWeckesser 7ab2434
TST: Add a test of conv1d_full with both input core dims 0
WarrenWeckesser aedce12
TST: Remove the test gufunc wl1_pdist
WarrenWeckesser a8dcfa8
DOC: Add comment about the PyUFunc_ProcessCoreDimsFunc type.
WarrenWeckesser ee89a1f
DOC: Copy-edit PyUFunc_ProcessCoreDimsFunc comment.
WarrenWeckesser e71f7ae
DOC: Work on the reference doc for the process_core_dim_sizes function.
WarrenWeckesser 30418e0
DOC: Copy-edit, fix a few typos.
WarrenWeckesser 0586b38
MAINT: Update 2.1 C-API version and use it
seberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,39 @@ typedef int (PyUFunc_TypeResolutionFunc)( | |
| PyObject *type_tup, | ||
| PyArray_Descr **out_dtypes); | ||
|
|
||
| /* | ||
| * This is the signature for the functions that may be assigned to the | ||
| * `process_core_dims_func` field of the PyUFuncObject structure. | ||
| * Implementation of this function is optional. This function is only used | ||
| * by generalized ufuncs (i.e. those with the field `core_enabled` set to 1). | ||
| * The function is called by the ufunc during the processing of the arguments | ||
| * of a call of the ufunc. The function can check the core dimensions of the | ||
| * input and output arrays and return -1 with an exception set if any | ||
| * requirements are not satisfied. If the caller of the ufunc didn't provide | ||
| * output arrays, the core dimensions associated with the output arrays (i.e. | ||
| * those that are not also used in input arrays) will have the value -1 in | ||
| * `core_dim_sizes`. This function can replace any output core dimensions | ||
| * that are -1 with a value that is appropriate for the ufunc. | ||
| * | ||
| * Parameter Description | ||
| * --------------- ------------------------------------------------------ | ||
| * ufunc The ufunc object | ||
| * core_dim_sizes An array with length `ufunc->core_num_dim_ix`. | ||
| * The core dimensions of the arrays passed to the ufunc | ||
| * will have been set. If the caller of the ufunc didn't | ||
| * provide the output array(s), the output-only core | ||
| * dimensions will have the value -1. | ||
| * | ||
| * The function must not change any element in `core_dim_sizes` that is | ||
| * not -1 on input. Doing so will result in incorrect output from the | ||
| * ufunc, and could result in a crash of the Python interpreter. | ||
| * | ||
| * The function must return 0 on success, -1 on failure (with an exception | ||
| * set). | ||
| */ | ||
| typedef int (PyUFunc_ProcessCoreDimsFunc)( | ||
|
mhvk marked this conversation as resolved.
|
||
| struct _tagPyUFuncObject *ufunc, | ||
| npy_intp *core_dim_sizes); | ||
|
|
||
| typedef struct _tagPyUFuncObject { | ||
| PyObject_HEAD | ||
|
|
@@ -191,6 +224,12 @@ typedef struct _tagPyUFuncObject { | |
| /* A PyListObject of `(tuple of DTypes, ArrayMethod/Promoter)` */ | ||
| PyObject *_loops; | ||
| #endif | ||
| #if NPY_FEATURE_VERSION >= NPY_2_1_API_VERSION | ||
|
Member
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. Just noticed, but just noting to not forget: |
||
| /* | ||
| * Optional function to process core dimensions of a gufunc. | ||
| */ | ||
| PyUFunc_ProcessCoreDimsFunc *process_core_dims_func; | ||
| #endif | ||
| } PyUFuncObject; | ||
|
|
||
| #include "arrayobject.h" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What a really nice & clear addition to the documentation!