Last active
April 3, 2018 08:39
-
-
Save randompast/4de740060c7df8f3afd9f5c5a00c6d9d to your computer and use it in GitHub Desktop.
Slow implementation of convolve in chapel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Random; | |
use LinearAlgebra; | |
proc rand(D: int, seed : int, mag: real):[1..D] real { | |
var X: [1..D] real; | |
fillRandom(X, seed, algorithm=RNG.NPB); | |
return mag*(2*X-1); | |
} | |
proc conv(A: [?D1] real, K: [?D2] real) { | |
var B: [1..(A.size - K.size)] real; | |
/*[i in 1..B.size] B[i] = dot(A[i..(i+K.size-1)], K);*/ | |
/*12.029s*/ | |
/*[i in 1..B.size] B[i] = + reduce (A[i..(i+K.size-1)] * K);*/ | |
/*8.923s*/ | |
/*for i in 1..B.size { | |
var s = 0.0; | |
for j in 1..K.size { | |
s += A[i+j-1] * K[j]; | |
} | |
B[i] = s; | |
}*/ | |
/*5.778s*/ | |
/*Check first 5 elements are equivalent*/ | |
/*writeln(B[1..5]);*/ | |
return B; | |
} | |
var X = rand(1000000, 1, 1); | |
var K : [1..100] real; | |
K = 1/100.0; | |
conv(X,K); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment