Add values to an existing sparse column in place
Source:R/add_assign_col_inplace.R
add_assign_col_inplace.RdAdds value to the existing nonzero entries of column j at rows i.
Only existing nonzeros are updated; no new nonzeros are created.
add_assign_col_inplace_unsafe skips the input validation performed by
add_assign_col_inplace.
When validate = TRUE, the function checks that i is strictly
increasing, in range, and contains no NA; that value contains no NA/NaN;
and that the column pointer p is nondecreasing.
Usage
add_assign_col_inplace(x, i, j, value, validate = TRUE)
add_assign_col_inplace_unsafe(x, i, j, value)Examples
if (requireNamespace("Matrix", quietly = TRUE)) {
x <- Matrix::Matrix(0, nrow = 4, ncol = 2, sparse = TRUE)
x[1, 1] <- 1
x[3, 1] <- 2
# value is the same length as i
add_assign_col_inplace(x, i = c(1L, 3L), j = 1L, value = c(10, -5))
}
#> 4 x 2 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 11 .
#> [2,] . .
#> [3,] -3 .
#> [4,] . .