Copyright (C) 2003 Aki Vehtari
It is often useful to make operations on two matrices for which singleton dimensions are expanded to match the size of the other. This can be achieved with repmat, but the code looks nasty. Douglas M. Schwarz wrote genops, which implements generalized operations in MEX-files with C. Based on that idea I reimplemented genops in plain M-files. This solution uses internally repmat, and thus it is not as fast and uses more memory. It is useful when distributing small code packages which use genops, and thus saving trouble of binary compatibility or re-compiling.
Original implementation by Douglas M. Schwarz overloaded built-in operations, but I think it can cause more trouble than benefit. Instead I have installed the generalized operators as functions starting with letter `g'. So generalized versions of built-in functions plus, minus, times, rdivide, ldivide, power, eq, ne, lt, gt, le and ge are named as gplus, gminus, gtimes, grdivide, gldivide, gpower, geq, gne, glt, ggt, gle and gge. Additionally there is function genop, which can be called with arbitrary function working on two same sized matrices.
X = randn(10,100); Y = gminus(X, mean(X));
This software is distributed under the GNU General Public Licence (version 2 or later); please refer to the file Licence.txt, included with the software, for details.
Generalized arithmetic operators. GPLUS - Generalized plus GMINUS - Generalized minus GTIMES - Generalized array multiply GPOWER - Generalized array power GLDIVIDE - Generalized left array divide GRDIVIDE - Generalized right array divide Generalized relational operators. GEQ - Generalized equal GNE - Generalized not equal GLT - Generalized less than GGT - Generalized greater than GLE - Generalized less than or equal GGE - Generalized greater than or equal