Skip to content

Distinguish uninferred dimensions from rank-0 scalars #153

Description

@t-kalinowski

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions