Class shape¶
class shape<dims> base¶
template <index_t Dims>
struct shape : static_array_base<index_t, csizeseq_t<Dims>> { … } Fixed-rank multidimensional shape used by tensor .
| dims | Number of dimensions. Use 0 for a scalar or dynamic_shape for a run-time rank. |
typedef base ¶
using base = static_array_base<index_t, csizeseq_t<Dims>> Underlying static array storing one index_t per axis.
Fully qualified name: kfr::shape<Dims>::base
Declared at base/shape.hpp:187
constructor shape<dims>(const base &) ¶
constexpr shape(const base& a) : base(a) { … } Construct a shape from a base static array.
| a | Source static array to copy from. |
Fully qualified name: kfr::shape<Dims>::shape<dims>(const base &)
Declared at base/shape.hpp:193
function dims() ¶
static constexpr size_t dims() { … } Returns the number of dimensions (compile-time constant).
Fully qualified name: kfr::shape<Dims>::dims()
Declared at base/shape.hpp:198
function operator unsigned long() ¶
template <int dummy = 0>
requires(Dims == 1)
operator index_t() const Implicit conversion to index_t for 1D shapes.
Allows a 1D shape to be used wherever a single size is expected.
| dummy | Unused template parameter used to delay constraint checking. |
| The size of the only axis. |
Fully qualified name: kfr::shape<Dims>::operator unsigned long()
Declared at base/shape.hpp:207
function from_std_array(const std::array<TI, Dims> &) ¶
Build a shape from a std::array.
| TI | Element type of the input array (typically index_t ). |
| a | Source array of exactly Dims elements. |
A shape whose elements are copied from a. |
Fully qualified name: kfr::shape<Dims>::from_std_array(const std::array<TI, Dims> &)
Declared at base/shape.hpp:217
function to_std_array() ¶
Convert the shape to a std::array.
| TI | Element type of the output array (defaults to index_t ). |
A new std::array containing the shape's elements. |
Fully qualified name: kfr::shape<Dims>::to_std_array()
Declared at base/shape.hpp:228
function ge(const shape<dims> &) ¶
bool ge(const shape& other) const Element-wise greater-than-or-equal comparison.
| other | The shape to compare against. |
true if every axis of *this is at least as large as the corresponding axis of other. |
Fully qualified name: kfr::shape<Dims>::ge(const shape<dims> &)
Declared at base/shape.hpp:239
function trailing_zeros() ¶
index_t trailing_zeros() const Number of trailing axes of size 1, counting from the back.
Returns the position of the first axis (from the front) whose reverse-indexed size is not zero. In other words, the number of trailing length-1 axes in a row-major layout.
The number of trailing size-1 axes, in the range [0, Dims]. |
Fully qualified name: kfr::shape<Dims>::trailing_zeros()
Declared at base/shape.hpp:257
function le(const shape<dims> &) ¶
bool le(const shape& other) const Element-wise less-than-or-equal comparison.
| other | The shape to compare against. |
true if every axis of *this is at most as large as the corresponding axis of other. |
Fully qualified name: kfr::shape<Dims>::le(const shape<dims> &)
Declared at base/shape.hpp:271
function add(index_t) ¶
Add value to the last axis.
| value | Amount to add to the trailing axis. |
A new shape with the trailing axis increased by value. |
Fully qualified name: kfr::shape<Dims>::add(index_t)
Declared at base/shape.hpp:286
function add_at(index_t, cval_t<index_t, Axis>) ¶
Add value to the axis selected by the template parameter.
| Axis | Index of the axis to modify (compile-time constant). |
| value | Amount to add to Axis. |
| tag | Tag value selecting Axis (unused, for ADL dispatch). |
A new shape with axis Axis increased by value. |
Fully qualified name: kfr::shape<Dims>::add_at(index_t, cval_t<index_t, Axis>)
Declared at base/shape.hpp:298
function add(const shape<dims> &) ¶
Element-wise addition of two shapes.
| other | Shape to add. |
| A new shape where each axis is the sum of the two operands. |
Fully qualified name: kfr::shape<Dims>::add(const shape<dims> &)
Declared at base/shape.hpp:307
function sub(const shape<dims> &) ¶
Element-wise subtraction of two shapes.
| other | Shape to subtract. |
| A new shape where each axis is the difference of the two operands. |
Fully qualified name: kfr::shape<Dims>::sub(const shape<dims> &)
Declared at base/shape.hpp:311
function sum() ¶
constexpr index_t sum() const { … } Sum of every axis size.
| The total number of elements summed across all axes. |
Fully qualified name: kfr::shape<Dims>::sum()
Declared at base/shape.hpp:314
function has_infinity() ¶
constexpr bool has_infinity() const { … } Detect the infinite_size sentinel among the axes.
true if any axis equals infinite_size . |
Fully qualified name: kfr::shape<Dims>::has_infinity()
Declared at base/shape.hpp:318
function add_shape(const shape<dims> &, const shape<dims> &) ¶
Combine two shapes using the broadcasting rule max(max(x, y), x + y).
| lhs | Left-hand shape. |
| rhs | Right-hand shape. |
| A shape representing the union of the two extents. |
Fully qualified name: kfr::shape<Dims>::add_shape(const shape<dims> &, const shape<dims> &)
Declared at base/shape.hpp:336
function sub_shape(const shape<dims> &, const shape<dims> &) ¶
Subtract one shape from another, treating infinite_size as infinite.
| lhs | Left-hand shape. |
| rhs | Right-hand shape. |
A shape representing the difference, with infinite_size propagated. |
Fully qualified name: kfr::shape<Dims>::sub_shape(const shape<dims> &, const shape<dims> &)
Declared at base/shape.hpp:350
function add_shape_undef(const shape<dims> &, const shape<dims> &) ¶
Variant of add_shape that also propagates undefined_size .
| lhs | Left-hand shape. |
| rhs | Right-hand shape. |
| A shape with the sentinels propagated appropriately. |
Fully qualified name: kfr::shape<Dims>::add_shape_undef(const shape<dims> &, const shape<dims> &)
Declared at base/shape.hpp:364
function sub_shape_undef(const shape<dims> &, const shape<dims> &) ¶
Variant of sub_shape that also propagates undefined_size .
| lhs | Left-hand shape. |
| rhs | Right-hand shape. |
| A shape with the sentinels propagated appropriately. |
Fully qualified name: kfr::shape<Dims>::sub_shape_undef(const shape<dims> &, const shape<dims> &)
Declared at base/shape.hpp:383
function min(const shape<dims> &, const shape<dims> &) ¶
Element-wise minimum of two shapes.
| x | First shape. |
| y | Second shape. |
| A shape where each axis is the smaller of the two operands. |
Fully qualified name: kfr::shape<Dims>::min(const shape<dims> &, const shape<dims> &)
Declared at base/shape.hpp:398
function operator*() ¶
constexpr const base& operator*() const { … } Access the underlying static array.
A const reference to the base storage. |
Fully qualified name: kfr::shape<Dims>::operator*()
Declared at base/shape.hpp:402
function operator->() ¶
constexpr const base* operator->() const { … } Pointer-like access to the underlying static array.
A const pointer to the base storage. |
Fully qualified name: kfr::shape<Dims>::operator->()
Declared at base/shape.hpp:406
function to_flat(const shape<Dims> &) ¶
Convert multi-dimensional indices to a flat offset.
| indices | Multi-dimensional index. |
| The flat linear offset. |
Fully qualified name: kfr::shape<Dims>::to_flat(const shape<Dims> &)
Declared at base/shape.hpp:414
function from_flat(size_t) ¶
Convert a flat offset to multi-dimensional indices.
| index | Flat linear offset. |
| The multi-dimensional index. |
Fully qualified name: kfr::shape<Dims>::from_flat(size_t)
Declared at base/shape.hpp:444
function dot(const shape<dims> &) ¶
Dot product of the two shapes (element-wise multiply and sum).
| other | The other shape. |
| The sum of the products of corresponding axes. |
Fully qualified name: kfr::shape<Dims>::dot(const shape<dims> &)
Declared at base/shape.hpp:472
function adapt(const shape<indims> &, cbool_t<stop>) ¶
template <index_t indims, bool stop = false>
KFR_MEM_INTRINSIC constexpr shape adapt(const shape<indims>& other, cbool_t<stop> = { … } Adapt a higher-rank shape to the current rank for indexing.
| indims | Rank of the source shape (must be at least Dims). |
| stop | When true, the upper bound is inclusive. |
| other | The higher-rank shape to adapt. |
The adapted shape of rank Dims. |
Fully qualified name: kfr::shape<Dims>::adapt(const shape<indims> &, cbool_t<stop>)
Declared at base/shape.hpp:485
function product() ¶
Product of every axis size (total number of elements).
| The product of all axes. |
Fully qualified name: kfr::shape<Dims>::product()
Declared at base/shape.hpp:496
function tomask() ¶
Build a dimset mask with bits set for non-collapsed axes.
A dimset describing which axes are non-trivial. |
Fully qualified name: kfr::shape<Dims>::tomask()
Declared at base/shape.hpp:504
function extend(index_t) ¶
template <index_t new_dims>
constexpr KFR_MEM_INTRINSIC shape<new_dims> extend(index_t value = infinite_size) const { … } Promote the shape to a higher rank by prepending axes.
| new_dims | The desired rank (must be at least Dims). |
| value | Size of the prepended axes. |
A shape of rank new_dims. |
Fully qualified name: kfr::shape<Dims>::extend(index_t)
Declared at base/shape.hpp:523
function trim() ¶
Reduce the shape to a lower rank by dropping leading axes.
| odims | Desired rank (must not exceed Dims). |
A shape of rank odims. |
Fully qualified name: kfr::shape<Dims>::trim()
Declared at base/shape.hpp:539
function rotate_left() ¶
constexpr KFR_MEM_INTRINSIC shape rotate_left() const { … } Rotate the axes left by one position.
| A new shape with the axes cyclically shifted left. |
Fully qualified name: kfr::shape<Dims>::rotate_left()
Declared at base/shape.hpp:557
function rotate_right() ¶
constexpr KFR_MEM_INTRINSIC shape rotate_right() const { … } Rotate the axes right by one position.
| A new shape with the axes cyclically shifted right. |
Fully qualified name: kfr::shape<Dims>::rotate_right()
Declared at base/shape.hpp:567
function remove_back() ¶
constexpr KFR_MEM_INTRINSIC shape<Dims - 1> remove_back() const { … } Drop the last axis.
A shape of rank Dims - 1 (or the empty shape for Dims == 1). |
Fully qualified name: kfr::shape<Dims>::remove_back()
Declared at base/shape.hpp:575
function remove_front() ¶
constexpr KFR_MEM_INTRINSIC shape<Dims - 1> remove_front() const { … } Drop the first axis.
A shape of rank Dims - 1 (or the empty shape for Dims == 1). |
Fully qualified name: kfr::shape<Dims>::remove_front()
Declared at base/shape.hpp:589
function trunc() ¶
constexpr KFR_MEM_INTRINSIC shape<Dims - 1> trunc() const { … } Drop the last axis. Synonym for remove_back .
A shape of rank Dims - 1. |
Fully qualified name: kfr::shape<Dims>::trunc()
Declared at base/shape.hpp:603
function revindex(size_t) ¶
Read an axis by its position from the back.
| index | Number of axes from the back (0 is the last axis). |
The size of that axis, or 1 if index is out of range. |
Fully qualified name: kfr::shape<Dims>::revindex(size_t)
Declared at base/shape.hpp:608
function set_revindex(size_t, index_t) ¶
Write an axis by its position from the back.
| index | Number of axes from the back (0 is the last axis). |
| val | New value to store. |
Note
Out-of-range indices are silently ignored.
Fully qualified name: kfr::shape<Dims>::set_revindex(size_t, index_t)
Declared at base/shape.hpp:616
function transpose() ¶
Reverse the order of the axes.
| A new shape with the axes in reverse order. |
Fully qualified name: kfr::shape<Dims>::transpose()
Declared at base/shape.hpp:624
Fully qualified name: kfr::shape<dims>
Declared at base/shape.hpp:183
Class shape¶
struct shape<0> base¶
template <>
struct shape<0> { … } Scalar shape specialization.
variable static_size ¶
static constexpr size_t static_size = 0 Compile-time size of the shape, always zero.
Fully qualified name: kfr::shape<0>::static_size
Declared at base/shape.hpp:639
function size() ¶
static constexpr size_t size() { … } Returns the number of elements (always 0).
Fully qualified name: kfr::shape<0>::size()
Declared at base/shape.hpp:642
function dims() ¶
static constexpr size_t dims() { … } Returns the number of dimensions (always 0).
Fully qualified name: kfr::shape<0>::dims()
Declared at base/shape.hpp:645
constructor shape() ¶
constexpr shape() = default Default-construct an empty (scalar) shape.
Fully qualified name: kfr::shape<0>::shape()
Declared at base/shape.hpp:648
constructor shape(index_t) ¶
constexpr shape(index_t value) { … } Construct a scalar shape; the value is ignored.
Fully qualified name: kfr::shape<0>::shape(index_t)
Declared at base/shape.hpp:650
function has_infinity() ¶
constexpr bool has_infinity() const { … } A scalar shape has no axes, so it can never contain infinite_size .
Always false. |
Fully qualified name: kfr::shape<0>::has_infinity()
Declared at base/shape.hpp:655
function to_flat(const shape<0> &) ¶
Flat offset for a scalar; the only valid offset is 0.
| indices | Multi-dimensional index (ignored for a scalar). |
| 0. |
Fully qualified name: kfr::shape<0>::to_flat(const shape<0> &)
Declared at base/shape.hpp:660
function from_flat(size_t) ¶
Inverse of to_flat : returns the empty shape.
| index | Flat linear offset (ignored for a scalar). |
The empty shape<0> . |
Fully qualified name: kfr::shape<0>::from_flat(size_t)
Declared at base/shape.hpp:664
function adapt(const shape<odims> &, cbool_t<stop>) ¶
template <index_t odims, bool stop = false>
KFR_MEM_INTRINSIC shape<0> adapt(const shape<odims>& other, cbool_t<stop> = { … } Adapt any shape to a scalar; always returns the empty shape.
| odims | Rank of the input shape. |
| stop | When true, the upper bound is inclusive (ignored here). |
| other | The source shape (ignored for a scalar). |
The empty shape<0> . |
Fully qualified name: kfr::shape<0>::adapt(const shape<odims> &, cbool_t<stop>)
Declared at base/shape.hpp:672
function trailing_zeros() ¶
index_t trailing_zeros() const A scalar shape has no trailing collapsed axes.
| 0. |
Fully qualified name: kfr::shape<0>::trailing_zeros()
Declared at base/shape.hpp:679
function dot(const shape<0> &) ¶
Dot product with another scalar shape; the empty product is 0.
| other | The other scalar shape (ignored). |
| 0. |
Fully qualified name: kfr::shape<0>::dot(const shape<0> &)
Declared at base/shape.hpp:684
function product() ¶
Product of all axes; the empty product is 0.
| 0. |
Fully qualified name: kfr::shape<0>::product()
Declared at base/shape.hpp:688
function tomask() ¶
Build a dimset with all bits set.
| A fully-active mask. |
Fully qualified name: kfr::shape<0>::tomask()
Declared at base/shape.hpp:692
function extend(index_t) ¶
template <index_t new_dims>
constexpr KFR_MEM_INTRINSIC shape<new_dims> extend(index_t value = infinite_size) const { … } Promote the scalar shape to a higher rank by prepending axes of size value.
| new_dims | Desired rank. |
| value | Size of the prepended axes (defaults to infinite_size ). |
A shape of rank new_dims with all axes of size value, or the empty shape when new_dims is 0. |
Fully qualified name: kfr::shape<0>::extend(index_t)
Declared at base/shape.hpp:701
function trim() ¶
Reduce the scalar shape to a smaller rank.
| new_dims | Must be 0. |
The empty shape<0> . |
Fully qualified name: kfr::shape<0>::trim()
Declared at base/shape.hpp:715
function operator==(const shape<0> &) ¶
Two scalar shapes are always equal.
| other | The other scalar shape (ignored). |
Fully qualified name: kfr::shape<0>::operator==(const shape<0> &)
Declared at base/shape.hpp:723
function operator!=(const shape<0> &) ¶
Two scalar shapes are never unequal.
| other | The other scalar shape (ignored). |
Fully qualified name: kfr::shape<0>::operator!=(const shape<0> &)
Declared at base/shape.hpp:726
function revindex(size_t) ¶
Read an axis by its position from the back; always returns 1 because there are no axes.
| index | Number of axes from the back (ignored for a scalar). |
| Always 1. |
Fully qualified name: kfr::shape<0>::revindex(size_t)
Declared at base/shape.hpp:732
function set_revindex(size_t, index_t) ¶
Set an axis by its position from the back; a no-op.
| index | Number of axes from the back (ignored for a scalar). |
| val | New value to store (ignored for a scalar). |
Fully qualified name: kfr::shape<0>::set_revindex(size_t, index_t)
Declared at base/shape.hpp:736
Fully qualified name: kfr::shape<0>
Declared at base/shape.hpp:636
Class shape¶
struct shape<dynamic_shape> base¶
Run-time-rank shape specialization.
function shape(shape<Dims>) ¶
Construct a dynamic-rank shape from a fixed-rank one.
| Dims | Rank of the source shape (must not be dynamic_shape ). |
| sh | The source shape, copied axis by axis. |
Fully qualified name: kfr::shape<dynamic_shape>::shape(shape<Dims>)
Declared at base/shape.hpp:768
function dims() ¶
size_t dims() const Returns the number of dimensions at run time.
| The current number of axes. |
Fully qualified name: kfr::shape<dynamic_shape>::dims()
Declared at base/shape.hpp:774
function product() ¶
Product of every axis size; 0 for an empty shape.
| The total number of elements, or 0 if the shape is empty. |
Fully qualified name: kfr::shape<dynamic_shape>::product()
Declared at base/shape.hpp:778
function rotate_left() ¶
Rotate the axes left by one position.
| A new shape with the axes cyclically shifted left. |
Fully qualified name: kfr::shape<dynamic_shape>::rotate_left()
Declared at base/shape.hpp:796
function rotate_right() ¶
Rotate the axes right by one position.
| A new shape with the axes cyclically shifted right. |
Fully qualified name: kfr::shape<dynamic_shape>::rotate_right()
Declared at base/shape.hpp:810
function remove_back() ¶
Drop the last axis.
| A new shape with one fewer axis (or a copy if empty). |
Fully qualified name: kfr::shape<dynamic_shape>::remove_back()
Declared at base/shape.hpp:820
function remove_front() ¶
Drop the first axis.
| A new shape with one fewer axis (or a copy if empty). |
Fully qualified name: kfr::shape<dynamic_shape>::remove_front()
Declared at base/shape.hpp:829
Fully qualified name: kfr::shape<dynamic_shape>
Declared at base/shape.hpp:750