Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

# Multiple matrix multiplications, with array expansion enabled 1.0

Date Added: May 02, 2013  |  Visits: 300

MULTIPROD is a powerful, quick and memory efficient generalization for N-D arrays of the MATLAB matrix multiplication operator (*). While the latter works only with 2-D arrays, MULTIPROD works also with multidimensional arrays.MULTIPROD performs multiple multiplications between matrices, vectors, or scalars contained in two multidimensional arrays, with automatic virtual array expansion (AX) enabled. AX allows you, for instance, to multiply a single matrix A by an array of matrices B, by virtually replicating A to obtain an array compatible with B.Multidimensional arrays may contain matrices or vectors or even scalars along one or two of their dimensions. For instance, a 4doOCo5doOCo3 array A contains three 4doOCo5 matrices along its first and second dimension (fig. 1). Thus, array A can be described as a block array the elements of which are matrices, and its size can be denoted by (4doOCo5)doOCo3.MULTIPROD can be also described as a generalization of the built-in function TIMES. While TIMES operates element-by-element multiplications (e.g. A .* B), MULTIPROD operates block-by-block matrix multiplications.EXAMPLESLet's say thatA is (2doOCo5)doOCo6, andB is (5doOCo3)doOCo6.With MULTIPROD the six matrices in A can be multiplied by those in B in a single intuitively appealing step:C = MULTIPROD(A, B). where C is (2doOCo3)doOCo6.By automatically applying AX, MULTIPROD can multiply a single matrix by all the blocks of a block array. So, ifA is 2doOCo5 (single matrix), andB is (5doOCo3)doOCo1000doOCo10,then C = MULTIPROD(A, B) yields a (2doOCo3)doOCo1000doOCo10 array. A is virtually expanded to a (2doOCo5)doOCo1000doOCo10 size, then multi-multiplied by B. This is done without using loops, and without actually replicating the matrix (see Appendix A). We refer to this particular application of AX as virtual matrix expansion. In a system running MATLAB R2008a, MULTIPROD performs it about 380 times faster than the following equivalent loop (see Appendix B):for i = 1:1000 for j = 1:10 C(:,:,i,j) = A * B(:,:,i,j); endendAX generalizes matrix expansion to multidimensional arrays of any size. For instance, if A is (2doOCo5)doOCo10, andB is (5doOCo3)doOCo1doOCo6,then C = MULTIPROD(A, B) multiplies each of the 10 matrices in A by each of the 6 matrices in B, obtaining 60 matrices stored in a (2doOCo3)doOCo10doOCo6 array C. It does that by virtually expanding A to (2doOCo5)doOCo10doOCo6, and B to (5doOCo3)doOCo10doOCo6. A detailed definition of AX is provided in the manual.APPLICATIONSMULTIPROD has a broad field of potential applications. By calling MULTIPROD, multiple geometrical transformations such as rotations or roto-translations can be performed on large arrays of vectors in a single step and with no loops. Multiple operations such as normalizing an array of vectors, or finding their projection along the axes indicated by another array of vectors can be performed easily, with no loops and with two or three rows of code.Sample functions performing some of these tasks by calling MULTIPROD are included in the separate toolbox "Vector algebra for multidimensional arrays of vectors" (MATLAB Central, file #8782).OPTIMIZATION AND TESTINGSince I wanted to be of service to as many people as possible, MULTIPROD was designed, debugged, and optimized for speed and memory efficiency with extreme care. Precious advices by Jinhui Bai (Georgetown University) helped me to make it even faster, more efficient and more versatile. Suggestions to improve it further will be welcome. The code ("testMULTIPROD.m") I used to systematically test the function output is included in this package.THE ARRAYLAB TOOLBOXIn sum, MULTIPROD is a generalization for N-D arrays of the matrix multiplication function MTIMES, with AX enabled.Vector inner, outer, and cross products generalized for N-D arrays and with AX enabled are performed by DOT2, OUTER, and CROSS2 (MATLAB Central, file #8782, http://www.mathworks.com/matlabcentral/fileexchange/8782).Element-by-element multiplications (see TIMES) and other elementwise binary operations (such as PLUS and EQ) with AX enabled are performed by BAXFUN (MATLAB Central, file #23084, http://www.mathworks.com/matlabcentral/fileexchange/23084).Together, these functions make up the d-deDUARRAYLAB toolboxd-deDt. I hope that The MathWorks will include it in the next version of MATLAB.MULTITRANSPThis package includes the function MULTITRANSP, performing multiple matrix transpositions. B = MULTITRANSP(A, DIM) transposes all the matrices contained along dimensions DIM and DIM+1 of A.

 Requirements: No special requirements Platforms: Matlab Keyword: Functions,  Included,  Performing,  Projection,  Sample,  Separate,  Tasks Users rating: 0/10