[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
associative operators extended
From: |
Jaroslav Hajek |
Subject: |
associative operators extended |
Date: |
Fri, 12 Jun 2009 12:00:50 +0200 |
hi,
inspired by the question of Carlo Rossi:
http://www.nabble.com/cell-p23833329.html (and I think this appeared
several times before), I've extended the built-in functions `plus',
`times', `mtimes', `and', `or' to accept multiple arguments, in which
case they simply apply cumulatively from left to right:
http://hg.savannah.gnu.org/hgweb/octave/rev/c0b104835d0d
This can be used to conveniently sum elements in a cell or struct array:
plus (matrices{:}) # or times/mtimes/and/or
the same can be achieved by using
sum (cat (3, matrices{:}), 3) # or prod/all/any, no equivalent for mtimes
Advantages of the former:
1. more readable
2. can handle a mixture of arbitrary matrix types and scalars, as well
as user classes.
3. expected to be more efficient (memory, probably time as well)
PS. Of course, if you work with a large number of equal-size
equal-type matrices, it is usually better to use a 3d array from the
very start, in which case the sum, prod, any, all reductions are the
most efficient.
enjoy
--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- associative operators extended,
Jaroslav Hajek <=