Signet Forge 0.1.0
C++20 Parquet library with AI-native extensions
DEMO
Loading...
Searching...
No Matches
signet::forge::TensorView Class Reference

A lightweight, non-owning view into a contiguous block of typed memory, interpreted as a multi-dimensional tensor. More...

#include <tensor_bridge.hpp>

Public Member Functions

 TensorView ()=default
 Default constructor: creates an invalid (null) view.
 
 TensorView (void *data, TensorShape shape, TensorDataType dtype, size_t byte_stride=0) noexcept
 Construct a view over existing memory.
 
 TensorView (const void *data, TensorShape shape, TensorDataType dtype, size_t byte_stride=0) noexcept
 Construct a const view (stores as void* internally, constness enforced by the const overloads of data()/typed_data()).
 
void * data () noexcept
 Raw mutable pointer to the underlying data buffer.
 
const void * data () const noexcept
 Raw const pointer to the underlying data buffer.
 
template<typename T >
T * typed_data () noexcept
 Reinterpret the data pointer as a typed mutable pointer.
 
template<typename T >
const T * typed_data () const noexcept
 Reinterpret the data pointer as a typed const pointer.
 
const TensorShapeshape () const noexcept
 The shape of this tensor view.
 
TensorDataType dtype () const noexcept
 The element data type.
 
size_t element_size () const noexcept
 Bytes per element.
 
int64_t num_elements () const noexcept
 Total number of elements.
 
size_t byte_size () const noexcept
 Total byte size of the tensor data (num_elements * element_size).
 
size_t effective_byte_stride () const noexcept
 Effective stride in bytes along the first dimension.
 
template<typename T >
T & at (int64_t i)
 Access a single element in a 1D tensor (mutable).
 
template<typename T >
const T & at (int64_t i) const
 Access a single element in a 1D tensor (const).
 
template<typename T >
T & at (int64_t row, int64_t col)
 Access a single element in a 2D tensor by (row, col) (mutable).
 
template<typename T >
const T & at (int64_t row, int64_t col) const
 Access a single element in a 2D tensor by (row, col) (const).
 
bool is_contiguous () const noexcept
 True if the data is densely packed (no stride gaps).
 
bool is_valid () const noexcept
 True if the view points to valid data.
 
TensorView slice (int64_t start, int64_t count) const
 Slice along the first dimension: returns a view over rows [start, start+count).
 
expected< TensorViewreshape (TensorShape new_shape) const
 Reshape the view to a new shape with the same total number of elements.
 

Detailed Description

A lightweight, non-owning view into a contiguous block of typed memory, interpreted as a multi-dimensional tensor.

This is the core zero-copy type: wrapping existing Parquet column data as a TensorView involves no allocation or data movement. The caller is responsible for ensuring the underlying data remains valid for the lifetime of the view.

The optional byte_stride parameter supports non-contiguous views (e.g. a single column extracted from a row-major matrix). When byte_stride is 0 (the default), the data is assumed to be densely packed.

Definition at line 274 of file tensor_bridge.hpp.

Constructor & Destructor Documentation

◆ TensorView() [1/3]

signet::forge::TensorView::TensorView ( )
default

Default constructor: creates an invalid (null) view.

◆ TensorView() [2/3]

signet::forge::TensorView::TensorView ( void *  data,
TensorShape  shape,
TensorDataType  dtype,
size_t  byte_stride = 0 
)
inlinenoexcept

Construct a view over existing memory.

Parameters
dataPointer to the start of the data buffer.
shapeShape of the tensor.
dtypeElement data type.
byte_strideStride in bytes between consecutive elements along the first axis. 0 means contiguous (dense packing).

Definition at line 286 of file tensor_bridge.hpp.

◆ TensorView() [3/3]

signet::forge::TensorView::TensorView ( const void *  data,
TensorShape  shape,
TensorDataType  dtype,
size_t  byte_stride = 0 
)
inlinenoexcept

Construct a const view (stores as void* internally, constness enforced by the const overloads of data()/typed_data()).

Definition at line 295 of file tensor_bridge.hpp.

Member Function Documentation

◆ at() [1/4]

template<typename T >
T & signet::forge::TensorView::at ( int64_t  i)
inline

Access a single element in a 1D tensor (mutable).

Template Parameters
TElement type (must match dtype()).
Parameters
iZero-based element index.
Returns
Reference to the element.
Exceptions
std::out_of_rangeif index is invalid or data is null.

Definition at line 370 of file tensor_bridge.hpp.

◆ at() [2/4]

template<typename T >
const T & signet::forge::TensorView::at ( int64_t  i) const
inline

Access a single element in a 1D tensor (const).

Template Parameters
TElement type (must match dtype()).
Parameters
iZero-based element index.
Returns
Const reference to the element.
Exceptions
std::out_of_rangeif index is invalid or data is null.

Definition at line 391 of file tensor_bridge.hpp.

◆ at() [3/4]

template<typename T >
T & signet::forge::TensorView::at ( int64_t  row,
int64_t  col 
)
inline

Access a single element in a 2D tensor by (row, col) (mutable).

Template Parameters
TElement type (must match dtype()).
Parameters
rowZero-based row index.
colZero-based column index.
Returns
Reference to the element.
Exceptions
std::out_of_rangeif indices are invalid or data is null.

Definition at line 413 of file tensor_bridge.hpp.

◆ at() [4/4]

template<typename T >
const T & signet::forge::TensorView::at ( int64_t  row,
int64_t  col 
) const
inline

Access a single element in a 2D tensor by (row, col) (const).

Template Parameters
TElement type (must match dtype()).
Parameters
rowZero-based row index.
colZero-based column index.
Returns
Const reference to the element.
Exceptions
std::out_of_rangeif indices are invalid or data is null.

Definition at line 438 of file tensor_bridge.hpp.

◆ byte_size()

size_t signet::forge::TensorView::byte_size ( ) const
inlinenoexcept

Total byte size of the tensor data (num_elements * element_size).

Returns 0 if num_elements() is non-positive (empty or error shape).

Definition at line 343 of file tensor_bridge.hpp.

◆ data() [1/2]

const void * signet::forge::TensorView::data ( ) const
inlinenoexcept

Raw const pointer to the underlying data buffer.

Definition at line 307 of file tensor_bridge.hpp.

◆ data() [2/2]

void * signet::forge::TensorView::data ( )
inlinenoexcept

Raw mutable pointer to the underlying data buffer.

Definition at line 305 of file tensor_bridge.hpp.

◆ dtype()

TensorDataType signet::forge::TensorView::dtype ( ) const
inlinenoexcept

The element data type.

Definition at line 329 of file tensor_bridge.hpp.

◆ effective_byte_stride()

size_t signet::forge::TensorView::effective_byte_stride ( ) const
inlinenoexcept

Effective stride in bytes along the first dimension.

If byte_stride_ is 0 (contiguous), computes the dense stride.

Definition at line 351 of file tensor_bridge.hpp.

◆ element_size()

size_t signet::forge::TensorView::element_size ( ) const
inlinenoexcept

Bytes per element.

Definition at line 332 of file tensor_bridge.hpp.

◆ is_contiguous()

bool signet::forge::TensorView::is_contiguous ( ) const
inlinenoexcept

True if the data is densely packed (no stride gaps).

Definition at line 459 of file tensor_bridge.hpp.

◆ is_valid()

bool signet::forge::TensorView::is_valid ( ) const
inlinenoexcept

True if the view points to valid data.

Definition at line 464 of file tensor_bridge.hpp.

◆ num_elements()

int64_t signet::forge::TensorView::num_elements ( ) const
inlinenoexcept

Total number of elements.

Definition at line 337 of file tensor_bridge.hpp.

◆ reshape()

expected< TensorView > signet::forge::TensorView::reshape ( TensorShape  new_shape) const
inline

Reshape the view to a new shape with the same total number of elements.

Only valid for contiguous views. Returns an error if:

  • the view is non-contiguous (has a non-zero byte_stride)
  • the total element count does not match

Definition at line 501 of file tensor_bridge.hpp.

◆ shape()

const TensorShape & signet::forge::TensorView::shape ( ) const
inlinenoexcept

The shape of this tensor view.

Definition at line 327 of file tensor_bridge.hpp.

◆ slice()

TensorView signet::forge::TensorView::slice ( int64_t  start,
int64_t  count 
) const
inline

Slice along the first dimension: returns a view over rows [start, start+count).

Zero-copy: the returned view's data pointer is offset into this view's buffer. No data is copied.

Parameters
startFirst row index (inclusive).
countNumber of rows.
Returns
A new TensorView covering the requested slice.

Definition at line 478 of file tensor_bridge.hpp.

◆ typed_data() [1/2]

template<typename T >
const T * signet::forge::TensorView::typed_data ( ) const
inlinenoexcept

Reinterpret the data pointer as a typed const pointer.

Template Parameters
TElement type (e.g. float, double, int32_t).

Definition at line 320 of file tensor_bridge.hpp.

◆ typed_data() [2/2]

template<typename T >
T * signet::forge::TensorView::typed_data ( )
inlinenoexcept

Reinterpret the data pointer as a typed mutable pointer.

The caller is responsible for ensuring T matches dtype().

Template Parameters
TElement type (e.g. float, double, int32_t).

Definition at line 313 of file tensor_bridge.hpp.


The documentation for this class was generated from the following file: