Skip to content

Commit 261618c

Browse files
committed
PERF: avoid using Array.transpose in Array.__getitem__ to avoid creating an extra Array()
1 parent afa7177 commit 261618c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

larray/core/array.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,10 +1962,12 @@ def __getitem__(self, key, collapse_slices=False, translate_key=True, points=Fal
19621962
self.axes._key_to_raw_and_axes(key, collapse_slices, translate_key, points, wildcard=False)
19631963
res_data = self.data[raw_broadcasted_key]
19641964
if res_axes:
1965-
res = Array(res_data, res_axes)
19661965
# if some axes have been moved in front because of advanced indexing, we transpose them back to their
1967-
# original position
1968-
return res.transpose(transpose_indices) if transpose_indices is not None else res
1966+
# original position. We do not use Array.transpose because that creates another Array object which is costly
1967+
if transpose_indices is not None:
1968+
res_data = res_data.transpose(transpose_indices)
1969+
res_axes = res_axes[transpose_indices]
1970+
return Array(res_data, res_axes)
19691971
else:
19701972
return res_data
19711973

0 commit comments

Comments
 (0)