class tensor<T, NDims> tensor¶
template <typename T, index_t NDims>
struct tensor : public tensor_subscript<T, tensor<T, NDims>, std::make_integer_sequence<index_t, NDims>> { … } 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.
| T | element type |
| NDims | number of dimensions |
typedef value_type ¶
using value_type = T Defined at base/tensor.hpp:104
typedef pointer ¶
using pointer = T* Defined at base/tensor.hpp:105
typedef const_pointer ¶
using const_pointer = const T* Defined at base/tensor.hpp:106
typedef reference ¶
using reference = T& Defined at base/tensor.hpp:107
typedef const_reference ¶
using const_reference = const T& Defined at base/tensor.hpp:108
typedef size_type ¶
using size_type = index_t Defined at base/tensor.hpp:109
variable dims ¶
constexpr static inline index_t dims = NDims Defined at base/tensor.hpp:111
typedef shape_type ¶
Defined at base/tensor.hpp:113
struct tensor_iterator ¶
struct tensor_iterator { … } Tensor iterator. Iterates through flattened array
typedef iterator_category ¶
using iterator_category = std::forward_iterator_tag Defined at base/tensor.hpp:118
typedef difference_type ¶
using difference_type = std::ptrdiff_t Defined at base/tensor.hpp:119
typedef value_type ¶
using value_type = T Defined at base/tensor.hpp:120
typedef pointer ¶
using pointer = T* Defined at base/tensor.hpp:121
typedef reference ¶
using reference = T& Defined at base/tensor.hpp:122
variable src ¶
const tensor* src Defined at base/tensor.hpp:124
variable indices ¶
shape_type indices Defined at base/tensor.hpp:125
function flat_index() ¶
Defined at base/tensor.hpp:127
function is_end() ¶
Defined at base/tensor.hpp:129
function operator*() ¶
Defined at base/tensor.hpp:131
function operator->() ¶
Defined at base/tensor.hpp:132
function operator++() ¶
Defined at base/tensor.hpp:135
function operator++(int) ¶
Defined at base/tensor.hpp:145
function operator==(const tensor_iterator &) ¶
Defined at base/tensor.hpp:152
function operator!=(const tensor_iterator &) ¶
Defined at base/tensor.hpp:156
Defined at base/tensor.hpp:116
typedef iterator ¶
using iterator = tensor_iterator Defined at base/tensor.hpp:159
typedef const_iterator ¶
using const_iterator = tensor_iterator Defined at base/tensor.hpp:160
typedef contiguous_iterator ¶
using contiguous_iterator = pointer Defined at base/tensor.hpp:162
typedef const_contiguous_iterator ¶
using const_contiguous_iterator = pointer Defined at base/tensor.hpp:163
constructor tensor<T, NDims>() ¶
Default constructor. Creates tensor with null shape
Defined at base/tensor.hpp:166
constructor tensor<T, NDims>(T *, const shape_type &, const shape_type &, memory_finalizer) ¶
Construct from external pointer, shape, strides and finalizer
Defined at base/tensor.hpp:172
constructor tensor<T, NDims>(T *, const shape_type &, memory_finalizer) ¶
Construct from external pointer, shape and finalizer with default strides
Defined at base/tensor.hpp:181
function allocate(size_t) ¶
Defined at base/tensor.hpp:187
function deallocate(T *) ¶
Defined at base/tensor.hpp:189
constructor tensor<T, NDims>(const shape_type &) ¶
Construct from shape and allocate memory
Defined at base/tensor.hpp:192
constructor tensor<T, NDims>(const shape_type &, const shape_type &) ¶
Construct from shape, strides and allocate memory
Defined at base/tensor.hpp:202
constructor tensor<T, NDims>(const shape_type &, T) ¶
Construct from shape, allocate memory and fill with value
Defined at base/tensor.hpp:213
constructor tensor<T, NDims>(const shape_type &, const shape_type &, T) ¶
Construct from shape, strides, allocate memory and fill with value
Defined at base/tensor.hpp:219
constructor tensor<T, NDims>(const shape_type &, const std::initializer_list<T> &) ¶
Construct from shape, allocate memory and fill with flat list
Defined at base/tensor.hpp:225
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) Initialize with braced list. Defined for 1D tensor only
Defined at base/tensor.hpp:234
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) Initialize with braced list. Defined for 2D tensor only
Defined at base/tensor.hpp:242
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) Initialize with braced list. Defined for 3D tensor only
Defined at base/tensor.hpp:251
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) Initialize with braced list. Defined for 4D tensor only
Defined at base/tensor.hpp:260
constructor tensor<T, NDims>(const shape_type &, const shape_type &, std::initializer_list<T>) ¶
Defined at base/tensor.hpp:269
function tensor<T, NDims>(Input &&) ¶
template <expression_argument Input>
KFR_MEM_INTRINSIC tensor(Input&& input) Defined at base/tensor.hpp:278
function data() ¶
Defined at base/tensor.hpp:284
function size() ¶
Defined at base/tensor.hpp:286
function empty() ¶
Defined at base/tensor.hpp:288
function begin() ¶
Defined at base/tensor.hpp:290
function end() ¶
Defined at base/tensor.hpp:297
function require_contiguous() ¶
Defined at base/tensor.hpp:302
function contiguous_begin() ¶
Defined at base/tensor.hpp:308
function contiguous_end() ¶
Defined at base/tensor.hpp:313
function contiguous_begin_unsafe() ¶
Defined at base/tensor.hpp:319
function contiguous_end_unsafe() ¶
Defined at base/tensor.hpp:320
function calc_index(const shape_type &) ¶
Defined at base/tensor.hpp:322
function access(const shape_type &) ¶
Defined at base/tensor.hpp:327
function operator[](index_t) ¶
Defined at base/tensor.hpp:332
function operator()(const shape_type &, const shape_type &) ¶
Defined at base/tensor.hpp:334
constructor tensor<T, NDims>(const tensor<T, NDims> &) ¶
tensor(const tensor&) = default Defined at base/tensor.hpp:358
constructor tensor<T, NDims>(tensor<T, NDims> &&) ¶
tensor(tensor&&) = default Defined at base/tensor.hpp:359
constructor tensor<T, NDims>(tensor<T, NDims> &) ¶
tensor(tensor& other) Defined at base/tensor.hpp:360
constructor tensor<T, NDims>(const tensor<T, NDims> &&) ¶
tensor(const tensor&& other) Defined at base/tensor.hpp:361
function operator=(const tensor<T, NDims> &) ¶
Defined at base/tensor.hpp:365
function operator=(tensor<T, NDims> &&) ¶
Defined at base/tensor.hpp:371
function operator=(const tensor<T, NDims> &) ¶
Defined at base/tensor.hpp:382
function operator=(const tensor<T, NDims> &) ¶
Defined at base/tensor.hpp:387
function operator=(const T &) ¶
Defined at base/tensor.hpp:392
function operator=(const T &) ¶
Defined at base/tensor.hpp:397
function assign(const tensor<T, NDims> &) ¶
Defined at base/tensor.hpp:403
function assign(const T &) ¶
Defined at base/tensor.hpp:409
variable has_tensor_range ¶
template <typename... Index>
static constexpr bool has_tensor_range = (std::is_same_v<Index, tensor_range> || ...) Defined at base/tensor.hpp:412
function get_range(index_t &, index_t &, index_t &, signed_index_t, index_t) ¶
Defined at base/tensor.hpp:414
function get_range(index_t &, index_t &, index_t &, signed_index_t, const tensor_range &) ¶
Defined at base/tensor.hpp:424
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 Defined at base/tensor.hpp:470
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 Defined at base/tensor.hpp:494
typedef operator() ¶
Defined at base/tensor.hpp:514
function transpose() ¶
Defined at base/tensor.hpp:516
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 Defined at base/tensor.hpp:534
function reshape(const kfr::shape<dims> &) ¶
template <index_t dims>
KFR_MEM_INTRINSIC tensor<T, dims> reshape(const kfr::shape<dims>& new_shape) const Defined at base/tensor.hpp:569
function flatten() ¶
Defined at base/tensor.hpp:574
function flatten_may_copy(bool) ¶
Defined at base/tensor.hpp:576
function copy() ¶
Defined at base/tensor.hpp:581
function copy_from(const tensor<T, NDims> &) ¶
Defined at base/tensor.hpp:588
function iterate(Fn &&) ¶
template <typename Fn>
KFR_MEM_INTRINSIC void iterate(Fn&& fn) const Defined at base/tensor.hpp:591
function map(Fn &&) ¶
template <typename Fn, typename Tout = std::invoke_result_t<Fn, T>>
KFR_MEM_INTRINSIC tensor<Tout, dims> map(Fn&& fn) const Defined at base/tensor.hpp:602
function unary(Fn &&) ¶
template <typename Fn, typename Tout = std::invoke_result_t<Fn, T>>
KFR_MEM_INTRINSIC tensor<Tout, dims> unary(Fn&& fn) const Defined at base/tensor.hpp:608
function unary_inplace(Fn &&) ¶
template <typename Fn>
KFR_MEM_INTRINSIC const tensor& unary_inplace(Fn&& fn) const Defined at base/tensor.hpp:636
function reduce(Fn &&, T) ¶
template <typename Fn>
KFR_MEM_INTRINSIC T reduce(Fn&& fn, T initial = T { … } Defined at base/tensor.hpp:660
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 Defined at base/tensor.hpp:685
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 Defined at base/tensor.hpp:718
function astype() ¶
template <typename U>
KFR_MEM_INTRINSIC tensor<U, dims> astype() const Defined at base/tensor.hpp:746
function to_array() ¶
template <size_t Nout>
KFR_MEM_INTRINSIC std::array<T, Nout> to_array() const Defined at base/tensor.hpp:752
struct nested_iterator_t ¶
struct nested_iterator_t { … } typedef iterator_category ¶
using iterator_category = std::forward_iterator_tag Defined at base/tensor.hpp:765
typedef difference_type ¶
using difference_type = std::ptrdiff_t Defined at base/tensor.hpp:766
typedef value_type ¶
using value_type = tensor<T, dims - 1> Defined at base/tensor.hpp:767
typedef pointer ¶
using pointer = const value_type* Defined at base/tensor.hpp:768
typedef reference ¶
using reference = const value_type& Defined at base/tensor.hpp:769
variable src ¶
const tensor* src Defined at base/tensor.hpp:771
variable index ¶
size_t index Defined at base/tensor.hpp:772
function operator*() ¶
Defined at base/tensor.hpp:774
function operator->() ¶
Defined at base/tensor.hpp:775
function operator++() ¶
Defined at base/tensor.hpp:778
function operator++(int) ¶
Defined at base/tensor.hpp:785
function operator==(const nested_iterator_t &) ¶
Defined at base/tensor.hpp:792
function operator!=(const nested_iterator_t &) ¶
Defined at base/tensor.hpp:796
Defined at base/tensor.hpp:763
typedef nested_iterator ¶
using nested_iterator = std::conditional_t<dims == 1, tensor_iterator, nested_iterator_t> Defined at base/tensor.hpp:799
function nested_begin() ¶
Defined at base/tensor.hpp:801
function nested_end() ¶
Defined at base/tensor.hpp:808
function finalizer() ¶
Defined at base/tensor.hpp:816
function operator=(Input &&) ¶
template <expression_argument Input>
KFR_MEM_INTRINSIC const tensor& operator=(Input&& input) const& Defined at base/tensor.hpp:819
function operator=(Input &&) ¶
template <expression_argument Input>
KFR_MEM_INTRINSIC tensor& operator=(Input&& input) && Defined at base/tensor.hpp:825
function operator=(Input &&) ¶
template <expression_argument Input>
KFR_MEM_INTRINSIC tensor& operator=(Input&& input) & Defined at base/tensor.hpp:831
function operator==(const tensor<T, NDims> &, const tensor<T, NDims> &) ¶
Defined at base/tensor.hpp:837
function operator==(const tensor<T, NDims> &, tensor<T, NDims> &&) ¶
Defined at base/tensor.hpp:841
function operator==(const tensor<T, NDims> &, tensor<T, NDims> &) ¶
Defined at base/tensor.hpp:845
function operator==(tensor<T, NDims> &&, const tensor<T, NDims> &) ¶
Defined at base/tensor.hpp:850
function operator==(tensor<T, NDims> &&, tensor<T, NDims> &&) ¶
Defined at base/tensor.hpp:854
function operator==(tensor<T, NDims> &&, tensor<T, NDims> &) ¶
Defined at base/tensor.hpp:858
function operator==(tensor<T, NDims> &, const tensor<T, NDims> &) ¶
Defined at base/tensor.hpp:863
function operator==(tensor<T, NDims> &, tensor<T, NDims> &&) ¶
Defined at base/tensor.hpp:867
function operator==(tensor<T, NDims> &, tensor<T, NDims> &) ¶
Defined at base/tensor.hpp:871
function shape() ¶
Defined at base/tensor.hpp:876
function strides() ¶
Defined at base/tensor.hpp:877
function is_contiguous() ¶
Defined at base/tensor.hpp:879
function is_last_contiguous() ¶
Defined at base/tensor.hpp:881
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 Defined at base/tensor.hpp:884
Defined at base/tensor.hpp:101