Skip to content

Runtime dynamic access#198

Merged
perrydv merged 5 commits into
mainfrom
runtime-dynamic-access
Jun 5, 2026
Merged

Runtime dynamic access#198
perrydv merged 5 commits into
mainfrom
runtime-dynamic-access

Conversation

@perrydv

@perrydv perrydv commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

This PR provides support for obj[[varname]] where obj is an nClass object and varname is a string to access a variable in C++ by name at runtime. This returns an ETaccessorBase (ET is for "Eigen Tensor". "Base" is for "base class".) That object can only be used through an as statement, e.g. as(obj[[varname]], 'numericVector'). Even if obj[[varname]] is not a numericVector, it will be handled as one if possible (i.e. if at runtime it is conformable to a vector, such as a higher dimensional tensor with all but one extent being 1). This PR also extends as to handle true scalar types as the input or output type.

@perrydv

perrydv commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Also this has passed tests under Actions, so I will plan to merge it soon.

@paciorek

paciorek commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Do we have "char" or "string" as a type, e.g.,

function(varname = "string") {
obj[[varname]] ....
}

@perrydv

perrydv commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Yes.

Adding features for vectors (or potentially tensors) of strings is somewhere down the road, but we do have a scalar string type.

@perrydv perrydv merged commit cf61933 into main Jun 5, 2026
5 checks passed
@perrydv perrydv deleted the runtime-dynamic-access branch June 5, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants