Skip to content

Class tensor

class tensor<T, NDims> base

template <typename T, index_t NDims>
struct tensor : public tensor_subscript<T, tensor<T, NDims>, std::make_integer_sequence<index_t, NDims>> { … }

Holds or references multidimensional data and provides access to individual elements and complex operations on the data.

The number of elements in each axis of the array is defined by its shape. A tensor may own its data (allocated on construction) or reference externally owned data through a memory finalizer.

Template parameters
T element type.
NDims number of dimensions.

typedef value_type

using value_type      = T

Fully qualified name: kfr::tensor<T, NDims>::value_type

Declared at base/tensor.hpp:142

typedef pointer

using pointer         = T*

Fully qualified name: kfr::tensor<T, NDims>::pointer

Declared at base/tensor.hpp:143

typedef const_pointer

using const_pointer   = const T*

Fully qualified name: kfr::tensor<T, NDims>::const_pointer

Declared at base/tensor.hpp:144

typedef reference

using reference       = T&

Fully qualified name: kfr::tensor<T, NDims>::reference

Declared at base/tensor.hpp:145

typedef const_reference

using const_reference = const T&

Fully qualified name: kfr::tensor<T, NDims>::const_reference

Declared at base/tensor.hpp:146

typedef size_type

using size_type       = index_t

Fully qualified name: kfr::tensor<T, NDims>::size_type

Declared at base/tensor.hpp:147

variable dims

constexpr static inline index_t dims = NDims

Number of dimensions.

Fully qualified name: kfr::tensor<T, NDims>::dims

Declared at base/tensor.hpp:149

typedef shape_type

using shape_type = kfr::shape<dims>

Fully qualified name: kfr::tensor<T, NDims>::shape_type

Declared at base/tensor.hpp:151

struct tensor_iterator

struct tensor_iterator { … }

Tensor iterator. Iterates through the flattened array in row-major order.

typedef iterator_category

using iterator_category = std::forward_iterator_tag

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::iterator_category

Declared at base/tensor.hpp:156

typedef difference_type

using difference_type   = std::ptrdiff_t

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::difference_type

Declared at base/tensor.hpp:157

typedef value_type

using value_type        = T

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::value_type

Declared at base/tensor.hpp:158

typedef pointer

using pointer           = T*

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::pointer

Declared at base/tensor.hpp:159

typedef reference

using reference         = T&

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::reference

Declared at base/tensor.hpp:160

variable src

const tensor* src

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::src

Declared at base/tensor.hpp:162

variable indices

shape_type indices

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::indices

Declared at base/tensor.hpp:163

function flat_index()

Returns the flat (linear) index of the current element.

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::flat_index()

Declared at base/tensor.hpp:166

function is_end()

Returns true if this iterator is the end sentinel.

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::is_end()

Declared at base/tensor.hpp:169

function operator*()

Dereferences the iterator to the referenced element.

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::operator*()

Declared at base/tensor.hpp:172

function operator->()

Accesses the referenced element by pointer.

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::operator->()

Declared at base/tensor.hpp:174

function operator++()

Prefix increment, advancing to the next element in row-major order.

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::operator++()

Declared at base/tensor.hpp:178

function operator++(int)

Postfix increment.

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::operator++(int)

Declared at base/tensor.hpp:189

function operator==(const tensor_iterator &)

Returns true if two iterators refer to the same position.

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::operator==(const tensor_iterator &)

Declared at base/tensor.hpp:197

function operator!=(const tensor_iterator &)

Returns true if two iterators refer to different positions.

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator::operator!=(const tensor_iterator &)

Declared at base/tensor.hpp:202

Fully qualified name: kfr::tensor<T, NDims>::tensor_iterator

Declared at base/tensor.hpp:154

typedef iterator

using iterator       = tensor_iterator

Fully qualified name: kfr::tensor<T, NDims>::iterator

Declared at base/tensor.hpp:205

typedef const_iterator

using const_iterator = tensor_iterator

Fully qualified name: kfr::tensor<T, NDims>::const_iterator

Declared at base/tensor.hpp:206

typedef contiguous_iterator

using contiguous_iterator       = pointer

Fully qualified name: kfr::tensor<T, NDims>::contiguous_iterator

Declared at base/tensor.hpp:208

typedef const_contiguous_iterator

using const_contiguous_iterator = pointer

Fully qualified name: kfr::tensor<T, NDims>::const_contiguous_iterator

Declared at base/tensor.hpp:209

constructor tensor<T, NDims>()

Default constructor. Creates a tensor with a null shape.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>()

Declared at base/tensor.hpp:212

constructor tensor<T, NDims>(T *, const shape_type &, const shape_type &, memory_finalizer)

Constructs a tensor from an external pointer, shape, strides, and finalizer.

Parameters
data pointer to the external data.
shape shape of the tensor.
strides strides of the tensor.
finalizer memory finalizer keeping data alive.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(T *, const shape_type &, const shape_type &, memory_finalizer)

Declared at base/tensor.hpp:222

constructor tensor<T, NDims>(T *, const shape_type &, memory_finalizer)

Constructs a tensor from an external pointer, shape, and finalizer using default strides.

Parameters
data pointer to the external data.
shape shape of the tensor.
finalizer memory finalizer keeping data alive.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(T *, const shape_type &, memory_finalizer)

Declared at base/tensor.hpp:234

function allocate(size_t)

Allocates aligned memory for size elements.

Returns
Pointer to the allocated memory.

Fully qualified name: kfr::tensor<T, NDims>::allocate(size_t)

Declared at base/tensor.hpp:242

function deallocate(T *)

Deallocates memory previously returned by allocate().

Parameters
ptr pointer returned by allocate().

Fully qualified name: kfr::tensor<T, NDims>::deallocate(T *)

Declared at base/tensor.hpp:246

function has_contiguous_strides(const shape_type &, const shape_type &)

Returns true if strides describe a packed layout in some axis order.

Unit-length axes do not affect storage offsets and are ignored. This accepts row-major, column-major, and other permutations of contiguous axes, but rejects padding and overlap.

Fully qualified name: kfr::tensor<T, NDims>::has_contiguous_strides(const shape_type &, const shape_type &)

Declared at base/tensor.hpp:252

constructor tensor<T, NDims>(const shape_type &)

Constructs a tensor with the given shape and allocates memory for it.

Parameters
shape shape of the tensor.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(const shape_type &)

Declared at base/tensor.hpp:298

constructor tensor<T, NDims>(const shape_type &, const shape_type &)

Constructs a tensor with the given shape and a packed stride layout.

The strides must describe row-major, column-major, or another packed permutation of the axes. Padded, overlapping, and otherwise non-contiguous layouts require external storage.

Parameters
shape shape of the tensor.
strides strides of the tensor.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(const shape_type &, const shape_type &)

Declared at base/tensor.hpp:313

constructor tensor<T, NDims>(const shape_type &, T)

Constructs a tensor with the given shape, allocates memory, and fills it with value.

Parameters
shape shape of the tensor.
value value to fill the tensor with.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(const shape_type &, T)

Declared at base/tensor.hpp:328

constructor tensor<T, NDims>(const shape_type &, const shape_type &, T)

Constructs a tensor with the given shape and strides, allocates memory, and fills it with value .

Parameters
shape shape of the tensor.
strides strides of the tensor.
value value to fill the tensor with.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(const shape_type &, const shape_type &, T)

Declared at base/tensor.hpp:338

constructor tensor<T, NDims>(const shape_type &, const std::initializer_list<T> &)

Constructs a tensor with the given shape, allocates memory, and fills it from a flat initializer list.

Parameters
shape shape of the tensor.
values flat initializer list of values.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(const shape_type &, const std::initializer_list<T> &)

Declared at base/tensor.hpp:347

function tensor<T, NDims>(const std::initializer_list<U> &)

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

Initializes a 1D tensor from a braced list. Defined for 1D tensors only.

Parameters
values initializer list of values.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(const std::initializer_list<U> &)

Declared at base/tensor.hpp:358

function tensor<T, NDims>(const std::initializer_list<std::initializer_list<U>> &)

template <std::convertible_to<T> U>
    requires(dims == 2)
KFR_INTRINSIC tensor(const std::initializer_list<std::initializer_list<U>>& values)

Initializes a 2D tensor from a braced list. Defined for 2D tensors only.

Parameters
values nested initializer list of values.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(const std::initializer_list<std::initializer_list<U>> &)

Declared at base/tensor.hpp:368

function tensor<T, NDims>(const std::initializer_list<std::initializer_list<std::initializer_list<U>>> &)

template <std::convertible_to<T> U>
    requires(dims == 3)
KFR_INTRINSIC tensor(const std::initializer_list<std::initializer_list<std::initializer_list<U>>>& values)

Initializes a 3D tensor from a braced list. Defined for 3D tensors only.

Parameters
values nested initializer list of values.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(const std::initializer_list<std::initializer_list<std::initializer_list<U>>> &)

Declared at base/tensor.hpp:379

function tensor<T, NDims>(const std::initializer_list<std::initializer_list<std::initializer_list<std::initializer_list<U>>>> &)

template <std::convertible_to<T> U>
    requires(dims == 4)
KFR_INTRINSIC tensor(
    const std::initializer_list<std::initializer_list<std::initializer_list<std::initializer_list<U>>>>&
        values)

Initializes a 4D tensor from a braced list. Defined for 4D tensors only.

Parameters
values nested initializer list of values.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(const std::initializer_list<std::initializer_list<std::initializer_list<std::initializer_list<U>>>> &)

Declared at base/tensor.hpp:390

constructor tensor<T, NDims>(const shape_type &, const shape_type &, std::initializer_list<T>)

Constructs a tensor with the given shape and strides and fills it from a flat initializer list.

Parameters
shape shape of the tensor.
strides strides of the tensor.
values flat initializer list of values.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(const shape_type &, const shape_type &, std::initializer_list<T>)

Declared at base/tensor.hpp:403

function tensor<T, NDims>(Input &&)

template <expression_argument Input>
KFR_MEM_INTRINSIC tensor(Input&& input)

Constructs a tensor by evaluating an expression.

Parameters
input expression to evaluate and store in the tensor.

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(Input &&)

Declared at base/tensor.hpp:414

function data()

Returns a pointer to the underlying data.

Fully qualified name: kfr::tensor<T, NDims>::data()

Declared at base/tensor.hpp:421

function size()

Returns the total number of elements in the tensor.

Fully qualified name: kfr::tensor<T, NDims>::size()

Declared at base/tensor.hpp:424

function empty()

Returns true if the tensor has no elements.

Fully qualified name: kfr::tensor<T, NDims>::empty()

Declared at base/tensor.hpp:427

function begin()

Returns an iterator to the first element.

Fully qualified name: kfr::tensor<T, NDims>::begin()

Declared at base/tensor.hpp:430

function end()

Returns the end sentinel iterator.

Fully qualified name: kfr::tensor<T, NDims>::end()

Declared at base/tensor.hpp:438

function require_contiguous()

Throws if the tensor is not contiguous.

Fully qualified name: kfr::tensor<T, NDims>::require_contiguous()

Declared at base/tensor.hpp:444

function contiguous_begin()

Returns a contiguous iterator to the first element. The tensor must be contiguous.

Fully qualified name: kfr::tensor<T, NDims>::contiguous_begin()

Declared at base/tensor.hpp:452

function contiguous_end()

Returns a contiguous iterator past the last element. The tensor must be contiguous.

Fully qualified name: kfr::tensor<T, NDims>::contiguous_end()

Declared at base/tensor.hpp:459

function contiguous_begin_unsafe()

Returns a contiguous iterator to the first element without checking contiguity.

Fully qualified name: kfr::tensor<T, NDims>::contiguous_begin_unsafe()

Declared at base/tensor.hpp:466

function contiguous_end_unsafe()

Returns a contiguous iterator past the last element without checking contiguity.

Fully qualified name: kfr::tensor<T, NDims>::contiguous_end_unsafe()

Declared at base/tensor.hpp:468

function calc_index(const shape_type &)

Computes the linear offset of the element at indices using the tensor's strides.

Parameters
indices multi-dimensional index.
Returns
Flat offset into the underlying data.

Fully qualified name: kfr::tensor<T, NDims>::calc_index(const shape_type &)

Declared at base/tensor.hpp:473

function access(const shape_type &)

Returns a reference to the element at indices.

Parameters
indices multi-dimensional index.
Returns
Reference to the element.

Fully qualified name: kfr::tensor<T, NDims>::access(const shape_type &)

Declared at base/tensor.hpp:481

function operator[](index_t)

Returns a reference to the element at the given flat index.

Parameters
flat_index linear offset into the underlying data.

Fully qualified name: kfr::tensor<T, NDims>::operator[](index_t)

Declared at base/tensor.hpp:488

function operator()(const shape_type &, const shape_type &)

Returns a sub-tensor (slice) spanning from start to stop.

Parameters
start starting indices of the slice.
stop stopping indices of the slice (exclusive).
Returns
New tensor referencing the sliced region.

Fully qualified name: kfr::tensor<T, NDims>::operator()(const shape_type &, const shape_type &)

Declared at base/tensor.hpp:494

constructor tensor<T, NDims>(const tensor<T, NDims> &)

tensor(const tensor&) = default

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(const tensor<T, NDims> &)

Declared at base/tensor.hpp:522

constructor tensor<T, NDims>(tensor<T, NDims> &&)

tensor(tensor&&)      = default

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(tensor<T, NDims> &&)

Declared at base/tensor.hpp:523

constructor tensor<T, NDims>(tensor<T, NDims> &)

tensor(tensor& other)

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(tensor<T, NDims> &)

Declared at base/tensor.hpp:524

constructor tensor<T, NDims>(const tensor<T, NDims> &&)

tensor(const tensor&& other)

Fully qualified name: kfr::tensor<T, NDims>::tensor<T, NDims>(const tensor<T, NDims> &&)

Declared at base/tensor.hpp:525

function operator=(const tensor<T, NDims> &)

tensor& operator=(const tensor& src) &

Copy-assigns the tensor, sharing the data of src.

Parameters
src tensor to copy from.
Returns
Reference to *this.

Fully qualified name: kfr::tensor<T, NDims>::operator=(const tensor<T, NDims> &)

Declared at base/tensor.hpp:532

function operator=(tensor<T, NDims> &&)

tensor& operator=(tensor&& src) &

Move-assigns the tensor from src.

Parameters
src tensor to move from.
Returns
Reference to *this.

Fully qualified name: kfr::tensor<T, NDims>::operator=(tensor<T, NDims> &&)

Declared at base/tensor.hpp:541

function operator=(const tensor<T, NDims> &)

Copy-assigns the tensor from src (const overload).

Parameters
src tensor to copy from.
Returns
Reference to *this.

Fully qualified name: kfr::tensor<T, NDims>::operator=(const tensor<T, NDims> &)

Declared at base/tensor.hpp:555

function operator=(const tensor<T, NDims> &)

Copy-assigns the tensor from src (rvalue overload).

Parameters
src tensor to copy from.
Returns
Reference to *this.

Fully qualified name: kfr::tensor<T, NDims>::operator=(const tensor<T, NDims> &)

Declared at base/tensor.hpp:563

function operator=(const T &)

Fills the tensor with a scalar value (const overload).

Parameters
scalar value to assign to every element.
Returns
Reference to *this.

Fully qualified name: kfr::tensor<T, NDims>::operator=(const T &)

Declared at base/tensor.hpp:571

function operator=(const T &)

Fills the tensor with a scalar value (rvalue overload).

Parameters
scalar value to assign to every element.
Returns
Reference to *this.

Fully qualified name: kfr::tensor<T, NDims>::operator=(const T &)

Declared at base/tensor.hpp:579

function assign(const tensor<T, NDims> &)

Copies the contents of src into this tensor. Both tensors must have the same shape.

Parameters
src tensor to copy from.

Fully qualified name: kfr::tensor<T, NDims>::assign(const tensor<T, NDims> &)

Declared at base/tensor.hpp:588

function assign(const T &)

Fills the tensor with a scalar value.

Parameters
scalar value to assign to every element.

Fully qualified name: kfr::tensor<T, NDims>::assign(const T &)

Declared at base/tensor.hpp:596

variable has_tensor_range

template <typename... Index>
static constexpr bool has_tensor_range = (std::is_same_v<Index, tensor_range> || ...)

Returns true if any of Index... is a tensor_range.

Fully qualified name: kfr::tensor<T, NDims>::has_tensor_range

Declared at base/tensor.hpp:600

function get_range(index_t &, index_t &, index_t &, signed_index_t, index_t)

Computes the range for a single integer index.

Parameters
start computed start offset.
shape computed shape (0 or 1).
step computed step.
tsize size of the axis.
iidx integer index (negative values count from the end).

Fully qualified name: kfr::tensor<T, NDims>::get_range(index_t &, index_t &, index_t &, signed_index_t, index_t)

Declared at base/tensor.hpp:608

function get_range(index_t &, index_t &, index_t &, signed_index_t, const tensor_range &)

Computes the range for a tensor_range specifier. Handles optional start/stop/step, negative indices, and clamping to the axis size.

Parameters
start computed start offset.
shape computed number of elements in the range.
step computed step.
tsize size of the axis.
iidx tensor_range describing the slice.

Fully qualified name: kfr::tensor<T, NDims>::get_range(index_t &, index_t &, index_t &, signed_index_t, const tensor_range &)

Declared at base/tensor.hpp:625

function get_ranges(shape_type &, shape_type &, shape_type &, cvals_t<index_t, Num...>, const std::tuple<Index...> &)

template <index_t... Num, typename... Index>
KFR_MEM_INTRINSIC void get_ranges(shape_type& start, shape_type& shape, shape_type& step,
                                  cvals_t<index_t, Num...> indices, const std::tuple<Index...>& idx) const

Computes the start, shape, and step for each axis given a set of indices and ranges. Axes without a corresponding index cover the full extent of the axis.

Parameters
start computed start offsets per axis.
shape computed shape per axis.
step computed step per axis.
indices compile-time axis index sequence.
idx tuple of indices and ranges.

Fully qualified name: kfr::tensor<T, NDims>::get_ranges(shape_type &, shape_type &, shape_type &, cvals_t<index_t, Num...>, const std::tuple<Index...> &)

Declared at base/tensor.hpp:681

function operator()(const Index &...)

template <typename... Index,
          size_t ndimOut = internal_generic::count_dimensions<Index...>() + (dims - sizeof...(Index)),
          std::enable_if_t<has_tensor_range<Index...> || (sizeof...(Index) < dims)>* = nullptr>
KFR_MEM_INTRINSIC tensor<T, ndimOut> operator()(const Index&... idx) const

Returns a sub-tensor (slice) selected by a mix of integer indices and tensor_range specifiers. Axes indexed by integers are removed from the result; axes indexed by tensor_range are kept.

Parameters
idx... one index or range per axis (trailing axes may be omitted to select the full extent).
Returns
New tensor referencing the sliced region.

Fully qualified name: kfr::tensor<T, NDims>::operator()(const Index &...)

Declared at base/tensor.hpp:709

function transpose()

Returns a tensor with the order of axes reversed. For 0D and 1D tensors returns *this.

Returns
New tensor referencing the same data with transposed shape and strides.

Fully qualified name: kfr::tensor<T, NDims>::transpose()

Declared at base/tensor.hpp:734

function reshape_may_copy(const kfr::shape<dims> &, bool)

template <index_t dims>
KFR_MEM_INTRINSIC tensor<T, dims> reshape_may_copy(const kfr::shape<dims>& new_shape,
                                                   bool allow_copy = true) const

Returns a tensor with a different shape, copying if necessary.

Template parameters
dims number of dimensions of the result.
Parameters
new_shape new shape; must have the same total number of elements.
allow_copy if true, a copy is made when the tensor is not contiguous; otherwise an error is reported for non-contiguous tensors.
Returns
New tensor with the requested shape.

Fully qualified name: kfr::tensor<T, NDims>::reshape_may_copy(const kfr::shape<dims> &, bool)

Declared at base/tensor.hpp:758

function reshape(const kfr::shape<dims> &)

template <index_t dims>
KFR_MEM_INTRINSIC tensor<T, dims> reshape(const kfr::shape<dims>& new_shape) const

Returns a tensor with a different shape without copying. The tensor must be contiguous.

Template parameters
dims number of dimensions of the result.
Parameters
new_shape new shape; must have the same total number of elements.
Returns
New tensor with the requested shape.

Fully qualified name: kfr::tensor<T, NDims>::reshape(const kfr::shape<dims> &)

Declared at base/tensor.hpp:798

function flatten()

Returns a 1D tensor view of the data.

Fully qualified name: kfr::tensor<T, NDims>::flatten()

Declared at base/tensor.hpp:804

function flatten_may_copy(bool)

Returns a 1D tensor view of the data, copying if necessary.

Parameters
allow_copy if true, a copy is made when the tensor is not contiguous.
Returns
New 1D tensor.

Fully qualified name: kfr::tensor<T, NDims>::flatten_may_copy(bool)

Declared at base/tensor.hpp:809

function copy()

Returns a deep copy of the tensor.

Fully qualified name: kfr::tensor<T, NDims>::copy()

Declared at base/tensor.hpp:815

function copy_from(const tensor<T, NDims> &)

Copies the contents of other into this tensor.

Parameters
other tensor to copy from.

Fully qualified name: kfr::tensor<T, NDims>::copy_from(const tensor<T, NDims> &)

Declared at base/tensor.hpp:824

function iterate(Fn &&)

template <typename Fn>
KFR_MEM_INTRINSIC void iterate(Fn&& fn) const

Calls fn for each element together with its multi-dimensional index.

Parameters
fn callable invoked as fn(element, indices).

Fully qualified name: kfr::tensor<T, NDims>::iterate(Fn &&)

Declared at base/tensor.hpp:829

function map(Fn &&)

template <typename Fn, typename Tout = std::invoke_result_t<Fn, T>>
KFR_MEM_INTRINSIC tensor<Tout, dims> map(Fn&& fn) const

Applies fn to each element and returns the resulting tensor.

Template parameters
Fn unary callable type.
Parameters
fn callable returning the new element value.
Returns
New tensor with the result of applying fn to each element.

Fully qualified name: kfr::tensor<T, NDims>::map(Fn &&)

Declared at base/tensor.hpp:844

function unary(Fn &&)

template <typename Fn, typename Tout = std::invoke_result_t<Fn, T>>
KFR_MEM_INTRINSIC tensor<Tout, dims> unary(Fn&& fn) const

Applies a unary function to each element and returns the resulting tensor.

Template parameters
Fn unary callable type.
Parameters
fn callable returning the new element value.
Returns
New tensor with the result of applying fn to each element.

Fully qualified name: kfr::tensor<T, NDims>::unary(Fn &&)

Declared at base/tensor.hpp:854

function unary_inplace(Fn &&)

template <typename Fn>
KFR_MEM_INTRINSIC const tensor& unary_inplace(Fn&& fn) const

Applies fn to each element in place.

Template parameters
Fn unary callable type.
Parameters
fn callable returning the new element value.
Returns
Reference to *this.

Fully qualified name: kfr::tensor<T, NDims>::unary_inplace(Fn &&)

Declared at base/tensor.hpp:886

function reduce(Fn &&, T)

template <typename Fn>
KFR_MEM_INTRINSIC T reduce(Fn&& fn, T initial = T { … }

Reduces all elements using fn and an initial value.

Template parameters
Fn binary callable type.
Parameters
fn callable invoked as fn(element, accumulator).
initial initial value of the accumulator.
Returns
The final accumulator value.

Fully qualified name: kfr::tensor<T, NDims>::reduce(Fn &&, T)

Declared at base/tensor.hpp:915

function binary(const tensor<U, dims> &, Fn &&)

template <typename Fn, typename U, typename Tout = std::invoke_result_t<Fn, T, U>>
KFR_MEM_INTRINSIC tensor<Tout, dims> binary(const tensor<U, dims>& rhs, Fn&& fn) const

Applies a binary function element-wise with rhs and returns the resulting tensor.

Template parameters
Fn binary callable type.
U element type of rhs.
Parameters
rhs right-hand tensor; must have the same shape as *this.
fn callable invoked as fn(lhs_element, rhs_element).
Returns
New tensor with the result of the element-wise operation.

Fully qualified name: kfr::tensor<T, NDims>::binary(const tensor<U, dims> &, Fn &&)

Declared at base/tensor.hpp:946

function binary_inplace(const tensor<U, dims> &, Fn &&)

template <typename Fn, typename U>
KFR_MEM_INTRINSIC const tensor& binary_inplace(const tensor<U, dims>& rhs, Fn&& fn) const

Applies a binary function element-wise with rhs in place.

Template parameters
Fn binary callable type.
U element type of rhs.
Parameters
rhs right-hand tensor; must have the same shape as *this.
fn callable invoked as fn(lhs_element, rhs_element).
Returns
Reference to *this.

Fully qualified name: kfr::tensor<T, NDims>::binary_inplace(const tensor<U, dims> &, Fn &&)

Declared at base/tensor.hpp:985

function astype()

template <typename U>
KFR_MEM_INTRINSIC tensor<U, dims> astype() const

Returns a tensor with elements converted to type U.

Template parameters
U target element type.
Returns
New tensor with each element static_cast'ed to U.

Fully qualified name: kfr::tensor<T, NDims>::astype()

Declared at base/tensor.hpp:1016

function to_array()

template <size_t Nout>
KFR_MEM_INTRINSIC std::array<T, Nout> to_array() const

Copies the tensor elements into a std::array.

Template parameters
Nout size of the resulting array; must equal size().
Returns
Array containing the tensor elements.

Fully qualified name: kfr::tensor<T, NDims>::to_array()

Declared at base/tensor.hpp:1025

struct nested_iterator_t

struct nested_iterator_t { … }

Iterator over the first axis yielding sub-tensors of one fewer dimension.

typedef iterator_category

using iterator_category = std::forward_iterator_tag

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator_t::iterator_category

Declared at base/tensor.hpp:1039

typedef difference_type

using difference_type   = std::ptrdiff_t

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator_t::difference_type

Declared at base/tensor.hpp:1040

typedef value_type

using value_type        = tensor<T, dims - 1>

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator_t::value_type

Declared at base/tensor.hpp:1041

typedef pointer

using pointer           = void

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator_t::pointer

Declared at base/tensor.hpp:1042

typedef reference

using reference         = value_type

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator_t::reference

Declared at base/tensor.hpp:1043

variable src

const tensor* src

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator_t::src

Declared at base/tensor.hpp:1045

variable index

size_t index

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator_t::index

Declared at base/tensor.hpp:1046

function operator*()

Dereferences the iterator to the sub-tensor at the current index.

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator_t::operator*()

Declared at base/tensor.hpp:1049

function operator++()

Prefix increment, advancing to the next sub-tensor.

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator_t::operator++()

Declared at base/tensor.hpp:1053

function operator++(int)

Postfix increment.

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator_t::operator++(int)

Declared at base/tensor.hpp:1061

function operator==(const nested_iterator_t &)

Returns true if two iterators refer to the same position.

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator_t::operator==(const nested_iterator_t &)

Declared at base/tensor.hpp:1069

function operator!=(const nested_iterator_t &)

Returns true if two iterators refer to different positions.

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator_t::operator!=(const nested_iterator_t &)

Declared at base/tensor.hpp:1074

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator_t

Declared at base/tensor.hpp:1037

typedef nested_iterator

using nested_iterator = std::conditional_t<dims == 1, tensor_iterator, nested_iterator_t>

Fully qualified name: kfr::tensor<T, NDims>::nested_iterator

Declared at base/tensor.hpp:1077

function nested_begin()

Returns a nested iterator to the first sub-tensor along the first axis.

Fully qualified name: kfr::tensor<T, NDims>::nested_begin()

Declared at base/tensor.hpp:1080

function nested_end()

Returns the nested iterator sentinel past the last sub-tensor.

Fully qualified name: kfr::tensor<T, NDims>::nested_end()

Declared at base/tensor.hpp:1088

function finalizer()

Returns the memory finalizer holding the data alive.

Fully qualified name: kfr::tensor<T, NDims>::finalizer()

Declared at base/tensor.hpp:1097

function operator=(Input &&)

template <expression_argument Input>
KFR_MEM_INTRINSIC const tensor& operator=(Input&& input) const&

Evaluates input and assigns the result to this tensor (const overload).

Parameters
input expression to evaluate.
Returns
Reference to *this.

Fully qualified name: kfr::tensor<T, NDims>::operator=(Input &&)

Declared at base/tensor.hpp:1103

function operator=(Input &&)

template <expression_argument Input>
KFR_MEM_INTRINSIC tensor& operator=(Input&& input) &&

Evaluates input and assigns the result to this tensor (rvalue overload).

Parameters
input expression to evaluate.
Returns
Reference to *this.

Fully qualified name: kfr::tensor<T, NDims>::operator=(Input &&)

Declared at base/tensor.hpp:1112

function operator=(Input &&)

template <expression_argument Input>
KFR_MEM_INTRINSIC tensor& operator=(Input&& input) &

Evaluates input and assigns the result to this tensor (lvalue overload).

Parameters
input expression to evaluate.
Returns
Reference to *this.

Fully qualified name: kfr::tensor<T, NDims>::operator=(Input &&)

Declared at base/tensor.hpp:1121

function operator==(const tensor<T, NDims> &, const tensor<T, NDims> &)

friend bool operator==(const tensor& lhs, const tensor& rhs)

Returns true if both tensors have the same shape and equal elements.

Fully qualified name: kfr::tensor<T, NDims>::operator==(const tensor<T, NDims> &, const tensor<T, NDims> &)

Declared at base/tensor.hpp:1128

function operator==(const tensor<T, NDims> &, tensor<T, NDims> &&)

friend bool operator==(const tensor& lhs, tensor&& rhs)

Returns true if both tensors have the same shape and equal elements.

Fully qualified name: kfr::tensor<T, NDims>::operator==(const tensor<T, NDims> &, tensor<T, NDims> &&)

Declared at base/tensor.hpp:1133

function operator==(const tensor<T, NDims> &, tensor<T, NDims> &)

friend bool operator==(const tensor& lhs, tensor& rhs)

Returns true if both tensors have the same shape and equal elements.

Fully qualified name: kfr::tensor<T, NDims>::operator==(const tensor<T, NDims> &, tensor<T, NDims> &)

Declared at base/tensor.hpp:1138

function operator==(tensor<T, NDims> &&, const tensor<T, NDims> &)

friend bool operator==(tensor&& lhs, const tensor& rhs)

Returns true if both tensors have the same shape and equal elements.

Fully qualified name: kfr::tensor<T, NDims>::operator==(tensor<T, NDims> &&, const tensor<T, NDims> &)

Declared at base/tensor.hpp:1144

function operator==(tensor<T, NDims> &&, tensor<T, NDims> &&)

friend bool operator==(tensor&& lhs, tensor&& rhs)

Returns true if both tensors have the same shape and equal elements.

Fully qualified name: kfr::tensor<T, NDims>::operator==(tensor<T, NDims> &&, tensor<T, NDims> &&)

Declared at base/tensor.hpp:1149

function operator==(tensor<T, NDims> &&, tensor<T, NDims> &)

friend bool operator==(tensor&& lhs, tensor& rhs)

Returns true if both tensors have the same shape and equal elements.

Fully qualified name: kfr::tensor<T, NDims>::operator==(tensor<T, NDims> &&, tensor<T, NDims> &)

Declared at base/tensor.hpp:1154

function operator==(tensor<T, NDims> &, const tensor<T, NDims> &)

friend bool operator==(tensor& lhs, const tensor& rhs)

Returns true if both tensors have the same shape and equal elements.

Fully qualified name: kfr::tensor<T, NDims>::operator==(tensor<T, NDims> &, const tensor<T, NDims> &)

Declared at base/tensor.hpp:1160

function operator==(tensor<T, NDims> &, tensor<T, NDims> &&)

friend bool operator==(tensor& lhs, tensor&& rhs)

Returns true if both tensors have the same shape and equal elements.

Fully qualified name: kfr::tensor<T, NDims>::operator==(tensor<T, NDims> &, tensor<T, NDims> &&)

Declared at base/tensor.hpp:1165

function operator==(tensor<T, NDims> &, tensor<T, NDims> &)

friend bool operator==(tensor& lhs, tensor& rhs)

Returns true if both tensors have the same shape and equal elements.

Fully qualified name: kfr::tensor<T, NDims>::operator==(tensor<T, NDims> &, tensor<T, NDims> &)

Declared at base/tensor.hpp:1170

function shape()

Returns the shape of the tensor.

Fully qualified name: kfr::tensor<T, NDims>::shape()

Declared at base/tensor.hpp:1176

function strides()

Returns the strides of the tensor.

Fully qualified name: kfr::tensor<T, NDims>::strides()

Declared at base/tensor.hpp:1178

function is_contiguous()

Returns true if the tensor data is stored contiguously.

Fully qualified name: kfr::tensor<T, NDims>::is_contiguous()

Declared at base/tensor.hpp:1181

function is_last_contiguous()

Returns true if the last axis has stride 1.

Fully qualified name: kfr::tensor<T, NDims>::is_last_contiguous()

Declared at base/tensor.hpp:1184

function to_string(int, int, std::string, std::string, std::string)

template <typename Fmt = void>
std::string to_string(int max_columns = 16, int max_dimensions = INT_MAX, std::string separator = ", ",
                      std::string open = "{", std::string close = "}") const

Returns a string representation of the tensor.

Parameters
max_columns maximum number of columns to print per row.
max_dimensions maximum number of dimensions to print.
separator separator between elements.
open string used to open a row.
close string used to close a row.
Returns
Formatted string representation.

Fully qualified name: kfr::tensor<T, NDims>::to_string(int, int, std::string, std::string, std::string)

Declared at base/tensor.hpp:1194

Fully qualified name: kfr::tensor<T, NDims>

Declared at base/tensor.hpp:139

Class tensor

class tensor<T, dynamic_shape> base

template <typename T>
struct tensor<T, dynamic_shape> { … }

Specialization of tensor for a dynamic shape. Not implemented yet.

Fully qualified name: kfr::tensor<T, dynamic_shape>

Declared at base/tensor.hpp:1232

This file was generated by cxxdox, a C++ documentation generator based on MkDocs Material and libclang.