mult: Callback-based Multiplication of Matrices

View source: R/mult.R

multR Documentation

Callback-based Multiplication of Matrices

Description

Perform a custom multiplication of the matrices x and y by using the callback function f.

Usage

mult(x, y, f, ...)

Arguments

x

A first matrix. The number of columns must match with the number of rows of the y matrix.

y

A second matrix. The number of rows must match with the number of columns of the x matrix.

f

A function to be applied to the matrices in order to compute the multiplication. It must accept at least two arguments.

...

Additional arguments that are passed to the function f.

Details

For a matrix x of size (u,v) and a matrix y of size (v,w), mult calls the function f uw-times to create a resulting matrix of size (u,w). Each (i,j)-th element of the resulting matrix is obtained from a call of the function f with x's i-th row and y's j-th column passed as its arguments.

Value

A matrix with v rows and w columns, where v is the number of rows of x and w is the number of columns of y.

Author(s)

Michal Burda

See Also

compose()

Examples

    x <- matrix(runif(24, -100, 100), ncol=6)
    y <- matrix(runif(18, -100, 100), nrow=6)

    mult(x, y, function(xx, yy) sum(xx * yy)) # the same as "x %*% y"


lfl documentation built on Sept. 8, 2022, 5:08 p.m.

Related to mult in lfl...