Skip to contents

Creates a labeled array (tensor) from an array. %_% and tensor() serve the same purpose, but typically usage of %_% is preferred due to brevity. tensor() is exported to provide a standard-evaluation interface as well which might be useful under some circumstances.

Usage

tensor(a, index_names, index_positions)

a %_% i

Arguments

a

An array or any object that can be coerced to an array via as.array().

index_names

A character vector of index names / labels.

index_positions

A character vector of index positions with two allowed values "+" and "-", for "upper" and "lower" position respectively. The length of index_positions needs to agree with the length of index_names.

i

An index slot label specification created with .().

Value

A labeled tensor object of class "tensor", an array() with attached dimension labels. Note that the index structure of the resulting tensor does not necessarily have to match i. In case implicit calculations are already triggered (e.g. contractions) the index structure reflects the resulting tensor.

Examples

a <- array(1:4, dim = c(2, 2))
a %_% .(i, j)
#> <Labeled Array> [2x2] .(-i, -j)
#>      [,1] [,2]
#> [1,]    1    3
#> [2,]    2    4