-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH/FIX: Allow very large values in relabel_sequential (#4612)
* Adding first draft of Cython relabel_sequential Co-authored-by: Juan Nunez-Iglesias <juan.nunez-iglesias@monash.edu> * fixed order of args for map_array * Add ArrayMap str and repr * Add __call__ method to ArrayMap object * Add missing colon * Add array representation for ArrayMap * Use array representation to preserve relabel_sequential doctests * Restore ValueError checks for relabel_sequential * Fix PEP8 issues * Ensure 0 always maps to 0 * Ensure dtype is correct for output * Fix incorrect dtype for array being relabeled The docs specify that only integer arrays are supported. This change was added in gh-811 without any discussion so imho safe to revert. * Fix dtype of output and map * Inverse map dtype should actually map the input dtype * Fix docstring for map_array, check for contiguous out * Add docstring for ArrayMap * Rename attributes in ArrayMap * Add C++0x standard to the compiler options * added missing paren in docstring * mention large size of returned array in __array__ docstr * adjusted sample array to fix doctest Co-authored-by: Juan Nunez-Iglesias <juan.nunez-iglesias@monash.edu> * added tests for dtype overflow * test relabel_seq... works for large input * Simplify checking of contiguous array Co-Authored-By: Riadh Fezzani <rfezzani@gmail.com> * Minor code updates from review Co-Authored-By: Riadh Fezzani <rfezzani@gmail.com> * Restore reshaping of output array when provided * Add note about -std=c++0x flag * Ensure reshape is zero-copy * Clarify error message when output has incorrect shape * Remove unused numpy import * Update relabel_sequential docstring to indicate new output types * Raise error if the input array has non-integer type * Ensure arrays being mapped and value arrays have same dtype * Add doctests for ArrayMap.__str__ and fix * Rework logic for in-place reshaping * Add test for error when labels dtype is not int * Add test for incorrect map_array output shape * Test discontiguous output array * Add test for long reprs for ArrayMap * Add test for calling ArrayMap * Remove long-deprecated relabel_from_one * Add len to ArrayMap * Add support for setitem and scalar mapping * Add support for slicing and updating map in-place * Allow bool indices in arraymap getitem Co-authored-by: Volker Hilsenstein <volker.hilsenstein@monash.edu> Co-authored-by: Juan Nunez-Iglesias <juan.nunez-iglesias@monash.edu> Co-authored-by: Riadh Fezzani <rfezzani@gmail.com>
- Loading branch information
1 parent
06aa947
commit 4bff390
Showing
5 changed files
with
364 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# distutils: language = c++ | ||
|
||
from libcpp.unordered_map cimport unordered_map | ||
cimport cython | ||
from .._shared.fused_numerics cimport np_numeric, np_anyint | ||
|
||
@cython.boundscheck(False) # Deactivate bounds checking | ||
@cython.wraparound(False) # Deactivate negative indexing | ||
def _map_array(np_anyint[:] inarr, np_numeric[:] outarr, | ||
np_anyint[:] inval, np_numeric[:] outval): | ||
# build the map from the input and output vectors | ||
cdef size_t i, n_map, n_array | ||
cdef unordered_map[np_anyint, np_numeric] lut | ||
n_map = inval.shape[0] | ||
for i in range(n_map): | ||
lut[inval[i]] = outval[i] | ||
# apply the map to the array | ||
n_array = inarr.shape[0] | ||
# The prange option gave some compilation warnings | ||
# "Unsigned index type not allowed before OpenMP 3.0" | ||
# and didn't seem to be any faster | ||
# for i in prange(n_array, nogil=True): # | ||
for i in range(n_array): | ||
outarr[i] = lut[inarr[i]] |
This file contains 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.