20 lines
441 B
R
20 lines
441 B
R
|
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)
|
||
|
}
|