MATRIX_MULTIPLY

The MATRIX_MULTIPLY function calculates the IDL # operator of two (possibly transposed) arrays. The transpose operation (if desired) is done simultaneously with the multiplication, thus conserving memory and increasing the speed of the operation. If the arrays are not transposed, then MATRIX_MULTIPLY is equivalent to using the # operator.

The # Operator vs. MATRIX_MULTIPLY

The following table illustrates how various operations are performed using the # operator versus the MATRIX_MULTIPLY function:

# Operator

Function

A # B

matrix_multiply(A, B)

transpose(A) # B

matrix_multiply(A, B, /ATRANSPOSE)

A # transpose(B)

matrix_multiply(A, B, /BTRANSPOSE)

transpose(A) # transpose(B)

matrix_multiply(A, B, /ATRANSPOSE, /BTRANSPOSE)

Note: MATRIX_MULTIPLY can also be used in place of the ## operator. For example, A ## B is equivalent to MATRIX_MULTIPLY(B, A), and A ## TRANSPOSE(B) is equivalent to MATRIX_MULTIPLY(BA, /ATRANSPOSE).

Note: MATRIX_MULTIPLY will invoke BLAS_GEMM for floating-point and complex inputs.

Syntax

Result = MATRIX_MULTIPLY( A, B [, /ATRANSPOSE] [, /BTRANSPOSE] [, /NAN])

Return Value

The type for the result depends upon the input type. For byte or integer arrays, the result has the type of the next-larger integer type that could contain the result (for example, byte, integer, or long input returns type long integer). For floating-point, the result has the same type as the input.

For the case of no transpose, the resulting array has the same number of columns as the first array and the same number of rows as the second array. The second array must have the same number of columns as the first array has rows.

Note: If A and B arguments are vectors, then C = MATRIX_MULTIPLY(A, B) is a matrix with Cij = AiBj. Mathematically, this is equivalent to the outer product, usually denoted by AÄB.

Arguments

A

The left operand for the matrix multiplication. Dimensions higher than two are ignored.

B

The right operand for the matrix multiplication. Dimensions higher than two are ignored.

Keywords

ATRANSPOSE

Set this keyword to multiply using the transpose of A.

BTRANSPOSE

Set this keyword to multiply using the transpose of B.

NAN

Set this keyword to cause the routine to check for occurrences of the IEEE floating-point values NaN or Infinity in the input data. Elements with the value NaN or Infinity are treated as equal to zero.

Thread Pool Keywords

This routine is written to make use of IDL’s thread pool, which can increase execution speed on systems with multiple CPUs. The values stored in the !CPU system variable control whether IDL uses the thread pool for a given computation. In addition, you can use the thread pool keywords TPOOL_MAX_ELTS, TPOOL_MIN_ELTS, and TPOOL_NOTHREAD to override the defaults established by !CPU for a single invocation of this routine. See Thread Pool Keywords for details.

Note: For integer inputs the threading is performed by dividing the right operand (B) into blocks of rows (or columns if BTRANSPOSE is set). If your B operand is a one-dimensional vector array then threading will not be used.

Version History

5.4

Introduced

9.0

Added NAN keyword

See Also

MATRIX_POWER, BLAS_GEMM