Skip to content

Commit 4260a26

Browse files
committed
PERF: use custom function to argsort a Python list
1 parent 261618c commit 4260a26

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

larray/core/axis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
_idx_seq_to_slice, _seq_group_to_name, _translate_group_key_hdf, remove_nested_groups)
1616
from larray.util.oset import OrderedSet
1717
from larray.util.misc import (duplicates, array_lookup2, ReprString, index_by_id, renamed_to, common_type, LHDFStore,
18-
lazy_attribute, _isnoneslice, unique_list, unique_multi, Product)
18+
lazy_attribute, _isnoneslice, unique_list, unique_multi, Product, argsort)
1919

2020

2121
np_frompyfunc = np.frompyfunc
@@ -2966,7 +2966,7 @@ def slice_to_sequence(axis, axis_key):
29662966
slice_axes_indices = [i for i, axis_key in enumerate(key)
29672967
if isinstance(axis_key, slice)]
29682968
result_axes_indices = adv_axes_indices + slice_axes_indices
2969-
transpose_indices = tuple(np.array(result_axes_indices).argsort())
2969+
transpose_indices = argsort(result_axes_indices)
29702970
else:
29712971
# the advanced indexing subspace keep its position (insert at position of first concerned axis)
29722972
adv_key_subspace_pos = adv_axes_indices[0]

larray/util/misc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,3 +984,7 @@ def _positive_integer(value):
984984
def _validate_dir(directory):
985985
if not os.path.isdir(directory):
986986
raise ValueError(f"The directory {directory} could not be found")
987+
988+
989+
def argsort(seq):
990+
return sorted(range(len(seq)), key=seq.__getitem__)

0 commit comments

Comments
 (0)