Skip to content

refactor(dataset): replace Eigen matrix with mdspan/mdarray storage - #64

Merged
foolnotion merged 3 commits into
mainfrom
refactor/dataset-mdspan
May 29, 2026
Merged

refactor(dataset): replace Eigen matrix with mdspan/mdarray storage#64
foolnotion merged 3 commits into
mainfrom
refactor/dataset-mdspan

Conversation

@foolnotion

Copy link
Copy Markdown
Member

Summary

  • Replaces Dataset's Eigen::Array + Eigen::Map storage with MDArray<Scalar, dextents<int,2>> (owned) and MDSpan<Scalar const, dextents<int,2>> (non-owning view), both of which are already dependencies
  • Removes the Eigen dependency from dataset.hpp entirely — Eigen is now only used in the optimizer, interpreter backends, and cost functions where it belongs
  • IsView() now checks storage_.size() == 0 instead of comparing Eigen data pointers
  • All downstream API (GetValues, Rows(), Cols(), IsView(), Shuffle, Normalize, Standardize) is preserved unchanged — no callers needed updating

New additions

  • Data() -> View — exposes the raw MDSpan view for callers that want direct 2D access
  • SetWeights(Span<Scalar const>) / Weights() -> optional<Span<Scalar const>> — optional per-sample weight vector, laying the groundwork for weighted evaluation (PR add sample weights to Evaluator. #49)

Test changes

  • Replace Dataset::Matrix values(r, c); values << ...; Dataset ds(values) with the vector<vector<Scalar>> constructor or the raw-pointer view constructor
  • Replace ds.Values().col(j) Eigen column expressions with ds.GetValues(int64_t{j}) spans
  • RandomDataset helper in operon_test.hpp updated to use vector<vector<Scalar>> columns

Test plan

  • All tests pass (ctest 100%)

Replace Dataset's Eigen::Array/Map storage with MDArray<Scalar, dextents<int,2>>
(column-major) and a MDSpan<Scalar const, dextents<int,2>> view, removing the
Eigen dependency from dataset.hpp entirely.

Key changes:
- Storage is MDArray (owned); View is MDSpan (non-owning, used for external data)
- IsView() checks storage_.size() == 0 instead of comparing Eigen data pointers
- GetValues() returns Span<Scalar const> as before — no downstream API changes
- Add SetWeights()/Weights() for optional per-sample weight vector
- Shuffle/PermuteRows reimplemented as column-wise permutation over the flat buffer
- Normalize/Standardize operate directly on the raw column pointer + vstat

Tests updated: replace Dataset::Matrix + Eigen stream init with vector-of-columns
constructor or the raw-pointer view constructor; replace ds.Values().col(j) Eigen
expressions with ds.GetValues(int64_t{j}) spans.
…types.hpp

Single source of truth for 32-byte alignment: all MDArray users (Dataset
storage, interpreter dispatch buffers) now inherit alignment from the
type alias definition rather than specifying it independently.
GetVariable("Y") in performance tests threw bad_optional_access because
RandomDataset generated columns named X1..Xn with no Y.
@foolnotion
foolnotion merged commit 7188556 into main May 29, 2026
3 checks passed
@foolnotion
foolnotion deleted the refactor/dataset-mdspan branch May 31, 2026 11:33
foolnotion added a commit that referenced this pull request Jul 13, 2026
refactor(dataset): replace Eigen matrix with mdspan/mdarray storage
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