Fast computation of all pairwise element-wise column products of a matrix.

pairwise_Schur_product(x, self = FALSE)

Arguments

x

A matrix with dimensions r*c.

self

A logical that determines whether a column should also be multiplied by itself.

Value

A matrix with the same number of rows as x and a number of columns corresponding to c choose 2 (+ c if self is TRUE), where c is the number of columns of x.

Details

Note that the output order of columns corresponds to the order of the columns in x. First column 1 is multiplied with each of the other columns, then column 2 with the remaining columns etc.

Examples

X <- cbind(rep(1, 4), 1:4, 4:1) pairwise_Schur_product(X)
#> [,1] [,2] [,3] #> [1,] 1 4 4 #> [2,] 2 3 6 #> [3,] 3 2 6 #> [4,] 4 1 4
pairwise_Schur_product(X, self=TRUE)
#> [,1] [,2] [,3] [,4] [,5] [,6] #> [1,] 1 1 4 1 4 16 #> [2,] 1 2 3 4 6 9 #> [3,] 1 3 2 9 6 4 #> [4,] 1 4 1 16 4 1