Variable@dims currently uses NULL to represent a rank-0 scalar. This is reflected in the class comment, the rank and is_scalar properties, and scalar Variable() construction throughout the package.
However, Variable() is also used as a placeholder while its type and shape are being inferred. These placeholders have dims = NULL, so they are treated as rank-0 scalars before their shape is known. This makes an uninferred shape indistinguishable from an inferred scalar.
I think we should use the following representation:
@dims |
Meaning |
NULL |
shape and rank have not been inferred |
list() |
rank-0 scalar |
list(1L) |
rank-1 value with extent 1 |
list(NA_integer_) |
rank-1 value with an unknown extent |
list(NA_integer_, NA_integer_) |
rank-2 value with unknown extents |
Under this representation, declarations such as integer() would produce dims = list(). Unknown extents of a known-rank value would continue to use NA per axis.
The implementation will require:
- preserving the distinction between
NULL and list() in the dims setter;
- making scalar
Variable() construction pass dims = list() explicitly;
- replacing other deliberate uses of
NULL for scalar results;
- making shape-sensitive operations fail clearly when dimensions have not been inferred;
- auditing
@rank, @is_scalar, passes_as_scalar(), and is.null(@dims) consumers;
- adding public tests that exercise rank-0 declarations, generated code, runtime results, and shape inference.
This is a follow-up to #137. The setter change there remains consistent with the current representation; this issue proposes changing that representation separately.
Variable@dimscurrently usesNULLto represent a rank-0 scalar. This is reflected in the class comment, therankandis_scalarproperties, and scalarVariable()construction throughout the package.However,
Variable()is also used as a placeholder while its type and shape are being inferred. These placeholders havedims = NULL, so they are treated as rank-0 scalars before their shape is known. This makes an uninferred shape indistinguishable from an inferred scalar.I think we should use the following representation:
@dimsNULLlist()list(1L)list(NA_integer_)list(NA_integer_, NA_integer_)Under this representation, declarations such as
integer()would producedims = list(). Unknown extents of a known-rank value would continue to useNAper axis.The implementation will require:
NULLandlist()in thedimssetter;Variable()construction passdims = list()explicitly;NULLfor scalar results;@rank,@is_scalar,passes_as_scalar(), andis.null(@dims)consumers;This is a follow-up to #137. The setter change there remains consistent with the current representation; this issue proposes changing that representation separately.