Issue #185 opened discussion on as, a DSL feature to provide some run-time type flexibility.
PR #195 adds this feature, with updates to what it covers and not.
The best way to see what it currently covers is to work through specificOp_tests/test-as.R.
Broadly:
as(X, type) treats X as type, where type is a basic type such as numericVector.
- This works on the LHS or RHS and should work with any other Eigen operations.
- When
X has a known type, implementation is roughly:
- with same-type scalars (
X and type involve the same scalar element type)
- On RHS or LHS
- with no indexing after the
as(), return an Eigen::TensorMap (e.g. to view a matrix as a vector).
- with indexing after the
as(), return a StridedTensorMap (an Eigen extension in nCompiler)
- with cross-type scalars
- on LHS
- return a "CastingProxy" object that holds an STM for a Proxy copy that is updated on exit (destruction)
- on RHS
- return a "RHSCastProxy" object that holds a TM or STM (if non-indexed or indexed, respectively) and applies a static_cast when accessing elements.
These are all determined from ETaccessorTyped::asTyped, called from nC_as.
Because some cases need a Proxy class to hold a copy of X, all cases are implemented with a proxy layer so that there is a coding standard where an extra () is needed to access the Eigen-compatible object. e.g. nC_as<type>(X)(). (Due to delicacy of Eigen chains going out of scope, the extra () must be local.)
Future steps or to-dos for discussion include:
- Support true scalar types as inputs or target types.
- Allow
as(x, 'integer') to maintain whatever nDim x already has.
- Allow
as(x, 'vector') to maintain whatever scalar type x already has
- Use for argument passing, e.g. to pass one type for another by a copy, ref, or blockRef.
- When
as is on the LHS, we are not also getting the benefit of flex_() assignment. Check on that.
- LHS proxies (also without indexing) might sometimes not need to make the copy upon creation but rather just allocate memory to be assigned into.
Issue #185 opened discussion on
as, a DSL feature to provide some run-time type flexibility.PR #195 adds this feature, with updates to what it covers and not.
The best way to see what it currently covers is to work through
specificOp_tests/test-as.R.Broadly:
as(X, type)treatsXastype, wheretypeis a basic type such asnumericVector.Xhas a known type, implementation is roughly:Xandtypeinvolve the same scalar element type)as(), return anEigen::TensorMap(e.g. to view a matrix as a vector).as(), return aStridedTensorMap(an Eigen extension in nCompiler)These are all determined from
ETaccessorTyped::asTyped, called fromnC_as.Because some cases need a Proxy class to hold a copy of
X, all cases are implemented with a proxy layer so that there is a coding standard where an extra()is needed to access the Eigen-compatible object. e.g.nC_as<type>(X)(). (Due to delicacy of Eigen chains going out of scope, the extra()must be local.)Future steps or to-dos for discussion include:
as(x, 'integer')to maintain whatevernDimxalready has.as(x, 'vector')to maintain whatever scalar typexalready hasasis on the LHS, we are not also getting the benefit offlex_()assignment. Check on that.