@@ -33,61 +33,3 @@ test_that("compileNimble bridge works for one nimbleFunction object", {
3333# # add nClass to nCompiler:::compileNimble
3434# #
3535# # document, document, document
36-
37- test_that(" registering a user-defined operator definition (opDef) works" , {
38- # # first version: provide a function
39- nimArrayHandler <- function (code ,... ) {
40- code $ name <- ' nArray'
41- NULL
42- }
43- # This test works by:
44- # providing a handler to relpace "nimArray" with "nArray"
45- # and a handler to replace "nimArray2" with "nArray" to
46- # check on handling multiple cases.
47- registerOpDef(
48- list (nimArray =
49- list (
50- matchDef = function (value = 0 , dim = c(1 ,1 ), init = TRUE ,
51- fillZeros = TRUE , recycle = TRUE , nDim ,
52- type = " double" ) {},
53- # normalizeCalls=list(handler='skip'),
54- simpleTransformations = list (handler = nimArrayHandler ))))
55- expect_equal(ls(`:::`(" nCompiler" , " operatorDefUserEnv" )), " nimArray" )
56-
57- registerOpDef(
58- list (nimArray2 =
59- list (
60- matchDef = function (value = 0 , dim = c(1 ,1 ), init = TRUE ,
61- fillZeros = TRUE , recycle = TRUE , nDim ,
62- type = " double" ) {},
63- simpleTransformations = list (handler = ' replace' ,
64- replacement = ' nArray' ))))
65- expect_equal(ls(`:::`(" nCompiler" , " operatorDefUserEnv" )), c(" nimArray" , " nimArray2" ))
66-
67- nc <- nClass(
68- Cpublic = list (
69- foo = nFunction(
70- function () {
71- ans <- nimArray( 6 , dim = 2 )
72- ans2 <- nArray(value = 5 , dim = 2 )
73- return (ans )
74- returnType(' double(1)' )
75- }
76- ),
77- foo2 = nFunction(
78- function () {
79- ans <- nimArray2(3 ,dim = 2 )
80- return (ans )
81- returnType(' double(1)' )
82- })
83- ))
84- Cnc <- nCompile(nc )
85- obj <- Cnc $ new()
86- expect_identical(obj $ foo(), c(6 , 6 ))
87- expect_identical(obj $ foo2(), c(3 , 3 ))
88- rm(obj ); gc()
89- #
90- deregisterOpDef(" nimArray" )
91- deregisterOpDef(" nimArray2" )
92- expect_equal(length(ls(`:::`(" nCompiler" , " operatorDefUserEnv" ))), 0 )
93- })
0 commit comments