# kwgoodman/la

ENH Binary operations (+, -, &, ...) faster.

1 parent 91fb57f commit 3da07514b011e29bb7351693c0b4fbacfe02cd7b committed Mar 25, 2012
Showing with 22 additions and 26 deletions.
1. +3 −0 RELEASE.rst
2. +19 −26 la/deflarry.py
 @@ -11,6 +11,9 @@ la 0.7 *Release date: Not yet released, in development* +**Enhancements** + +- Binary functions (+, -, / , &, ...) are faster for unaligned larrys Older versions ==============
 @@ -927,32 +927,25 @@ def __or__(self, other): def __align(self, other): "Align larrys for binary operations." - if self.label == other.label: - # Labels are already aligned - x = self.x - y = other.x - label = self.copylabel() - else: - # Labels are not aligned. - if self.ndim != other.ndim: - msg = 'Binary operation on two larrys with different dimension' - raise IndexError, msg - label = [] - x = self.x - y = other.x - ax = -1 - for ls, lo in zip(self.copylabel(), other.label): - ax += 1 - if ls == lo: - lab = ls - else: - lab = list(frozenset(ls) & frozenset(lo)) - lab.sort() - ids = listmap(ls, lab) - ido = listmap(lo, lab) - x = x.take(ids, ax) - y = y.take(ido, ax) - label.append(lab) + if self.ndim != other.ndim: + msg = 'Binary operation on two larrys with different dimension' + raise IndexError, msg + label = [] + x = self.x + y = other.x + ax = -1 + for ls, lo in zip(self.label, other.label): + ax += 1 + if ls == lo: + lab = list(ls) + else: + lab = list(frozenset(ls).intersection(lo)) + lab.sort() + ids = listmap(ls, lab) + ido = listmap(lo, lab) + x = x.take(ids, ax) + y = y.take(ido, ax) + label.append(lab) return x, y, label # Reduce functions -------------------------------------------------------