LazyColumnTensorStorage
LazyColumnTensorStorage
Lazy column-based tensor storage backend. More…
#include <LazyColumnTensorStorage.hpp>
Inherits from TensorStorageBase< LazyColumnTensorStorage >
Public Functions
| Name | |
|---|---|
| LazyColumnTensorStorage(std::size_t num_rows, std::vector< ColumnSource > columns) Construct from a row count and column sources. |
|
| void | materializeColumn(std::size_t col) const Materialize a single column (populate its cache). |
| void | materializeAll() const Materialize all columns. |
| void | invalidateColumn(std::size_t col) Invalidate a single column’s cache. |
| void | invalidateAll() Invalidate all columns’ caches. |
| void | setColumnProvider(std::size_t col, std::string name, ColumnProviderFn provider) Replace a column’s provider (and invalidate its cache). |
| std::size_t | appendColumn(std::string name, ColumnProviderFn provider) Append a new column. |
| void | removeColumn(std::size_t col) Remove a column by index. |
| std::size_t | numColumns() const Number of columns. |
| std::size_t | numRows() const Number of rows. |
| std::vector< std::string > | columnNames() const Get column names. |
| std::vector< float > | materializeFlat() const Get a flat row-major copy of all data (materializes everything). |
| float | getValueAtImpl(std::span< std::size_t const > indices) const |
| std::span< float const > | flatDataImpl() const |
| std::vector< float > | sliceAlongAxisImpl(std::size_t axis, std::size_t index) const |
| std::vector< float > | getColumnImpl(std::size_t col) const |
| std::vector< std::size_t > | shapeImpl() const |
| std::size_t | totalElementsImpl() const |
| bool | isContiguousImpl() const |
| TensorStorageType | getStorageTypeImpl() const |
| TensorStorageCache | tryGetCacheImpl() const |
Additional inherited members
Public Functions inherited from TensorStorageBase< LazyColumnTensorStorage >
| Name | |
|---|---|
| float | getValueAt(std::span< std::size_t const > indices) const Get a single float value by multi-dimensional index. |
| std::span< float const > | flatData() const Get a span over the flat (row-major) data. |
| std::vector< float > | sliceAlongAxis(std::size_t axis, std::size_t index) const Extract a sub-tensor by fixing one axis to a single index. |
| std::vector< float > | getColumn(std::size_t col) const Get a single column (axis 1 slice) across all rows (axis 0). |
| std::vector< std::size_t > | shape() const Get the shape as a vector of sizes (one per axis). |
| std::size_t | totalElements() const Get the total number of elements (product of shape). |
| bool | isContiguous() const Whether the underlying data is contiguous in memory. |
| TensorStorageType | getStorageType() const Get the storage type identifier. |
| TensorStorageCache | tryGetCache() const Try to get cached pointers for fast-path access. |
Protected Functions inherited from TensorStorageBase< LazyColumnTensorStorage >
| Name | |
|---|---|
| ~TensorStorageBase() =default |
Detailed Description
class LazyColumnTensorStorage;Lazy column-based tensor storage backend.
Implements the TensorStorageBase CRTP interface for a 2D tensor where each column is independently computed via a type-erased provider function. Columns are materialized lazily (on first access) and cached.
Key properties
- Shape is always 2D: [num_rows, num_columns]
- Not contiguous:
[flatData()](/api_generated/Classes/classTensorStorageBase.md#function-flatdata)throws (no single contiguous buffer). Use[materializeAll()](/api_generated/Classes/classLazyColumnTensorStorage.md#function-materializeall)+flatCache()or[getColumn()](/api_generated/Classes/classTensorStorageBase.md#function-getcolumn)for access. - Per-column caching: each column is materialized independently.
- Per-column invalidation:
invalidateColumn(col)clears one cache;[invalidateAll()](/api_generated/Classes/classLazyColumnTensorStorage.md#function-invalidateall)clears all. - Thread safety: column materialization is guarded by a mutex so that concurrent reads don’t race on cache population. The mutex is per-storage, not per-column, for simplicity.
Relationship to other storages
[ArmadilloTensorStorage](/api_generated/Classes/classArmadilloTensorStorage.md)/[DenseTensorStorage](/api_generated/Classes/classDenseTensorStorage.md): owned, contiguous data.ViewTensorStorage: zero-copy slice of another storage.[LazyColumnTensorStorage](/api_generated/Classes/classLazyColumnTensorStorage.md): each column computed on demand, cached.
Mixed materialized + lazy columns: a “materialized” column is just a provider that returns fixed data (called once, cached forever if never invalidated).
Public Functions Documentation
function LazyColumnTensorStorage
LazyColumnTensorStorage(
std::size_t num_rows,
std::vector< ColumnSource > columns
)Construct from a row count and column sources.
Parameters:
- num_rows Number of rows (each provider must return this many floats)
- columns Column sources (name + provider + cache)
Exceptions:
- std::invalid_argument if num_rows == 0 or columns is empty
function materializeColumn
void materializeColumn(
std::size_t col
) constMaterialize a single column (populate its cache).
Parameters:
- col Column index
Exceptions:
- std::out_of_range if col >= numColumns()
- std::runtime_error if provider returns wrong size
No-op if already cached. Calls the column’s provider function and validates the result size.
function materializeAll
void materializeAll() constMaterialize all columns.
Calls materializeColumn for each column that isn’t already cached.
function invalidateColumn
void invalidateColumn(
std::size_t col
)Invalidate a single column’s cache.
Parameters:
- col Column index
Exceptions:
- std::out_of_range if col >= numColumns()
Clears the column’s cached data and the flat cache. The next access to this column will re-call the provider.
function invalidateAll
void invalidateAll()Invalidate all columns’ caches.
Clears all cached data. The next access to any column will re-call its provider.
function setColumnProvider
void setColumnProvider(
std::size_t col,
std::string name,
ColumnProviderFn provider
)Replace a column’s provider (and invalidate its cache).
Parameters:
- col Column index
- name New column name
- provider New provider function
Exceptions:
- std::out_of_range if col >= numColumns()
function appendColumn
std::size_t appendColumn(
std::string name,
ColumnProviderFn provider
)Append a new column.
Parameters:
- name Column name
- provider Provider function for the new column
Exceptions:
- std::invalid_argument if provider is null
Return: The index of the newly appended column
Adds a column to the end of the column list. The provider must return exactly [numRows()](/api_generated/Classes/classLazyColumnTensorStorage.md#function-numrows) elements when called.
function removeColumn
void removeColumn(
std::size_t col
)Remove a column by index.
Parameters:
- col Column index to remove
Exceptions:
- 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, shifting subsequent columns. The storage must have more than one column (cannot remove the last column).
function numColumns
std::size_t numColumns() constNumber of columns.
function numRows
std::size_t numRows() constNumber of rows.
function columnNames
std::vector< std::string > columnNames() constGet column names.
function materializeFlat
std::vector< float > materializeFlat() constGet a flat row-major copy of all data (materializes everything).
Return: Row-major flat vector of size num_rows * num_columns
Unlike flatData() (which requires contiguous storage), this always works by materializing all columns and assembling row-major output.
function getValueAtImpl
float getValueAtImpl(
std::span< std::size_t const > indices
) constfunction flatDataImpl
std::span< float const > flatDataImpl() constfunction sliceAlongAxisImpl
std::vector< float > sliceAlongAxisImpl(
std::size_t axis,
std::size_t index
) constfunction getColumnImpl
std::vector< float > getColumnImpl(
std::size_t col
) constfunction shapeImpl
std::vector< std::size_t > shapeImpl() constfunction totalElementsImpl
std::size_t totalElementsImpl() constfunction isContiguousImpl
inline bool isContiguousImpl() constfunction getStorageTypeImpl
inline TensorStorageType getStorageTypeImpl() constfunction tryGetCacheImpl
TensorStorageCache tryGetCacheImpl() constUpdated on 2026-11-13 at 20:25:40 +0000