tensorprod: Product of two arrays

View source: R/tensorprod.R

tensorprodR Documentation

Product of two arrays

Description

Consistent with tensor() function in tensor package, or ttl() in rTensor package.

Usage

tensorprod(
  A,
  B,
  alongA = integer(0),
  alongB = integer(0),
  path = tempfile(),
  meta_name = "farray.meta"
)

Arguments

A, B

an array or farray

alongA, alongB

integers; margins in A and B to be collapsed.

path, meta_name

where to store the results; see farray.

Details

It is highly recommended that A is a small array and B is a large array. The performance if highly related to how alongB is assigned. If all the fast margins (see is_fast_margin) are contained within alongB, then there is no memory optimization, and the whole calculation occurs in the memory. If at least one fast margin is not in alongB, then the calculation is memory optimized.

Value

A farray object.

Author(s)

Zhengjia Wang

Examples


x <- matrix(1:12, ncol = 4)
y <- array(rnorm(120), c(4,5,6))

# Equivalent to tensor::tensor(x, y, alongA = 2, alongB = 1)
# or rTensor::ttm(rTensor::as.tensor(y), x, m = 1)
tensorprod(x, y, alongA = 2, alongB = 1)


dipterix/farray documentation built on Oct. 16, 2022, 6:13 p.m.