Skip to content

Conversation

@eisenhauer
Copy link
Member

@eisenhauer eisenhauer commented Feb 5, 2026

This PR is essentially a proposal for an external API that gets us closer to "thread safety". (I.E. it at least creates the possibility of a thread-safe Get() operation subject to a number of other assumptions (metadata loaded and read-only, engine-specific Get() implementations cooperating, etc. The core of this is a Selection class that can be used two ways, either fluent or mutating. Internally this will be passed to calls like Get() and SelectionSize() that currently operate on values built up in the Variable class with calls like Var.SetBlock(). No existing APIs will be deprecated, only a few new calls created. Examples below:

// Mutating style with Set* calls
Selection sel;
sel.SetBlock(3);
sel.SetAccuracy({0.01, 0.0, false});
std::vector data;
engine.Get(var, data, sel);

// Fluent style
std::vector data;
engine.Get(var, data, Selection::Block(3).WithAccuracy({0.01, 0.0, false}));

// Pre-allocated buffer with raw pointer
auto sel = Selection::BoundingBox({0, 0}, {10, 20});
double *data = (double *)malloc(var.SelectionSize(sel) * sizeof(double));
engine.Get(var, data, sel);

Note that nothing here is complete. The implementation for any particular engine subclass would have to come later and may not make sense for non-current engines.

Introduce a unified Selection class that supports both immutable (fluent)
and mutable usage patterns for specifying data selections in Get() calls.

Key features:
- Factory methods: Selection::BoundingBox(), Selection::Block()
- Mutating setters: SetBoundingBox(), SetBlock(), SetSteps(), SetMemory(), SetAccuracy()
- Non-mutating modifiers: WithSteps(), WithMemory(), WithAccuracy()
- New Engine::Get() overloads that accept Selection parameter
- Variable::SelectionSize(const Selection&) for buffer pre-allocation

Usage patterns:
  // Fluent/immutable style
  auto sel = Selection::BoundingBox(start, count).WithSteps(0, 10);

  // Mutable/reuse style
  Selection sel;
  sel.SetBoundingBox(start, count).SetSteps(0, 10);

  // Get with selection
  engine.Get(variable, data, sel);

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant