Skip to content

Commit

Permalink
PERF: faster Array.append when axis is in value
Browse files Browse the repository at this point in the history
to avoid making .extend 10x slower on small arrays
  • Loading branch information
gdementen committed Mar 13, 2023
1 parent 53109ff commit 8558966
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion larray/core/array.py
Expand Up @@ -5785,6 +5785,8 @@ def opmethod(self, other) -> 'Array':
other = asarray(other)
elif other is not None and not isinstance(other, (Array, np.ndarray)) and not np.isscalar(other):
# support for inspect.signature
# FIXME: this should only be the case for __eq__. For other operations, we should
# probably raise a TypeError (or return NotImplemented???)
return False

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

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

0 comments on commit 8558966

Please sign in to comment.