1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
n1 = 5
n2 = 5
p = 6
y = rnorm(n1)
a = rnorm(n1*p)
a[abs(a)<1.0] = 0
A = matrix(a,n1,p)
b = rnorm(n2*p)
b[abs(b)<1.0] = 0
B = matrix(b,n2,p)
A.csr = as.matrix.csr(A)
B.csr = as.matrix.csr(B)
# testing matrix transposition and matrix-matrix multiplication
A.csr%*%t(B.csr)
as.matrix(A.csr%*%t(B.csr))
A%*%t(B)
# testing matrix transposition and matrix-vector multiplication
t(A.csr)%*%y
t(A)%*%y
# testing diag and diag<-
diag(A.csr)
diag(A)
diag(A.csr) <- 99
diag(A) <- 99
as.matrix(A.csr)
A
# testing element-wise addition
A.csr+B.csr
as.matrix(A.csr+B.csr)
A+B
# testing mix-mode multiplication
class(t(A.csr)%*%B)
class(t(A)%*%B.csr)
class(y%*%B.csr)
|