Detailed description |
When calculating the sum of sparseVector's the result seems to be wrong. It looks like that the positions, where the additions were done, is mixed up. When casting to a vector the result is correct.
library(Matrix)
x <- sparseVector(numeric(1), 1, length=200)
i <- 1:16*12
y1 <- sparseVector(1:3, 13:15, 16)
y2 <- sparseVector(1:6, c(5, 6, 7, 9, 14, 15), 16)
y3 <- sparseVector(1:9, 7:15, 16)
x[i] <- x[i] + y1
x[i] <- x[i] + y2
x[i]
# [1] . . . . 1 2 3 . 4 . . . 1 7 9 .
y3
# [1] . . . . . . 1 2 3 4 5 6 7 8 9 .
x[i] + y3 #gives wrong result
# [1] . . . . 1 2 8 2 12 4 5 6 10 12 10 .
as.vector(x[i]) + y3 #gives correct result
# [1] . . . . 1 2 4 2 7 4 5 6 8 15 18 .
sessionInfo()
#R version 3.6.2 (2019-12-12)
#Platform: x86_64-pc-linux-gnu (64-bit)
#Running under: Debian GNU/Linux 10 (buster)
#
#other attached packages:
#[1] Matrix_1.2-18 |
|