Skip to content

Commit cd66545

Browse files
committed
nodeInstr_nClass and calcInstr_nClass
1 parent 2a67ced commit cd66545

30 files changed

Lines changed: 267 additions & 208 deletions

nCompiler/NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export(NCinternals)
77
export(NFinternals)
88
export(argType2Cpp)
99
export(build_compiled_nClass)
10+
export(calcInstr_nClass)
1011
export(cloglog)
1112
export(check_Rcpp_for_nCompiler)
1213
export(compileNimble)
@@ -81,6 +82,7 @@ export(nList)
8182
export(nLogical)
8283
export(nMatrix)
8384
export(nodeFxnBase_nClass)
85+
export(nodeInstr_nClass)
8486
export(nArray)
8587
export(nOptions)
8688
export(nParse)

nCompiler/R/nimbleModels.R

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,34 @@
1414

1515
## a model will inherit from model_nClass
1616

17+
nodeInstr_nClass <- nClass(
18+
classname = "nodeInstr_nClass",
19+
Cpublic = list(
20+
methodInstr = 'integerVector',
21+
indsInstrVec = "nList('integerVector')"
22+
),
23+
predefined = quote(system.file(file.path("include","nCompiler", "predefined_nClasses"), package="nCompiler") |>
24+
file.path("nodeInstr_nClass")),
25+
compileInfo=list(interface="full",
26+
createFromR = TRUE#,
27+
#predefined_output_dir = "nodeInstr_nClass"
28+
)
29+
)
30+
31+
calcInstr_nClass <- nClass(
32+
classname = "calcInstr_nClass",
33+
Cpublic = list(
34+
nodeIndex = 'integerScalar',
35+
nodeInstrVec = "nList('nodeInstr_nClass')"
36+
),
37+
predefined = quote(system.file(file.path("include","nCompiler", "predefined_nClasses"), package="nCompiler") |>
38+
file.path("calcInstr_nClass")),
39+
compileInfo=list(interface="full",
40+
createFromR = TRUE#,
41+
#predefined_output_dir = "calcInstr_nClass"
42+
)
43+
)
44+
1745
nodeFxnBase_nClass <- nClass(
1846
classname = "nodeFxnBase_nClass",
1947
Cpublic = list(
@@ -24,7 +52,7 @@ nodeFxnBase_nClass <- nClass(
2452
),
2553
calculate = nFunction(
2654
name = "calculate",
27-
function(to_do = integer(1)) {return(0); returnType(double())},
55+
function(nodeInstr = 'nodeInstr_nClass') {return(0); returnType(double())},
2856
compileInfo = list(virtual=TRUE)
2957
)
3058
),
@@ -48,7 +76,8 @@ modelBase_nClass <- nClass(
4876
),
4977
calculate = nFunction(
5078
name = "calculate",
51-
function(nodes=SEXP()) {cppLiteral('Rprintf("modelBase_nClass calculate (should not see this)\\n");')},
79+
function(calcInstr='calcInstr_nClass') {cppLiteral('Rprintf("modelBase_nClass calculate (should not see this)\\n");'); return(0)},
80+
returnType = 'numericScalar',
5281
compileInfo = list(virtual=TRUE)
5382
)
5483
),

nCompiler/R/symbolTable.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ symbolTBD <- R6::R6Class(
189189
stop("Trying to generate a C++ type from a TBD type ('",
190190
self$name,
191191
"' of type '",
192-
self$type, "'.")
192+
self$type, "').")
193193
}
194194
)
195195
)

nCompiler/R/typeDeclarations.R

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
## each entry in the typeDeclarationList
32
## gives a function to convert the arguments of a
43
## type declaration into a symbol object.
@@ -237,7 +236,7 @@ typeDeclarationList <- list(
237236
RcppFunction = function(...) {
238237
symbolRcppType$new(RcppType = "Rcpp::Function", ...)
239238
},
240-
239+
241240
## RcppEigen RcppTypes
242241
RcppEigenMatrixXd = function(...) {
243242
symbolRcppType$new(RcppType = "Eigen::MatrixXd", ...)
@@ -257,7 +256,7 @@ typeDeclarationList <- list(
257256
RcppEigenVectorXcd = function(...) {
258257
symbolRcppType$new(RcppType = "Eigen::VectorXcd", ...)
259258
},
260-
259+
261260
## Sparse types
262261
nSparseMatrix = function(value,
263262
...,
@@ -290,7 +289,7 @@ typeDeclarationList <- list(
290289
nDim <= 6))
291290
stop(paste0("Invalid number of dimensions used to declare a.nCompiler ",
292291
"argument. Dimensions from 0-6 are allowed."),
293-
call. = FALSE)
292+
call. = FALSE)
294293
nType(scalarType, nDim)
295294
},
296295
CppVar = function(...) { # symbolBaseArgs will be passed to symbolBase$initialize
@@ -351,12 +350,12 @@ argType2symbol <- function(argType,
351350
## allow e.g. 'scalarInteger' to become scalarInteger()
352351
if(is.name(typeToUse))
353352
typeToUse <- as.call(list(typeToUse))
354-
353+
355354
## argType could be a blank
356355
if(is.name(argType))
357356
if(as.character(argType)=="")
358357
argType <- NULL
359-
358+
360359
ans <- try({
361360
## TO-DO: Case 1: It is a nType object
362361
## To be implemented
@@ -427,8 +426,8 @@ argType2symbol <- function(argType,
427426
## Case 3: It is a nClass type or possibly other "to-be-determined" type.
428427
## We defer type lookup until compiler stage labelAbstractTypes
429428
if(inputAsCharacter) {
430-
symbol <- symbolTBD$new(name = name,
431-
type = funName,
429+
symbol <- symbolTBD$new(name = name,
430+
type = funName,
432431
isArg = isArg)
433432
} else {
434433
## Case 4: Type can be determined by evaluating the default
@@ -461,7 +460,7 @@ argType2symbol <- function(argType,
461460
call.=FALSE)
462461
}
463462
if(isTRUE(symbol$isRef)) {
464-
463+
465464
}
466465
nErrorEnv$.isRef_has_been_set <- FALSE
467466
nErrorEnv$.isBlockRef_has_been_set <- FALSE
@@ -515,7 +514,7 @@ argTypeList2symbolTable <- function(argTypeList,
515514
}
516515
if(is.null(names(isArg)))
517516
names(isArg) <- names(argTypeList)
518-
517+
519518
## Check that isRef is valid
520519
if(!is.list(isRef)) {
521520
ok <- FALSE
@@ -617,11 +616,19 @@ resolveOneTBDsymbol <- function(symbol, env = parent.frame()) {
617616
NCgenerator = candidate)
618617
return(newSym)
619618
}
619+
} else if(inherits(symbol, "symbolNlist")) {
620+
elementSym <- symbol$elementSym
621+
if(inherits(elementSym, "symbolTBD")) {
622+
elementSym <- resolveOneTBDsymbol(elementSym, env)
623+
newSym <- symbol$clone(deep=TRUE)
624+
newSym$elementSym <- elementSym
625+
return(newSym)
626+
}
620627
}
621628
symbol #return unmodified symbol if nothing to do
622629
}
623630

624-
resolveTBDsymbols <- function(symTab,
631+
resolveTBDsymbols <- function(symTab,
625632
env = parent.frame()) {
626633
for(i in seq_along(symTab$symbols)) {
627634
symTab$symbols[[i]] <- resolveOneTBDsymbol(symTab$symbols[[i]], env)

nCompiler/inst/include/nCompiler/predefined_nClasses/calcInstr_nClass/calcInstr_nClass_copyFiles.txt

Whitespace-only changes.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* OPENER (Do not edit this comment) */
2+
#ifndef __calcInstr_nClass_CPP
3+
#define __calcInstr_nClass_CPP
4+
/* BODY (Do not edit this comment) */
5+
#ifndef R_NO_REMAP
6+
#define R_NO_REMAP
7+
#endif
8+
#include <iostream>
9+
#include "calcInstr_nClass_c_.h"
10+
using namespace Rcpp;
11+
// [[Rcpp::plugins(nCompiler_Eigen_plugin)]]
12+
// [[Rcpp::depends(RcppParallel)]]
13+
// [[Rcpp::depends(nCompiler)]]
14+
// [[Rcpp::depends(Rcereal)]]
15+
16+
calcInstr_nClass::calcInstr_nClass ( ) {
17+
RESET_EIGEN_ERRORS
18+
}
19+
20+
// [[Rcpp::export(name = "new_calcInstr_nClass")]]
21+
SEXP new_calcInstr_nClass ( ) {
22+
RESET_EIGEN_ERRORS
23+
return CREATE_NEW_NCOMP_OBJECT(calcInstr_nClass);;
24+
}
25+
26+
// [[Rcpp::export(name = "set_CnClass_env_new_calcInstr_nClass")]]
27+
void set_CnClass_env_calcInstr_nClass ( SEXP env ) {
28+
RESET_EIGEN_ERRORS
29+
SET_CNCLASS_ENV(calcInstr_nClass, env);;
30+
}
31+
32+
// [[Rcpp::export(name = "get_CnClass_env_new_calcInstr_nClass")]]
33+
Rcpp::Environment get_CnClass_env_calcInstr_nClass ( ) {
34+
RESET_EIGEN_ERRORS
35+
return GET_CNCLASS_ENV(calcInstr_nClass);;
36+
}
37+
38+
NCOMPILER_INTERFACE(
39+
calcInstr_nClass,
40+
NCOMPILER_FIELDS(
41+
field("nodeIndex", &calcInstr_nClass::nodeIndex),
42+
field("nodeInstrVec", &calcInstr_nClass::nodeInstrVec)
43+
),
44+
NCOMPILER_METHODS()
45+
)
46+
#endif
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
calcInstr_nClass_c_
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* OPENER (Do not edit this comment) */
2+
#ifndef __calcInstr_nClass_H
3+
#define __calcInstr_nClass_H
4+
/* BODY (Do not edit this comment) */
5+
#ifndef R_NO_REMAP
6+
#define R_NO_REMAP
7+
#endif
8+
#include <Rinternals.h>
9+
10+
class calcInstr_nClass : public interface_resolver< genericInterfaceC<calcInstr_nClass> >, public loadedObjectHookC<calcInstr_nClass> {
11+
public:
12+
calcInstr_nClass ( ) ;
13+
int nodeIndex;
14+
nList<std::shared_ptr<nodeInstr_nClass> > nodeInstrVec;
15+
};
16+
17+
SEXP new_calcInstr_nClass ( ) ;
18+
19+
void set_CnClass_env_calcInstr_nClass ( SEXP env ) ;
20+
21+
Rcpp::Environment get_CnClass_env_calcInstr_nClass ( ) ;
22+
23+
24+
#endif
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
list(saved_at = structure(1762351302.27482, class = c("POSIXct",
2+
"POSIXt")), packet_name = "calcInstr_nClass", elements = c("preamble",
3+
"cppContent", "hContent", "filebase", "post_cpp_compiler", "copyFiles"
4+
), files = list(preamble = "calcInstr_nClass_preamble.cpp", cppContent = "calcInstr_nClass_cppContent.cpp",
5+
hContent = "calcInstr_nClass_hContent.h", filebase = "calcInstr_nClass_filebase.txt",
6+
post_cpp_compiler = "calcInstr_nClass_post_cpp_compiler.txt",
7+
copyFiles = "calcInstr_nClass_copyFiles.txt"))

nCompiler/inst/include/nCompiler/predefined_nClasses/calcInstr_nClass/calcInstr_nClass_post_cpp_compiler.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)