-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathguessType.R
More file actions
51 lines (40 loc) · 1.1 KB
/
guessType.R
File metadata and controls
51 lines (40 loc) · 1.1 KB
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
guessTypes =
function(x, types)
{
# vars = all.vars(x)
}
RX =
function(pattern)
structure(pattern, class = "RegularExpression")
ReturnTypeTable =
list(numeric = c("sin", "cos", "log", "sinh", "log", "log10", "logb", "log1p", "exp", "^",
'rexp', 'rnorm', 'runif'),
ScalarNumeric = c('mean', 'median', 'sd', 'var'),
ScalarInteger = c("length", "floor", 'ceiling'),
integer = c("rpois", "rbinom"),
logical = c("duplicated", RX("is.*"), "is"),
ScalarLogical = c("&&", "||", "any", "all", "%in%"))
# Have to separate mode/typeof and the class
SameModeAsInput =
c("diag" )
# unlist() is tricky as we only know the type at run-time
# unless we know the types of each of the inputs.
getTypeOf =
function(call, types)
{
fun = as.character(call[[1]])
a = sapply(ReturnTypeTable, function(x) fun %in% x)
if(any(a))
return(names(ReturnTypeTable)[a])
}
AtomicTypes =
c("numeric" = DoublePtrType,
ScalarNumeric = DoubleType,
integer = Int32PtrType,
ScalarInteger = Int32Type
)
getCTypeOf =
function(rtype)
{
AtomicTypes[[rtype]]
}