Skip to content

Commit

Permalink
ENH Binary operations (+, -, &, ...) faster.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwgoodman committed Mar 25, 2012
1 parent 91fb57f commit 3da0751
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
3 changes: 3 additions & 0 deletions RELEASE.rst
Expand Up @@ -11,6 +11,9 @@ la 0.7


*Release date: Not yet released, in development* *Release date: Not yet released, in development*


**Enhancements**

- Binary functions (+, -, / , &, ...) are faster for unaligned larrys


Older versions Older versions
============== ==============
Expand Down
45 changes: 19 additions & 26 deletions la/deflarry.py
Expand Up @@ -927,32 +927,25 @@ def __or__(self, other):


def __align(self, other): def __align(self, other):
"Align larrys for binary operations." "Align larrys for binary operations."
if self.label == other.label: if self.ndim != other.ndim:
# Labels are already aligned msg = 'Binary operation on two larrys with different dimension'
x = self.x raise IndexError, msg
y = other.x label = []
label = self.copylabel() x = self.x
else: y = other.x
# Labels are not aligned. ax = -1
if self.ndim != other.ndim: for ls, lo in zip(self.label, other.label):
msg = 'Binary operation on two larrys with different dimension' ax += 1
raise IndexError, msg if ls == lo:
label = [] lab = list(ls)
x = self.x else:
y = other.x lab = list(frozenset(ls).intersection(lo))
ax = -1 lab.sort()
for ls, lo in zip(self.copylabel(), other.label): ids = listmap(ls, lab)
ax += 1 ido = listmap(lo, lab)
if ls == lo: x = x.take(ids, ax)
lab = ls y = y.take(ido, ax)
else: label.append(lab)
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)
return x, y, label return x, y, label


# Reduce functions ------------------------------------------------------- # Reduce functions -------------------------------------------------------
Expand Down

0 comments on commit 3da0751

Please sign in to comment.