yorick banner




Global Index


Quick Reference

Back: Rubber-Index Forward: Statistical   FastBack: Interpolating Up: Indexing FastForward: Sorting         Top: Yorick Contents: Table of Contents Index: Concept Index About: About this document

2.3.8 Marking an index for matrix multiplication

Yorick has a special syntax for matrix multiplication, or, more generally, inner product:


In the first example, A would be an L-by-M array, B would be an M-by-N array, and the result would be the L-by-N matrix product. In the second example, the result would be the N-by-L transpose of the first result. The general rule is that all of the "spectator" dimensions of the left operand precede the spectator dimensions of the right operand in the result.

The third example shows how to form the inner product of two vectors x and y of equal length. The fourth example shows how to contract the second dimension of a 4-D array P with the third dimension of the 3-D array Q. If P were 2-by-3-by-4-by-5 and Q were 6-by-7-by-3, the result array would be 2-by-4-by-5-by-6-by-7.

Unlike all of the other special subscript symbols (nil, -, .., and * so far), the + sign marking an index for use in an inner product is actually treated specially by the Yorick parser. The + subscript is a parse error unless the array (or expression) being subscripted is the left or right operand of a binary * operator, which is then parsed as matrix multiplication instead of Yorick's usual element-by-element multiplication. A parse error will also result if only one of the operands has a dimension marked by +. Both operands must have exactly one marked dimension, and the marked dimensions must turn out to be of equal length at run time.