Skip to content

Tensor


matrix_transpose function

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

Matrix transpose. Accepts vec, complex and other compound types


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_iterator

Tensor iterator. Iterates through flattened array

tensor<T, NDims> function

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 <typename U, KFR_ENABLE_IF(std::is_convertible_v<
                                        U, T> &&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 <typename U, KFR_ENABLE_IF(std::is_convertible_v<
                                        U, T> &&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 <typename U, KFR_ENABLE_IF(std::is_convertible_v<
                                        U, T> &&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


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