src/DataObjects/Tensors/storage/LazyColumnTensorStorage.hpp
src/DataObjects/Tensors/storage/LazyColumnTensorStorage.hpp
Lazy column-based tensor storage with type-erased column providers. More…
Classes
| Name | |
|---|---|
| struct | ColumnSource Describes one column source with a name and a provider function. |
| class | LazyColumnTensorStorage Lazy column-based tensor storage backend. |
Types
| Name | |
|---|---|
| using std::function< std::vector< float >()> | ColumnProviderFn A function that produces an entire column of float values. |
Detailed Description
Lazy column-based tensor storage with type-erased column providers.
See: tensor_data_refactor_proposal.md §6.6 for design rationale.
Each column is either a materialized std::vector
This storage lives in the DataManager library and has no dependency on TransformsV2, GatherResult, or DataManager itself. Provider functions are assembled at higher architectural layers and injected as closures.
Part of the TensorData refactor (step 7).
Types Documentation
using ColumnProviderFn
using ColumnProviderFn = std::function<std::vector<float>()>;A function that produces an entire column of float values.
Called once per materialization; result is cached. When the cache is invalidated, the next access re-calls the provider. The returned vector must have exactly num_rows elements.
Source code
#ifndef LAZY_COLUMN_TENSOR_STORAGE_HPP
#define LAZY_COLUMN_TENSOR_STORAGE_HPP
#include "TensorStorageBase.hpp"
#include <cstddef>
#include <functional>
#include <memory>
#include <mutex>
#include <optional>
#include <span>
#include <string>
#include <vector>
using ColumnProviderFn = std::function<std::vector<float>()>;
struct ColumnSource {
std::string name;
ColumnProviderFn provider;
mutable std::optional<std::vector<float>> cache;
};
class LazyColumnTensorStorage : public TensorStorageBase<LazyColumnTensorStorage> {
public:
// ========== Construction ==========
LazyColumnTensorStorage(std::size_t num_rows, std::vector<ColumnSource> columns);
// ========== Column-Level Control ==========
void materializeColumn(std::size_t col) const;
void materializeAll() const;
void invalidateColumn(std::size_t col);
void invalidateAll();
void setColumnProvider(std::size_t col, std::string name, ColumnProviderFn provider);
std::size_t appendColumn(std::string name, ColumnProviderFn provider);
void removeColumn(std::size_t col);
[[nodiscard]] std::size_t numColumns() const noexcept;
[[nodiscard]] std::size_t numRows() const noexcept;
[[nodiscard]] std::vector<std::string> columnNames() const;
[[nodiscard]] std::vector<float> materializeFlat() const;
// ========== CRTP Implementation ==========
[[nodiscard]] float getValueAtImpl(std::span<std::size_t const> indices) const;
[[nodiscard]] std::span<float const> flatDataImpl() const;
[[nodiscard]] std::vector<float> sliceAlongAxisImpl(std::size_t axis, std::size_t index) const;
[[nodiscard]] std::vector<float> getColumnImpl(std::size_t col) const;
[[nodiscard]] std::vector<std::size_t> shapeImpl() const;
[[nodiscard]] std::size_t totalElementsImpl() const;
[[nodiscard]] bool isContiguousImpl() const noexcept { return false; }
[[nodiscard]] TensorStorageType getStorageTypeImpl() const noexcept {
return TensorStorageType::Lazy;
}
[[nodiscard]] TensorStorageCache tryGetCacheImpl() const;
private:
std::size_t _num_rows;
mutable std::vector<ColumnSource> _columns;
mutable std::unique_ptr<std::mutex> _mutex;
void ensureMaterialized(std::size_t col) const;
void validateColumn(std::size_t col) const;
};
#endif // LAZY_COLUMN_TENSOR_STORAGE_HPPUpdated on 2026-11-13 at 20:25:43 +0000