DimensionDescriptor
DimensionDescriptor
Describes the shape and named axes of a tensor. More…
#include <DimensionDescriptor.hpp>
Public Functions
| Name | |
|---|---|
| DimensionDescriptor(std::vector< AxisDescriptor > axes) Construct from a list of axis descriptors. |
|
| DimensionDescriptor() =default Default constructor — zero-dimensional (scalar) tensor. |
|
| std::size_t | ndim() const Number of dimensions (axes). |
| std::size_t | totalElements() const Total number of elements (product of all axis sizes). |
| std::vector< std::size_t > | shape() const Get the shape as a vector of sizes (one per axis). |
| AxisDescriptor const & | axis(std::size_t i) const Access an axis descriptor by positional index. |
| std::optional< std::size_t > | findAxis(std::string_view name) const Find the positional index of an axis by name. |
| std::vector< std::size_t > const & | strides() const Row-major strides (precomputed). |
| std::size_t | flatIndex(std::vector< std::size_t > const & indices) const Compute the flat (row-major) index for a set of per-axis indices. |
| bool | is1D() const |
| bool | is2D() const |
| bool | is3D() const |
| bool | isAtLeast(std::size_t n) const |
| void | setAxisSize(std::size_t axis_index, std::size_t new_size) Set the size of a specific axis and recompute strides. |
| void | setColumnNames(std::vector< std::string > names) Assign human-readable names to columns (last axis). |
| std::vector< std::string > const & | columnNames() const Get the column names (empty if not set). |
| bool | hasColumnNames() const Whether column names have been assigned. |
| std::optional< std::size_t > | findColumn(std::string_view name) const Find a column index by name. |
| bool | operator==(DimensionDescriptor const & other) const |
| bool | operator!=(DimensionDescriptor const & other) const |
Detailed Description
class DimensionDescriptor;Describes the shape and named axes of a tensor.
A tensor has an ordered list of named axes. Each axis has a name and a size. The descriptor also supports optional named columns on one designated axis, useful for tabular / feature-matrix representations.
Axis names are freeform strings. Conventional names include:
- “time” — row axis indexed by TimeIndexStorage
- “channel” — named columns / features
- “frequency” — frequency bins (spectrograms)
- “batch” — batch dimension (model I/O)
- “height”, “width” — spatial (image-like tensors)
Row-major strides are computed on construction for efficient flat-index calculations.
Public Functions Documentation
function DimensionDescriptor
explicit DimensionDescriptor(
std::vector< AxisDescriptor > axes
)Construct from a list of axis descriptors.
Parameters:
- axes Ordered list of axes (outermost first, innermost last)
Exceptions:
- std::invalid_argument if any axis has size == 0 or duplicate names exist
function DimensionDescriptor
DimensionDescriptor() =defaultDefault constructor — zero-dimensional (scalar) tensor.
function ndim
inline std::size_t ndim() constNumber of dimensions (axes).
function totalElements
std::size_t totalElements() constTotal number of elements (product of all axis sizes).
Returns 1 for a scalar (zero axes). Returns 0 only if an axis has size 0, which is disallowed by the constructor.
function shape
std::vector< std::size_t > shape() constGet the shape as a vector of sizes (one per axis).
function axis
AxisDescriptor const & axis(
std::size_t i
) constAccess an axis descriptor by positional index.
Exceptions:
- std::out_of_range if i >= ndim()
function findAxis
std::optional< std::size_t > findAxis(
std::string_view name
) constFind the positional index of an axis by name.
Return: The index, or std::nullopt if no axis has that name
function strides
inline std::vector< std::size_t > const & strides() constRow-major strides (precomputed).
stride[i] = product of sizes of axes i+1 .. ndim-1. For a scalar tensor, returns an empty vector.
function flatIndex
std::size_t flatIndex(
std::vector< std::size_t > const & indices
) constCompute the flat (row-major) index for a set of per-axis indices.
Parameters:
- indices One index per axis
Exceptions:
- std::invalid_argument if indices.size() != ndim()
- std::out_of_range if any index is out of bounds
Return: The flat offset into a row-major buffer
function is1D
inline bool is1D() constfunction is2D
inline bool is2D() constfunction is3D
inline bool is3D() constfunction isAtLeast
inline bool isAtLeast(
std::size_t n
) constfunction setAxisSize
void setAxisSize(
std::size_t axis_index,
std::size_t new_size
)Set the size of a specific axis and recompute strides.
Parameters:
- axis_index Positional index of the axis to resize
- new_size New size for the axis (must be > 0)
Exceptions:
- std::out_of_range if axis_index >= ndim()
- std::invalid_argument if new_size == 0
Note: This invalidates any previously set column names if the resized axis is the last axis.
Used by column mutation operations (append/remove) to keep the DimensionDescriptor in sync with the underlying storage.
function setColumnNames
void setColumnNames(
std::vector< std::string > names
)Assign human-readable names to columns (last axis).
Parameters:
- names Column names; must have size == last axis size
Exceptions:
- std::invalid_argument if names.size() doesn’t match last axis, or if input is provided on a scalar tensor
function columnNames
inline std::vector< std::string > const & columnNames() constGet the column names (empty if not set).
function hasColumnNames
inline bool hasColumnNames() constWhether column names have been assigned.
function findColumn
std::optional< std::size_t > findColumn(
std::string_view name
) constFind a column index by name.
Return: The column index, or std::nullopt if not found (or no column names set)
function operator==
bool operator==(
DimensionDescriptor const & other
) constfunction operator!=
inline bool operator!=(
DimensionDescriptor const & other
) constUpdated on 2026-11-13 at 20:25:41 +0000