-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathget-R-poly-test-vectors.R
More file actions
62 lines (52 loc) · 1.23 KB
/
get-R-poly-test-vectors.R
File metadata and controls
62 lines (52 loc) · 1.23 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
52
53
54
55
56
57
58
59
60
61
62
cat("# This file auto-generated by tools/get-R-poly-test-vectors.R\n")
cat(sprintf("# Using: %s\n", R.Version()$version.string))
cat("import numpy as np\n")
options(digits=20)
library(splines)
x <- (1.5)^(0:19)
MISSING <- "MISSING"
is.missing <- function(obj) {
length(obj) == 1 && obj == MISSING
}
pyprint <- function(arr) {
if (is.missing(arr)) {
cat("None\n")
} else {
cat("np.array([")
for (val in arr) {
cat(val)
cat(", ")
}
cat("])")
if (!is.null(dim(arr))) {
cat(".reshape((")
for (size in dim(arr)) {
cat(sprintf("%s, ", size))
}
cat("), order=\"F\")")
}
cat("\n")
}
}
num.tests <- 0
dump.poly <- function(degree, raw) {
cat("--BEGIN TEST CASE--\n")
cat(sprintf("degree=%s\n", degree))
cat(sprintf("raw=%s\n", raw))
args <- list(x=x, degree=degree, raw=raw)
result <- do.call(poly, args)
cat("output=")
pyprint(result)
cat("--END TEST CASE--\n")
assign("num.tests", num.tests + 1, envir=.GlobalEnv)
}
cat("R_poly_test_x = ")
pyprint(x)
cat("R_poly_test_data = \"\"\"\n")
for (degree in c(1, 3, 5)) {
for (raw in c(TRUE, FALSE)) {
dump.poly(degree, raw)
}
}
cat("\"\"\"\n")
cat(sprintf("R_poly_num_tests = %s\n", num.tests))