RfastOfficial/Rfast

Occasional issue with eachrow function

ldkregar opened this issue · 1 comments

Using eachrow to multiply a matrix by a vector returns incorrect results, for some reason the values approach 0. Code below, result should be identical to sweep_res.

Console input

mat <- matrix(c(1:12), 3)
mat
some_vector <- rep(2, 4)
sweep_res <- sweep(mat, 2, some_vector, "*")
sweep_res
rfast_res <- Rfast::eachrow(mat, some_vector, "*")
rfast_res

Console output

mat <- matrix(c(1:12), 3)
mat
[,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12
some_vector <- rep(2, 4)
sweep_res <- sweep(mat, 2, some_vector, "*")
sweep_res
[,1] [,2] [,3] [,4]
[1,] 2 8 14 20
[2,] 4 10 16 22
[3,] 6 12 18 24
rfast_res <- Rfast::eachrow(mat, some_vector, "*")
rfast_res
[,1] [,2] [,3] [,4]
[1,] 8.487983e-314 3.395193e-313 1.388910e-309 1.388912e-309
[2,] 1.697597e-313 4.243992e-313 5.741465e-14 1.388911e-309
[3,] 2.546395e-313 5.092790e-313 6.365987e-314 1.388911e-309

R version 4.3.0 (2023-04-21)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.6.1
Rfast_2.0.8

For now you have to convert the data to numeric because we don't test for integers.

mat <- matrix(as.numeric(c(1:12)), 3) > some_vector <- as.numeric(rep(2, 4)) > Rfast::eachrow(mat,some_vector,"*")