# NOT RUN {
# two sparse matrices with row names
X <- rSparseMatrix(1e4, 1e3, 1e4)
Y <- rSparseMatrix(1e4, 1e3, 1e4)
rownames(X) <- 1:nrow(X)
rownames(Y) <- 1:nrow(Y)
# the basic KhatriRao product is very fast
# but almost all rows are empty
system.time(M <- KhatriRao(X, Y))
# }
# NOT RUN {
sum(rowSums(M)==0)/nrow(M) # 99.9% empty rows
# }
# NOT RUN {
# To produce all row names takes a long time
# with 1e8 row names it took half an hour on my laptop
# so: don't try the following, except on a very large machine!
# }
# NOT RUN {
system.time(M <- KhatriRao(X, Y, make.dimnames = TRUE))
# }
# NOT RUN {
# Using the current special version works just fine and is reasonably quick
system.time(M <- rKhatriRao(X, Y))
# }
Run the code above in your browser using DataLab