Home
Manual
Packages
Global Index
Keywords
Quick Reference

2.3.8 Marking an index for matrix multiplication
Yorick has a special syntax for matrix multiplication, or, more
generally, inner product:
 A(,+)*B(+,)
B(+,)*A(,+)
x(+)*y(+)
P(,+,,)*Q(,,+)

In the first example, A would be an LbyM array, B would be
an MbyN array, and the result would be the LbyN matrix product. In
the second example, the result would be the NbyL 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 4D array P with the third
dimension of the 3D array Q. If P were 2by3by4by5
and Q were 6by7by3, the result array would be
2by4by5by6by7.
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 elementbyelement 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.
