-
Notifications
You must be signed in to change notification settings - Fork 10
/
mkCallProxy.R
56 lines (46 loc) · 1.54 KB
/
mkCallProxy.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
library(Rllvm)
if(FALSE) {
library(Rllvm)
source("mkCallProxy.R")
m = parseIR("explorations/dnormLoop.ir")
proxy = mkCallProxy(m$v_dnorm)
b = getBlocks(proxy)
ee = ExecutionEngine(m)
fptr = getPointerToFunction(proxy, ee)@ref
sym = list(name = "r_v_dnorm", address = structure(fptr, class = "NativeSymbol"), dll = NULL)
x = seq(-1.5, 1.5, by = .1)
y = .Call(sym, x, length(x), 0.1, 1.2)
fun = function(x, mu, sd) { tmp = (x-mu)/sd; 1/(sd*2.506628)*exp(-.5*tmp*tmp)}
stopifnot(identical(y, fun(x, .1, 1.2)))
}
if(FALSE) {
library(Rllvm)
source("mkCallProxy.R")
m = parseIR("explorations/proxyEg.ir")
proxy = mkCallProxy(m$foo)
b = getBlocks(proxy)
ee = ExecutionEngine(m)
fptr = getPointerToFunction(proxy, ee)@ref
sym = list(name = "", address = structure(fptr, class = "NativeSymbol"), dll = NULL)
# x = seq(-1.5, 1.5, by = .1)
x = 1:10
y = seq_len(length(x)) + .5
z = .Call(sym, x, y, length(x))
stopifnot( identical(z, sum(x*y)) )
}
if(FALSE) {
library(Rllvm)
source("mkCallProxy.R")
m = parseIR("explorations/proxyEg.ir")
proxy = mkCallProxy(m$bar)
b = getBlocks(proxy)
ee = ExecutionEngine(m)
fptr = getPointerToFunction(proxy, ee)@ref
sym = list(name = "", address = structure(fptr, class = "NativeSymbol"), dll = NULL)
# x = seq(-1.5, 1.5, by = .1)
x = 1:10
y = seq_len(length(x)) + .5
z = .Call(sym, x, y, length(x))
stopifnot( identical(z[[1]], sum(x*y)),
identical(x*y, z[[2]]))
}