evoalgs-r-practise/w1/mat.R

20 lines
441 B
R
Raw Normal View History

2024-05-06 06:54:48 +00:00
dyn.load("mat.so")
sum1 <- function(matrix) {
result <- 0
for (i in seq_len(nrow(matrix))) {
for (j in seq_len(ncol(matrix))) {
result <- result + matrix[i, j]
}
}
return(result)
}
sum2 <- function(matrix) {
nrow <- nrow(matrix)
ncol <- ncol(matrix)
result <- .C("c_sum_matrix", as.double(matrix), as.integer(nrow), as.integer(ncol), result = double(1))$result
return(result)
}