Browse Source

ue01 notebook

master
Tom 3 years ago
parent
commit
e9f07c38fb
7 changed files with 363 additions and 1 deletions
  1. +154
    -0
      ue01/.ipynb_checkpoints/Untitled-checkpoint.ipynb
  2. +11
    -0
      ue01/.ipynb_checkpoints/sum1-checkpoint.R
  3. +10
    -0
      ue01/.ipynb_checkpoints/sum2-checkpoint.R
  4. +14
    -0
      ue01/.ipynb_checkpoints/sum2-checkpoint.c
  5. +19
    -0
      ue01/.ipynb_checkpoints/time_sum-checkpoint.R
  6. +154
    -0
      ue01/Untitled.ipynb
  7. +1
    -1
      ue01/sum2.c

+ 154
- 0
ue01/.ipynb_checkpoints/Untitled-checkpoint.ipynb
File diff suppressed because it is too large
View File


+ 11
- 0
ue01/.ipynb_checkpoints/sum1-checkpoint.R View 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
- 0
ue01/.ipynb_checkpoints/sum2-checkpoint.R View 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
- 0
ue01/.ipynb_checkpoints/sum2-checkpoint.c View 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
- 0
ue01/.ipynb_checkpoints/time_sum-checkpoint.R View 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))
}

+ 154
- 0
ue01/Untitled.ipynb
File diff suppressed because it is too large
View File


+ 1
- 1
ue01/sum2.c View File

@ -1,5 +1,5 @@
#include <R.h> #include <R.h>
void sum2(double* mtrx, int* m, int* n, double* res) void sum2(double* mtrx, int* m, int* n, double* res)
{ {
*res = 0; *res = 0;


Loading…
Cancel
Save