This gives all combinations of indices of a tensor with dimension d in the order of the numbers in the memory.

pos.tensor(d)

Arguments

d

a dim attribute of a tensor

Value

a matrix with the same number of rows as the tensor has entries an the same number of columns as the tensor has dimensions. Each row represents the index combination of a the corresponding element.

Details

tensors are stored according to the R-convention that the leftmost index varies fastest.

See also

Author

K.Gerald van den Boogaart

Examples

   (A <- to.tensor(1:20,dim=c(A=2,B=2,C=5)))
#> , , 1
#> 
#>       B
#> A      [,1] [,2]
#>   [1,]    1    3
#>   [2,]    2    4
#> 
#> , , 2
#> 
#>       B
#> A      [,1] [,2]
#>   [1,]    5    7
#>   [2,]    6    8
#> 
#> , , 3
#> 
#>       B
#> A      [,1] [,2]
#>   [1,]    9   11
#>   [2,]   10   12
#> 
#> , , 4
#> 
#>       B
#> A      [,1] [,2]
#>   [1,]   13   15
#>   [2,]   14   16
#> 
#> , , 5
#> 
#>       B
#> A      [,1] [,2]
#>   [1,]   17   19
#>   [2,]   18   20
#> 
#> attr(,"class")
#> [1] "tensor"
   pos.tensor(dim(A))
#>       A B C
#>  [1,] 1 1 1
#>  [2,] 2 1 1
#>  [3,] 1 2 1
#>  [4,] 2 2 1
#>  [5,] 1 1 2
#>  [6,] 2 1 2
#>  [7,] 1 2 2
#>  [8,] 2 2 2
#>  [9,] 1 1 3
#> [10,] 2 1 3
#> [11,] 1 2 3
#> [12,] 2 2 3
#> [13,] 1 1 4
#> [14,] 2 1 4
#> [15,] 1 2 4
#> [16,] 2 2 4
#> [17,] 1 1 5
#> [18,] 2 1 5
#> [19,] 1 2 5
#> [20,] 2 2 5