Skip to content

tensor


npy_writer class (internal_generic::npy_writer)

template <typename Fn> npy_writer

npy_reader class (internal_generic::npy_reader)

template <typename Fn> npy_reader

npy_header class (internal_generic::npy_header)

npy_header

save_to_npy function

template <typename T, index_t Dims, typename Fn>
void save_to_npy(const tensor<T, Dims> &t,
                 Fn &&write_callback)

Saves a tensor to .npy format using a custom write callback.

The write callback must match the signature: void(const void* data, size_t write_size)
Template param T Element type of the tensor.
Template param Dims Number of dimensions.
Template param Fn Write callback type.
Param t Tensor to save.
Param write_callback Callback used to write binary data.


npy_decode_result enum

enum class npy_decode_result

Status returned by the .npy loading function.

ok enumerator (npy_decode_result::ok)

Successfully loaded

cannot_read enumerator (npy_decode_result::cannot_read)

Failed to read data or header

invalid_header enumerator (npy_decode_result::invalid_header)

Malformed header

invalid_type enumerator (npy_decode_result::invalid_type)

Type mismatch

invalid_shape enumerator (npy_decode_result::invalid_shape)

Shape mismatch


load_from_npy function

template <typename T, index_t Dims, typename Fn>
npy_decode_result load_from_npy(tensor<T, Dims> &result,
                                Fn &&read_callback)

Loads a tensor from .npy format using a custom read callback.

The read callback must match the signature: bool(void* data, size_t read_size)
Template param T Element type of the tensor.
Template param Dims Number of dimensions.
Template param Fn Read callback type.
Param result Tensor to populate with loaded data.
Param read_callback Callback used to read binary data.
Returns Status code indicating success or failure reason.


representation class

representation

memory_finalizer_base class (internal_generic::memory_finalizer_base)

memory_finalizer_base

memory_finalizer_data class (internal_generic::memory_finalizer_data)

template <typename Data> memory_finalizer_data

memory_finalizer_func class (internal_generic::memory_finalizer_func)

template <typename Func> memory_finalizer_func

tensor_subscript class

template <typename T, typename Derived, typename Dims>
tensor_subscript

template <typename T, typename Derived, index_t... Dims>
tensor_subscript

tensor class

template <typename T, index_t NDims> tensor

tensor holds or references multidimensional data and provides a way to access individual elements and perform complex operations on the data.

The number of elements in each axis of the array is defined by its shape.
Template param T element type
Template param NDims number of dimensions

tensor_iterator class (tensor::tensor_iterator)

tensor_iterator

Tensor iterator. Iterates through flattened array

tensor<T, NDims> function (tensor::tensor<T, NDims>)

constexpr tensor()
    : m_data(0), m_size(0), m_is_contiguous(false), m_shape

Default constructor. Creates tensor with null shape

tensor(T *data, const shape_type &shape,
       const shape_type &strides,
       memory_finalizer finalizer)
    : m_data(data), m_size(size_of_shape(shape)),
      m_is_contiguous(
          strides ==
          internal_generic::strides_for_shape(shape)),
      m_shape(shape), m_strides(strides),
      m_finalizer(std::move(finalizer))

Construct from external pointer, shape, strides and finalizer

tensor(T *data, const shape_type &shape,
       memory_finalizer finalizer)
    : m_data(data), m_size(size_of_shape(shape)),
      m_is_contiguous(true), m_shape(shape),
      m_strides(internal_generic::strides_for_shape(shape)),
      m_finalizer(std::move(finalizer))

Construct from external pointer, shape and finalizer with default strides

explicit tensor(const shape_type &shape)
    : m_size(size_of_shape(shape)), m_is_contiguous(true),
      m_shape(shape),
      m_strides(internal_generic::strides_for_shape(shape))

Construct from shape and allocate memory

tensor(const shape_type &shape, const shape_type &strides)
    : m_size(size_of_shape(shape)),
      m_is_contiguous(
          strides ==
          internal_generic::strides_for_shape(shape)),
      m_shape(shape), m_strides(strides)

Construct from shape, strides and allocate memory

tensor(const shape_type &shape, T value) : tensor(shape)

Construct from shape, allocate memory and fill with value

tensor(const shape_type &shape, const shape_type &strides,
       T value)
    : tensor(shape, strides)

Construct from shape, strides, allocate memory and fill with value

tensor(const shape_type &shape,
       const std::initializer_list<T> &values)
    : tensor(shape)

Construct from shape, allocate memory and fill with flat list

template <typename U, KFR_ENABLE_IF(std::is_convertible_v<
                                        U, T> &&dims == 1)>
tensor(const std::initializer_list<U> &values)
    : tensor(shape_type(values.size()))

Initialize with braced list. Defined for 1D tensor only

template <std::convertible_to<T> U>
  requires(dims == 2)
tensor(const std::initializer_list<std::initializer_list<U>>
           &values)
    : tensor(
          shape_type(values.size(), values.begin()->size()))

Initialize with braced list. Defined for 2D tensor only

template <std::convertible_to<T> U>
  requires(dims == 3)
tensor(const std::initializer_list<std::initializer_list<
           std::initializer_list<U>>> &values)
    : tensor(shape_type(values.size(),
                        values.begin()->size(),
                        values.begin()->begin()->size()))

Initialize with braced list. Defined for 3D tensor only

template <std::convertible_to<T> U>
  requires(dims == 4)
tensor(const std::initializer_list<std::initializer_list<
           std::initializer_list<std::initializer_list<U>>>>
           &values)
    : tensor(shape_type(
          values.size(), values.begin()->size(),
          values.begin()->begin()->size(),
          values.begin()->begin()->begin()->size()))

Initialize with braced list. Defined for 4D tensor only

nested_iterator_t class (tensor::nested_iterator_t)

nested_iterator_t

tensor class

template <typename T> tensor

expression_traits class

template <typename T, index_t Dims> expression_traits

representation class

template <typename T, kfr::index_t dims> representation

template <char t, int width, int prec, typename T,
          kfr::index_t dims>
representation

matrix_size class (generic::internal::matrix_size)

matrix_size

matrix_cycles class (generic::internal::matrix_cycles)

matrix_cycles

matrix_transpose function (generic::matrix_transpose)

template <typename T, index_t Dims>
void matrix_transpose(T *out, const T *in,
                      shape<Dims> shape)

Transposes a matrix (supports scalar and compound types).

Works with both scalar types (e.g., float, int) and compound types (e.g., vec, complex). The input matrix must be packed in memory (no padding between rows or columns). In-place transpose (when in and out point to the same buffer) is supported.
Template param T Element type (scalar or compound).
Template param Dims Number of dimensions (2 or greater).
Param out Output buffer (transposed matrix).
Param in Input buffer (original matrix).
Param shape Shape of the input matrix.


Auto-generated from sources, Revision , https://github.com/kfrlib/kfr/blob//include/kfr/