TensorData
TensorData
Refactored N-dimensional tensor with named axes, multiple storage backends, and first-class DataManager integration. More…
#include <TensorData.hpp>
Inherits from ObserverData
Public Classes
| Name | |
|---|---|
| struct | DataTraits Traits for generic trait-based dispatch in transforms v2. |
Public Functions
| Name | |
|---|---|
| TensorData() Default constructor — empty tensor (no storage, ordinal 0 rows). |
|
| ~TensorData() Destructor (non-trivial due to shared_ptr members). |
|
| TensorData(TensorData const & other) Copy. |
|
| TensorData & | operator=(TensorData const & other) |
| TensorData(TensorData && other) Move. |
|
| TensorData & | operator=(TensorData && other) |
| DimensionDescriptor const & | dimensions() const Get the full dimension descriptor. |
| std::size_t | ndim() const Number of dimensions (axes). |
| std::vector< std::size_t > | shape() const Shape as a vector of sizes (one per axis). |
| RowDescriptor const & | rows() const Get the row descriptor. |
| RowType | rowType() const Get the row type (TimeFrameIndex, Interval, or Ordinal). |
| std::size_t | numRows() const Number of rows (axis 0 size, or RowDescriptor::count() for ordinal). |
| bool | hasNamedColumns() const Whether this tensor has named columns. |
| std::vector< std::string > const & | columnNames() const Get the column names (empty if not set). |
| std::size_t | numColumns() const Number of columns (last axis size for ≥2D, 1 for 1D, 0 for scalar). |
| std::vector< float > | getColumn(std::size_t index) const Get column data by index. |
| std::vector< float > | getColumn(std::string_view name) const Get column data by name. |
| float | at(std::span< std::size_t const > indices) const Get a single element by multi-dimensional index. |
| std::vector< float > | row(std::size_t index) const Get an entire row as a flat vector (all columns for that row). |
| std::span< float const > | flatData() const Fast-path flat data access (contiguous storage only). |
| std::vector< float > | materializeFlat() const Materialize all data as a row-major flat vector (always works). |
| TensorData | materialize() const Materialize the tensor into owned storage. |
| TensorData | toArmadillo() const Convert to Armadillo-backed tensor (must be ≤3D). |
| arma::fmat const & | asArmadilloMatrix() const Direct access to the underlying Armadillo matrix (2D only). |
| arma::fcube const & | asArmadilloCube() const Direct access to the underlying Armadillo cube (3D only). |
| void | setData(std::vector< float > const & data, std::vector< std::size_t > const & new_shape) Replace all data with new flat data and shape. |
| void | setData(std::vector< float > && data, std::vector< std::size_t > const & new_shape) Replace all data with new flat data and shape (move overload). |
| std::size_t | appendColumn(std::string name, ColumnProviderFn provider) Append a new lazy column. |
| void | removeColumn(std::size_t col) Remove a column by index. |
| void | appendRow(std::span< float const > row_data) Append a row to the end of the tensor. |
| void | appendRow(std::span< float const > row_data, TimeFrameInterval interval) Append a row with an associated interval. |
| void | insertRow(std::size_t index, std::span< float const > row_data) Insert a row at a specific position. |
| void | insertRow(std::size_t index, std::span< float const > row_data, TimeFrameInterval interval) Insert a row with an associated interval. |
| void | setRow(std::size_t index, std::span< float const > row_data) Overwrite an existing row’s data in-place. |
| void | upsertRows(std::vector< std::pair< int, std::vector< float > > > const & frame_rows, std::shared_ptr< TimeFrame > time_frame) Upsert rows keyed by TimeFrameIndex. |
| TensorStorageWrapper const & | storage() const Get the underlying storage wrapper (for advanced backend access). |
| bool | isContiguous() const Whether the underlying storage is contiguous in memory. |
| bool | isEmpty() const Whether this tensor has valid (non-empty) storage. |
| void | setTimeFrame(std::shared_ptr< TimeFrame > tf) Set the time frame for this tensor. |
| std::shared_ptr< TimeFrame > | getTimeFrame() const Get the time frame (may be nullptr for ordinal tensors). |
| void | setColumnNames(std::vector< std::string > names) Set or replace column names. |
| TensorData | createTimeSeries2D(std::vector< float > const & data, std::size_t num_rows, std::size_t num_cols, std::shared_ptr< TimeIndexStorage > time_storage, std::shared_ptr< TimeFrame > time_frame, std::vector< std::string > column_names ={}) Create a 2D time-series tensor (rows = time, columns = features). |
| TensorData | createTimeSeries2D(arma::fmat matrix, std::shared_ptr< TimeIndexStorage > time_storage, std::shared_ptr< TimeFrame > time_frame, std::vector< std::string > column_names ={}) Create a 2D time-series tensor from a pre-built Armadillo matrix. |
| TensorData | createTimeSeries2DFromStorage(TensorStorageWrapper storage, std::shared_ptr< TimeIndexStorage > time_storage, std::shared_ptr< TimeFrame > time_frame, std::vector< std::string > column_names ={}) Create a 2D time-series tensor from a custom storage backend. |
| TensorData | createFromIntervals(std::vector< float > const & data, std::size_t num_rows, std::size_t num_cols, std::vector< TimeFrameInterval > intervals, std::shared_ptr< TimeFrame > time_frame, std::vector< std::string > column_names ={}) Create a 2D tensor with interval-based rows. |
| TensorData | createFromIntervals(arma::fmat matrix, std::vector< TimeFrameInterval > intervals, std::shared_ptr< TimeFrame > time_frame, std::vector< std::string > column_names ={}) Create a 2D tensor with interval-based rows from an Armadillo matrix. |
| TensorData | createFromIntervalsFromStorage(TensorStorageWrapper storage, std::vector< TimeFrameInterval > intervals, std::shared_ptr< TimeFrame > time_frame, std::vector< std::string > column_names ={}) Create a 2D tensor with interval-based rows from a custom storage backend. |
| TensorData | createND(std::vector< float > const & data, std::vector< AxisDescriptor > const & axes) Create an N-dimensional tensor from flat data and axis descriptors. |
| TensorData | createFromArmadillo(arma::fmat matrix, std::vector< std::string > column_names ={}) Create a 2D tensor from an Armadillo matrix (zero-copy). |
| TensorData | createFromArmadillo(arma::fcube cube, std::vector< AxisDescriptor > axes ={}) Create a 3D tensor from an Armadillo cube (zero-copy). |
| TensorData | createOrdinal2D(std::vector< float > const & data, std::size_t num_rows, std::size_t num_cols, std::vector< std::string > column_names ={}) Create a 2D ordinal tensor from flat data. |
| TensorData | createOrdinal2DFromStorage(TensorStorageWrapper storage, std::shared_ptr< TimeFrame > time_frame =[nullptr], std::vector< std::string > column_names ={}) Create a 2D ordinal tensor from a custom storage backend. |
| TensorData | createFromLazyColumns(std::size_t num_rows, std::vector< ColumnSource > columns, RowDescriptor rows, InvalidationWiringFn const & wiring ={}) Create a 2D tensor with lazily-computed columns. |
Additional inherited members
Public Classes inherited from ObserverData
| Name | |
|---|---|
| struct | ObserverEntry Entry in the observer map. |
Public Types inherited from ObserverData
| Name | |
|---|---|
| using std::function< void()> | ObserverCallback Type alias for observer callback functions. |
| using int | CallbackID Type alias for callback identifiers. |
Public Functions inherited from ObserverData
| Name | |
|---|---|
| ObserverData(std::string name =“UnnamedObservable”) | |
| CallbackID | addObserver(ObserverCallback callback, std::string name =“Anonymous”) Register a new observer callback. |
| void | notifyObservers() Notify all registered observers. |
| void | removeObserver(CallbackID id) Remove a previously registered observer. |
Detailed Description
class TensorData;Refactored N-dimensional tensor with named axes, multiple storage backends, and first-class DataManager integration.
Quick Start
// 2D time-series matrix (e.g., spectrogram)
auto spec = TensorData::createTimeSeries2D(
flat_magnitudes, num_time_bins, num_freq_bins,
time_storage, time_frame,
{"0-10 Hz", "10-20 Hz", "20-30 Hz"});
auto band = spec.getColumn("10-20 Hz");
// Direct Armadillo access for mlpack
arma::fmat const& m = spec.asArmadilloMatrix();tensor_data_refactor_proposal.md for full design rationale
Public Functions Documentation
function TensorData
TensorData()Default constructor — empty tensor (no storage, ordinal 0 rows).
function ~TensorData
~TensorData()Destructor (non-trivial due to shared_ptr members).
function TensorData
TensorData(
TensorData const & other
)Copy.
function operator=
TensorData & operator=(
TensorData const & other
)function TensorData
TensorData(
TensorData && other
)Move.
function operator=
TensorData & operator=(
TensorData && other
)function dimensions
DimensionDescriptor const & dimensions() constGet the full dimension descriptor.
function ndim
std::size_t ndim() constNumber of dimensions (axes).
function shape
std::vector< std::size_t > shape() constShape as a vector of sizes (one per axis).
function rows
RowDescriptor const & rows() constGet the row descriptor.
function rowType
RowType rowType() constGet the row type (TimeFrameIndex, Interval, or Ordinal).
function numRows
std::size_t numRows() constNumber of rows (axis 0 size, or RowDescriptor::count() for ordinal).
function hasNamedColumns
bool hasNamedColumns() constWhether this tensor has named columns.
function columnNames
std::vector< std::string > const & columnNames() constGet the column names (empty if not set).
function numColumns
std::size_t numColumns() constNumber of columns (last axis size for ≥2D, 1 for 1D, 0 for scalar).
function getColumn
std::vector< float > getColumn(
std::size_t index
) constGet column data by index.
Parameters:
- index Column index (0-based)
Exceptions:
- std::out_of_range if index >= numColumns()
Returns a vector of float values for all rows at the given column.
function getColumn
std::vector< float > getColumn(
std::string_view name
) constGet column data by name.
Parameters:
- name Column name (must match one set via setColumnNames / factory)
Exceptions:
- std::invalid_argument if name not found or no named columns
function at
float at(
std::span< std::size_t const > indices
) constGet a single element by multi-dimensional index.
Parameters:
- indices One index per dimension
Exceptions:
- std::out_of_range / std::invalid_argument on index errors
function row
std::vector< float > row(
std::size_t index
) constGet an entire row as a flat vector (all columns for that row).
Parameters:
- index Row index (axis 0)
Exceptions:
- std::out_of_range if index >= axis(0).size
For a 2D tensor with shape [R, C], returns C floats. For a 3D tensor with shape [D0, D1, D2], returns D1*D2 floats.
function flatData
std::span< float const > flatData() constFast-path flat data access (contiguous storage only).
Exceptions:
- std::runtime_error if storage is not contiguous
Note: Layout depends on the backend — Armadillo is column-major, Dense is row-major. For guaranteed row-major, use materializeFlat().
function materializeFlat
std::vector< float > materializeFlat() constMaterialize all data as a row-major flat vector (always works).
If storage is already contiguous and row-major, returns a copy of flatData(). Otherwise, reconstructs row-major order from element access.
function materialize
TensorData materialize() constMaterialize the tensor into owned storage.
If the tensor is already backed by owned storage (Armadillo or Dense), returns a copy. If backed by a View or Lazy storage, computes and returns a new TensorData with materialized data.
Uses ArmadilloTensorStorage for ≤3D, DenseTensorStorage for >3D.
function toArmadillo
TensorData toArmadillo() constConvert to Armadillo-backed tensor (must be ≤3D).
Exceptions:
- std::logic_error if ndim() > 3
If already Armadillo-backed, returns a shallow copy (shared storage). Otherwise, materializes into a new ArmadilloTensorStorage.
function asArmadilloMatrix
arma::fmat const & asArmadilloMatrix() constDirect access to the underlying Armadillo matrix (2D only).
Exceptions:
- std::logic_error if not 2D or not Armadillo-backed
function asArmadilloCube
arma::fcube const & asArmadilloCube() constDirect access to the underlying Armadillo cube (3D only).
Exceptions:
- std::logic_error if not 3D or not Armadillo-backed
function setData
void setData(
std::vector< float > const & data,
std::vector< std::size_t > const & new_shape
)Replace all data with new flat data and shape.
Parameters:
- data New flat row-major data
- new_shape New shape
Exceptions:
- std::invalid_argument on size mismatch
Creates new owned storage (Armadillo ≤3D, Dense >3D). Notifies observers.
function setData
void setData(
std::vector< float > && data,
std::vector< std::size_t > const & new_shape
)Replace all data with new flat data and shape (move overload).
function appendColumn
std::size_t appendColumn(
std::string name,
ColumnProviderFn provider
)Append a new lazy column.
Parameters:
- name Column name
- provider Provider function that returns
[numRows()](/api_generated/Classes/classTensorData.md#function-numrows)floats
Exceptions:
- std::logic_error if the storage is not LazyColumnTensorStorage
- std::invalid_argument if provider is null
Return: The index of the newly appended column
Adds a column to the end of the tensor. Only valid when the underlying storage is [LazyColumnTensorStorage](/api_generated/Classes/classLazyColumnTensorStorage.md). Updates the dimension descriptor (axis size + column names) and notifies observers.
function removeColumn
void removeColumn(
std::size_t col
)Remove a column by index.
Parameters:
- col Column index to remove
Exceptions:
- std::logic_error if the storage is not LazyColumnTensorStorage
- std::out_of_range if col >= numColumns()
- std::logic_error if removing the column would leave zero columns
Removes the column at the given index. Only valid when the underlying storage is [LazyColumnTensorStorage](/api_generated/Classes/classLazyColumnTensorStorage.md). The tensor must have more than one column. Updates the dimension descriptor and notifies observers.
function appendRow
void appendRow(
std::span< float const > row_data
)Append a row to the end of the tensor.
Parameters:
- row_data Values for the new row (size must equal numColumns())
Exceptions:
- std::logic_error if the tensor is not 2D, is backed by an unsupported storage type, or has TimeFrameIndex rows
- std::invalid_argument if row_data.size() != numColumns()
Works for 2D tensors backed by ArmadilloTensorStorage or DenseTensorStorage with Ordinal or Interval row semantics.
For Ordinal rows, the ordinal count is incremented. For Interval rows, the provided interval is appended to the row descriptor. TimeFrameIndex rows are not supported (time index storage is immutable).
Updates the dimension descriptor (axis 0 size) and notifies observers.
function appendRow
void appendRow(
std::span< float const > row_data,
TimeFrameInterval interval
)Append a row with an associated interval.
Parameters:
- row_data Values for the new row
- interval Time interval for the new row
Exceptions:
- std::logic_error if rowType() != RowType::Interval, or storage is unsupported
- std::invalid_argument if row_data.size() != numColumns()
Convenience overload for tensors with Interval row semantics.
function insertRow
void insertRow(
std::size_t index,
std::span< float const > row_data
)Insert a row at a specific position.
Parameters:
- index Position to insert before (0-based; numRows() appends)
- row_data Values for the new row
Exceptions:
- std::logic_error if unsupported storage or TimeFrameIndex rows
- std::out_of_range if index > numRows()
- std::invalid_argument if row_data.size() != numColumns()
Same storage and row-type constraints as appendRow(). Existing rows at and after the insertion point are shifted down.
function insertRow
void insertRow(
std::size_t index,
std::span< float const > row_data,
TimeFrameInterval interval
)Insert a row with an associated interval.
Parameters:
- index Position to insert before
- row_data Values for the new row
- interval Time interval for the new row
Exceptions:
- std::logic_error if rowType() != RowType::Interval, or storage is unsupported
- std::out_of_range if index > numRows()
- std::invalid_argument if row_data.size() != numColumns()
Convenience overload for tensors with Interval row semantics.
function setRow
void setRow(
std::size_t index,
std::span< float const > row_data
)Overwrite an existing row’s data in-place.
Parameters:
- index Row index to overwrite (0-based)
- row_data New values for the row (size must equal numColumns())
Exceptions:
- std::logic_error if the tensor is not 2D or has unsupported storage
- std::out_of_range if index >= numRows()
- std::invalid_argument if row_data.size() != numColumns()
Works for 2D tensors backed by ArmadilloTensorStorage or DenseTensorStorage. The row must already exist. Row descriptor and dimension metadata are unchanged. Notifies observers.
function upsertRows
void upsertRows(
std::vector< std::pair< int, std::vector< float > > > const & frame_rows,
std::shared_ptr< TimeFrame > time_frame
)Upsert rows keyed by TimeFrameIndex.
Parameters:
- frame_rows Pairs of (frame_index, row_data); row_data sizes must all equal numColumns() (or each other for empty tensors)
- time_frame Shared TimeFrame for the resulting time-indexed rows
Exceptions:
- std::invalid_argument if frame_rows is empty, row sizes are inconsistent, or time_frame is null
- std::logic_error if the tensor is non-empty and not 2D, or has unsupported storage
Precondition: All row_data vectors must have the same size
Merges the given frame→row-data pairs into this tensor. For each pair:
- If a row for that frame already exists, its data is overwritten.
- If no row exists for that frame, a new row is inserted in sorted order.
After the operation, the tensor’s rows are sorted by TimeFrameIndex and backed by a fresh TimeIndexStorage. The tensor must be 2D and backed by ArmadilloTensorStorage or DenseTensorStorage. If the tensor is empty (no storage), it is initialized from the provided rows.
function storage
TensorStorageWrapper const & storage() constGet the underlying storage wrapper (for advanced backend access).
function isContiguous
bool isContiguous() constWhether the underlying storage is contiguous in memory.
function isEmpty
bool isEmpty() constWhether this tensor has valid (non-empty) storage.
function setTimeFrame
void setTimeFrame(
std::shared_ptr< TimeFrame > tf
)Set the time frame for this tensor.
This is set automatically by factory methods that take a TimeFrame. Can also be set manually for ordinal tensors that later gain time semantics.
function getTimeFrame
std::shared_ptr< TimeFrame > getTimeFrame() constGet the time frame (may be nullptr for ordinal tensors).
function setColumnNames
void setColumnNames(
std::vector< std::string > names
)Set or replace column names.
Parameters:
- names Column names; must match the last axis size
Exceptions:
- std::invalid_argument on size mismatch
function createTimeSeries2D
static TensorData createTimeSeries2D(
std::vector< float > const & data,
std::size_t num_rows,
std::size_t num_cols,
std::shared_ptr< TimeIndexStorage > time_storage,
std::shared_ptr< TimeFrame > time_frame,
std::vector< std::string > column_names ={}
)Create a 2D time-series tensor (rows = time, columns = features).
Parameters:
- data Flat row-major data (size must == num_rows * num_cols)
- num_rows Number of rows (time points)
- num_cols Number of columns (features / frequency bins / channels)
- time_storage TimeIndexStorage mapping row indices to TimeFrameIndex
- time_frame Shared TimeFrame for absolute time reference (may be nullptr; DataManager assigns the correct TimeFrame when registered)
- column_names Optional column labels (size must match num_cols if provided)
Exceptions:
- std::invalid_argument on size mismatches or null time_storage
Precondition:
- time_storage != nullptr (enforcement: exception)
- time_storage->size() == num_rows (enforcement: exception)
- data.size() == num_rows * num_cols (enforcement: exception)
- column_names.empty() || column_names.size() == num_cols (enforcement: exception)
- num_rows * num_cols does not overflow std::size_t (enforcement: none) [LOW]
Uses ArmadilloTensorStorage internally. Axes named “time” and “channel”.
function createTimeSeries2D
static TensorData createTimeSeries2D(
arma::fmat matrix,
std::shared_ptr< TimeIndexStorage > time_storage,
std::shared_ptr< TimeFrame > time_frame,
std::vector< std::string > column_names ={}
)Create a 2D time-series tensor from a pre-built Armadillo matrix.
Parameters:
- matrix Armadillo float matrix (moved into storage)
- time_storage TimeIndexStorage mapping row indices to TimeFrameIndex
- time_frame Shared TimeFrame for absolute time reference (may be nullptr)
- column_names Optional column labels
Precondition:
- time_storage != nullptr (enforcement: exception)
- time_storage->size() == matrix.n_rows (enforcement: exception)
- matrix.n_rows > 0 && matrix.n_cols > 0 (enforcement: exception)
- column_names.empty() || column_names.size() == matrix.n_cols (enforcement: exception)
Zero-copy variant: the matrix is moved directly into ArmadilloTensorStorage, avoiding row-major → column-major conversion overhead. Axes named “time” and “channel”.
function createTimeSeries2DFromStorage
static TensorData createTimeSeries2DFromStorage(
TensorStorageWrapper storage,
std::shared_ptr< TimeIndexStorage > time_storage,
std::shared_ptr< TimeFrame > time_frame,
std::vector< std::string > column_names ={}
)Create a 2D time-series tensor from a custom storage backend.
Parameters:
- storage Type-erased storage wrapper (must report 2D shape).
- time_storage Dense time index storage (size must match storage rows).
- time_frame Shared TimeFrame for time reference (may be nullptr; DataManager assigns the correct TimeFrame when registered).
- column_names Optional column labels.
Precondition:
- time_storage != nullptr (enforcement: exception)
- time_storage->size() == storage.shape()[0] (enforcement: exception)
- storage.shape().size() == 2 (enforcement: exception)
Enables non-Armadillo backends (e.g., MmapTensorStorage) to be used as TensorData with time-indexed rows.
function createFromIntervals
static TensorData createFromIntervals(
std::vector< float > const & data,
std::size_t num_rows,
std::size_t num_cols,
std::vector< TimeFrameInterval > intervals,
std::shared_ptr< TimeFrame > time_frame,
std::vector< std::string > column_names ={}
)Create a 2D tensor with interval-based rows.
Parameters:
- data Flat row-major data (size must == num_rows * num_cols)
- num_rows Number of rows (intervals)
- num_cols Number of columns
- intervals One TimeFrameInterval per row
- time_frame Shared TimeFrame for time reference (may be nullptr; DataManager assigns the correct TimeFrame when registered)
- column_names Optional column labels
Exceptions:
- std::invalid_argument on size mismatches
Precondition:
- intervals.size() == num_rows (enforcement: exception)
- data.size() == num_rows * num_cols (enforcement: exception)
- column_names.empty() || column_names.size() == num_cols (enforcement: exception)
- num_rows * num_cols does not overflow std::size_t (enforcement: none) [LOW]
Each row corresponds to an interval (e.g., trial). Uses ArmadilloTensorStorage.
function createFromIntervals
static TensorData createFromIntervals(
arma::fmat matrix,
std::vector< TimeFrameInterval > intervals,
std::shared_ptr< TimeFrame > time_frame,
std::vector< std::string > column_names ={}
)Create a 2D tensor with interval-based rows from an Armadillo matrix.
Parameters:
- matrix Armadillo float matrix (moved into storage)
- intervals One TimeFrameInterval per row
- time_frame Shared TimeFrame for time reference (may be nullptr)
- column_names Optional column labels
Exceptions:
- std::invalid_argument on size mismatches
Precondition:
- intervals.size() == matrix.n_rows (enforcement: exception)
- matrix.n_rows > 0 && matrix.n_cols > 0 (enforcement: exception)
- column_names.empty() || column_names.size() == matrix.n_cols (enforcement: exception)
Zero-copy variant: the matrix is moved directly into ArmadilloTensorStorage, avoiding row-major to column-major conversion overhead.
function createFromIntervalsFromStorage
static TensorData createFromIntervalsFromStorage(
TensorStorageWrapper storage,
std::vector< TimeFrameInterval > intervals,
std::shared_ptr< TimeFrame > time_frame,
std::vector< std::string > column_names ={}
)Create a 2D tensor with interval-based rows from a custom storage backend.
Parameters:
- storage Type-erased storage wrapper (must report 2D shape).
- intervals One TimeFrameInterval per row.
- time_frame Shared TimeFrame for time reference (may be nullptr).
- column_names Optional column labels.
Precondition:
- storage.shape().size() == 2 (enforcement: exception)
- intervals.size() == storage.shape()[0] (enforcement: exception)
Enables non-Armadillo backends (for example LibTorchTensorStorage) to be used while preserving interval row semantics.
function createND
static TensorData createND(
std::vector< float > const & data,
std::vector< AxisDescriptor > const & axes
)Create an N-dimensional tensor from flat data and axis descriptors.
Parameters:
- data Flat row-major data
- axes Ordered axis descriptors (outermost first)
Exceptions:
- std::invalid_argument if data size doesn’t match total elements
Precondition:
- !axes.empty() (enforcement: exception)
- data.size() == product of all ax.size in axes (enforcement: exception)
- product of all ax.size does not overflow std::size_t (enforcement: none) [LOW]
Uses ArmadilloTensorStorage for ≤3D, DenseTensorStorage for >3D. Row descriptor is Ordinal (no time semantics).
function createFromArmadillo
static TensorData createFromArmadillo(
arma::fmat matrix,
std::vector< std::string > column_names ={}
)Create a 2D tensor from an Armadillo matrix (zero-copy).
Parameters:
- matrix Armadillo float matrix (moved into storage)
- column_names Optional column labels
Precondition:
- matrix.n_rows > 0 && matrix.n_cols > 0 (enforcement: exception)
- column_names.empty() || column_names.size() == matrix.n_cols (enforcement: exception)
Column names are optional. Row descriptor is Ordinal.
function createFromArmadillo
static TensorData createFromArmadillo(
arma::fcube cube,
std::vector< AxisDescriptor > axes ={}
)Create a 3D tensor from an Armadillo cube (zero-copy).
Parameters:
- cube Armadillo float cube (moved into storage)
- axes Optional axis descriptors; if empty, defaults to {“dim0”, nslices}, {“dim1”, nrows}, {“dim2”, ncols}
Precondition:
- cube.n_slices > 0 && cube.n_rows > 0 && cube.n_cols > 0 (enforcement: exception)
- axes.empty() || axes.size() == 3 (enforcement: none) [IMPORTANT]
- If !axes.empty(): axes[0].size == cube.n_slices, axes[1].size == cube.n_rows, axes[2].size == cube.n_cols — mismatched sizes will make dims.shape() lie silently (enforcement: none) [IMPORTANT]
- No zero-size axes and no duplicate axis names in provided axes (enforcement: exception)
function createOrdinal2D
static TensorData createOrdinal2D(
std::vector< float > const & data,
std::size_t num_rows,
std::size_t num_cols,
std::vector< std::string > column_names ={}
)Create a 2D ordinal tensor from flat data.
Parameters:
- data Flat row-major data
- num_rows Number of rows
- num_cols Number of columns
- column_names Optional column labels
Convenience for matrices without time semantics. Uses ArmadilloTensorStorage.
function createOrdinal2DFromStorage
static TensorData createOrdinal2DFromStorage(
TensorStorageWrapper storage,
std::shared_ptr< TimeFrame > time_frame =nullptr,
std::vector< std::string > column_names ={}
)Create a 2D ordinal tensor from a custom storage backend.
Parameters:
- storage Type-erased storage wrapper (must report 2D shape).
- time_frame Optional TimeFrame metadata to preserve.
- column_names Optional column labels.
Precondition: storage.shape().size() == 2 (enforcement: exception)
Enables non-Armadillo backends (for example LibTorchTensorStorage) to be wrapped as ordinal TensorData without materializing to Armadillo first.
function createFromLazyColumns
static TensorData createFromLazyColumns(
std::size_t num_rows,
std::vector< ColumnSource > columns,
RowDescriptor rows,
InvalidationWiringFn const & wiring ={}
)Create a 2D tensor with lazily-computed columns.
Parameters:
- num_rows Number of rows (each provider must return this many floats)
- columns Column sources (name + provider); must not be empty
- rows Row descriptor (ordinal, time-indexed, or interval)
- wiring Optional callback for observer invalidation wiring; called once after construction with references to the LazyColumnTensorStorage and TensorData
Exceptions:
- std::invalid_argument if num_rows == 0 or columns is empty
Each column is backed by a type-erased provider function that computes the column data on demand. Results are cached per-column and can be invalidated to trigger recomputation.
Column names are taken from the ColumnSource::name fields. Row semantics are specified by the RowDescriptor.
Updated on 2026-11-13 at 20:25:39 +0000