RfastOfficial / Rfast

A collection of Rfast functions for data analysis. Note 1: The vast majority of the functions accept matrices only, not data.frames. Note 2: Do not have matrices or vectors with have missing data (i.e NAs). We do no check about them and C++ internally transforms them into zeros (0), so you may get wrong results. Note 3: In general, make sure you give the correct input, in order to get the correct output. We do no checks and this is one of the many reasons we are fast.
139 stars 19 forks source link

mat.mult produces wrong results #27

Closed linliu-stats closed 4 years ago

linliu-stats commented 4 years ago

While I'm trying to use mat.mult instead of %*% to do matrix multiplication, I get wrong results. Please see the following as an example:

library(Rfast) Loading required package: Rcpp Loading required package: RcppZiggurat a <- matrix(c(1,2,3,4,5,6),3,2) b <- matrix(c(1,2,3,4),2,2) mat.mult(a,b) [,1] [,2] [1,] 9 19 [2,] 12 26 a %*% b [,1] [,2] [1,] 11 23 [2,] 10 24 [3,] 14 30

What's interesting is that I don't have such a problem two months ago the last time I used mat.mult. Any help will be appreciated.

linliu-stats commented 4 years ago

Also, it seems that mat.mult changes the result from time to time...

a [,1] [,2] [1,] 1 4 [2,] 2 5 [3,] 3 6 b [,1] [,2] [1,] 1 3 [2,] 2 4 mat.mult(a, b) [,1] [,2] [1,] 9 19 [2,] 12 26 mat.mult(a, b) [,1] [,2] [1,] 11 23 [2,] 10 24 mat.mult(a, b) [,1] [,2] [1,] 7 15 [2,] 9 23 mat.mult(a, b) [,1] [,2] [1,] 5 11 [2,] 11 25 mat.mult(a, b) [,1] [,2] [1,] 9 19 [2,] 12 26

statlink commented 4 years ago

We know this is wrong and we will fix it. This mistake has been pointed out by other users as well.