ue01 notebook
This commit is contained in:
154
ue01/.ipynb_checkpoints/Untitled-checkpoint.ipynb
Normal file
154
ue01/.ipynb_checkpoints/Untitled-checkpoint.ipynb
Normal file
File diff suppressed because one or more lines are too long
11
ue01/.ipynb_checkpoints/sum1-checkpoint.R
Normal file
11
ue01/.ipynb_checkpoints/sum1-checkpoint.R
Normal file
@@ -0,0 +1,11 @@
|
||||
sum1 <- function(m) {
|
||||
res = 0
|
||||
|
||||
for(i in 1:dim(m)[1]) {
|
||||
for(j in 1:dim(m)[2]) {
|
||||
res <- res + m[i,j]
|
||||
}
|
||||
}
|
||||
|
||||
return(res)
|
||||
}
|
10
ue01/.ipynb_checkpoints/sum2-checkpoint.R
Normal file
10
ue01/.ipynb_checkpoints/sum2-checkpoint.R
Normal file
@@ -0,0 +1,10 @@
|
||||
sum2 <- function(m) {
|
||||
res = .C("sum2"
|
||||
,mtrx=as.double(m)
|
||||
,m=as.integer(dim(m)[1])
|
||||
,n=as.integer(dim(m)[2])
|
||||
,res=as.double(0)
|
||||
)
|
||||
|
||||
return(res$res)
|
||||
}
|
14
ue01/.ipynb_checkpoints/sum2-checkpoint.c
Normal file
14
ue01/.ipynb_checkpoints/sum2-checkpoint.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <R.h>
|
||||
dyn.load("sum2.so")
|
||||
|
||||
void sum2(double* mtrx, int* m, int* n, double* res)
|
||||
{
|
||||
*res = 0;
|
||||
|
||||
for(int i=0; i < *n; i++)
|
||||
{
|
||||
for(int j=0; j < *m; j++) {
|
||||
*res += mtrx[j * (*n) + i];
|
||||
}
|
||||
}
|
||||
}
|
19
ue01/.ipynb_checkpoints/time_sum-checkpoint.R
Normal file
19
ue01/.ipynb_checkpoints/time_sum-checkpoint.R
Normal file
@@ -0,0 +1,19 @@
|
||||
source("sum1.R")
|
||||
source("sum2.R")
|
||||
|
||||
comp_sum_funcs <- function(sizes){
|
||||
msizes = c()
|
||||
times_1 = c()
|
||||
times_2 = c()
|
||||
|
||||
for(i in sizes) {
|
||||
m <- matrix(rnorm(i^2), i)
|
||||
|
||||
times_1 = append(times_1, summary(system.time(sum1(m)))[1])
|
||||
times_2 = append(times_2, summary(system.time(sum2(m)))[1])
|
||||
msizes = append(msizes, i)
|
||||
}
|
||||
|
||||
return(data.frame(size=msizes, sum_1 = times_1, sum_2 = times_2))
|
||||
}
|
||||
|
Reference in New Issue
Block a user