Skip to content

Commit 8558966

Browse files
committed
PERF: faster Array.append when axis is in value
to avoid making .extend 10x slower on small arrays
1 parent 53109ff commit 8558966

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

larray/core/array.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5785,6 +5785,8 @@ def opmethod(self, other) -> 'Array':
57855785
other = asarray(other)
57865786
elif other is not None and not isinstance(other, (Array, np.ndarray)) and not np.isscalar(other):
57875787
# support for inspect.signature
5788+
# FIXME: this should only be the case for __eq__. For other operations, we should
5789+
# probably raise a TypeError (or return NotImplemented???)
57885790
return False
57895791

57905792
if isinstance(other, Array):
@@ -6515,7 +6517,13 @@ def append(self, axis, value, label=None) -> 'Array':
65156517
Other F 0.0 0.0
65166518
"""
65176519
axis = self.axes[axis]
6518-
return self.insert(value, before=IGroup(len(axis), axis=axis), label=label)
6520+
if isinstance(value, Array) and axis in value.axes:
6521+
# This is just an optimization because going via the insert path
6522+
# for this case makes this 10x slower.
6523+
# FIXME: we should fix insert slowness instead
6524+
return concat((self, value), axis)
6525+
else:
6526+
return self.insert(value, before=IGroup(len(axis), axis=axis), label=label)
65196527
extend = renamed_to(append, 'extend')
65206528

65216529
def prepend(self, axis, value, label=None) -> 'Array':

0 commit comments

Comments
 (0)