(A <- ktensor(spray(matrix(c(1,1,2,2,3,3),2,3,byrow=TRUE),1:2)))
(B <- ktensor(spray(10+matrix(4:9,3,2),5:7)))
tensorprod(A,B)
A %X% B - B %X% A
Va <- matrix(rnorm(9),3,3)
Vb <- matrix(rnorm(38),19,2)
LHS <- as.function(A %X% B)(cbind(rbind(Va,matrix(0,19-3,3)),Vb))
RHS <- as.function(A)(Va) * as.function(B)(Vb)
c(LHS=LHS,RHS=RHS,diff=LHS-RHS)
Run the code above in your browser using DataLab