tcrossprod_ij: Compute cross product between two sets of rows of a matrix.

View source: R/sparse.R

tcrossprod_ijR Documentation

Compute cross product between two sets of rows of a matrix.

Description

tcrossprod_ij computes cross product between two sets of rows of a matrix.

Usage

tcrossprod_ij(X, id1, id2)

Arguments

X

matrix

id1

vector of integers specifying the list of rows of X (first set)

id2

vector of integers specifying the list of rows of X, (second set), same length as id1.

Value

matrix containing the cross product of X[id1, ] and X[id2, ].

Examples


set.seed(42)
X <- matrix(rnorm(5 * 3), 5, 3)

id1 <- c(1, 3)
id2 <- c(5, 4)

(s1 <- matric::tcrossprod_ij(X, id1, id2))

(s2 <- tcrossprod(X)[id1, id2])

all.equal(s1, s2)

matric documentation built on April 1, 2023, 12:19 a.m.