Skip to content

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 .

Template parameters
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.

Parameters
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.

Template parameters
dummy Unused template parameter used to delay constraint checking.
Returns
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> &)

template <typename TI>
static constexpr shape from_std_array(const std::array<TI, Dims>& a) { … }

Build a shape from a std::array.

Template parameters
TI Element type of the input array (typically index_t ).
Parameters
a Source array of exactly Dims elements.
Returns
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()

template <typename TI = index_t>
constexpr std::array<TI, Dims> to_std_array() const { … }

Convert the shape to a std::array.

Template parameters
TI Element type of the output array (defaults to index_t ).
Returns
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.

Parameters
other The shape to compare against.
Returns
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.

Returns
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.

Parameters
other The shape to compare against.
Returns
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)

constexpr shape add(index_t value) const { … }

Add value to the last axis.

Parameters
value Amount to add to the trailing axis.
Returns
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>)

template <index_t Axis>
constexpr shape add_at(index_t value, cval_t<index_t, Axis> = { … }

Add value to the axis selected by the template parameter.

Template parameters
Axis Index of the axis to modify (compile-time constant).
Parameters
value Amount to add to Axis.
tag Tag value selecting Axis (unused, for ADL dispatch).
Returns
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> &)

constexpr shape add(const shape& other) const { … }

Element-wise addition of two shapes.

Parameters
other Shape to add.
Returns
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> &)

constexpr shape sub(const shape& other) const { … }

Element-wise subtraction of two shapes.

Parameters
other Shape to subtract.
Returns
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.

Returns
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.

Returns
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> &)

friend constexpr shape add_shape(const shape& lhs, const shape& rhs) { … }

Combine two shapes using the broadcasting rule max(max(x, y), x + y).

Parameters
lhs Left-hand shape.
rhs Right-hand shape.
Returns
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> &)

friend constexpr shape sub_shape(const shape& lhs, const shape& rhs) { … }

Subtract one shape from another, treating infinite_size as infinite.

Parameters
lhs Left-hand shape.
rhs Right-hand shape.
Returns
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> &)

friend constexpr shape add_shape_undef(const shape& lhs, const shape& rhs) { … }

Variant of add_shape that also propagates undefined_size .

Parameters
lhs Left-hand shape.
rhs Right-hand shape.
Returns
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> &)

friend constexpr shape sub_shape_undef(const shape& lhs, const shape& rhs) { … }

Variant of sub_shape that also propagates undefined_size .

Parameters
lhs Left-hand shape.
rhs Right-hand shape.
Returns
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> &)

friend constexpr shape min(const shape& x, const shape& y) { … }

Element-wise minimum of two shapes.

Parameters
x First shape.
y Second shape.
Returns
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.

Returns
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.

Returns
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.

Parameters
indices Multi-dimensional index.
Returns
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.

Parameters
index Flat linear offset.
Returns
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).

Parameters
other The other shape.
Returns
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.

Template parameters
indims Rank of the source shape (must be at least Dims).
stop When true, the upper bound is inclusive.
Parameters
other The higher-rank shape to adapt.
Returns
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).

Returns
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.

Returns
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.

Template parameters
new_dims The desired rank (must be at least Dims).
Parameters
value Size of the prepended axes.
Returns
A shape of rank new_dims.

Fully qualified name: kfr::shape<Dims>::extend(index_t)

Declared at base/shape.hpp:523

function trim()

template <index_t odims>
constexpr shape<odims> trim() const { … }

Reduce the shape to a lower rank by dropping leading axes.

Template parameters
odims Desired rank (must not exceed Dims).
Returns
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.

Returns
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.

Returns
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.

Returns
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.

Returns
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 .

Returns
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.

Parameters
index Number of axes from the back (0 is the last axis).
Returns
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.

Parameters
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.

Returns
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 .

Returns
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.

Parameters
indices Multi-dimensional index (ignored for a scalar).
Returns
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.

Parameters
index Flat linear offset (ignored for a scalar).
Returns
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.

Template parameters
odims Rank of the input shape.
stop When true, the upper bound is inclusive (ignored here).
Parameters
other The source shape (ignored for a scalar).
Returns
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.

Returns
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.

Parameters
other The other scalar shape (ignored).
Returns
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.

Returns
0.

Fully qualified name: kfr::shape<0>::product()

Declared at base/shape.hpp:688

function tomask()

Build a dimset with all bits set.

Returns
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.

Template parameters
new_dims Desired rank.
Parameters
value Size of the prepended axes (defaults to infinite_size ).
Returns
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()

template <index_t new_dims>
constexpr shape<new_dims> trim() const { … }

Reduce the scalar shape to a smaller rank.

Template parameters
new_dims Must be 0.
Returns
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.

Parameters
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.

Parameters
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.

Parameters
index Number of axes from the back (ignored for a scalar).
Returns
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.

Parameters
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

template <>
struct shape<dynamic_shape> : protected std::vector<index_t> { … }

Run-time-rank shape specialization.

function shape(shape<Dims>)

template <index_t Dims>
    requires(Dims != dynamic_shape)
shape(shape<Dims> sh)

Construct a dynamic-rank shape from a fixed-rank one.

Template parameters
Dims Rank of the source shape (must not be dynamic_shape ).
Parameters
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.

Returns
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.

Returns
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.

Returns
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.

Returns
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.

Returns
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.

Returns
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

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