MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
shape.hpp File Reference
#include <algorithm>
#include <array>
#include <cassert>
#include <cstddef>
#include <initializer_list>
#include <numeric>
#include <stdexcept>
#include <string>
#include <mtl/detail/exceptions.hpp>
#include <mtl/tag/orientation.hpp>

Classes

class  mtl::array::shape< N >
 Static-rank shape: an array of N extents. More...

Namespaces

namespace  mtl
namespace  mtl::array
namespace  mtl::array::detail_shape

Typedefs

using mtl::array::c_order = tag::row_major
 Layout order for multi-dimensional arrays.
using mtl::array::f_order = tag::col_major

Functions

template<std::size_t N>
constexpr std::array< std::size_t, N > mtl::array::c_order_strides (const shape< N > &sh)
 Compute C-order (row-major) strides: last dimension has stride 1.
template<std::size_t N>
constexpr std::array< std::size_t, N > mtl::array::f_order_strides (const shape< N > &sh)
 Compute F-order (column-major) strides: first dimension has stride 1.
template<typename Order, std::size_t N>
constexpr std::array< std::size_t, N > mtl::array::compute_strides (const shape< N > &sh)
 Compute strides for a given layout order.
template<std::size_t N>
constexpr std::size_t mtl::array::compute_offset (const std::array< std::size_t, N > &indices, const std::array< std::size_t, N > &strides)
 Compute flat offset from multi-index and strides.
template<std::size_t N, typename... Indices>
constexpr std::size_t mtl::array::offset_from (const std::array< std::size_t, N > &strides, Indices... indices)
 Variadic offset computation - converts (i, j, k, ...) to flat index.
template<std::size_t N>
constexpr bool mtl::array::broadcast_shape (const shape< N > &a, const shape< N > &b, shape< N > &result)
 Compute the broadcast shape of two shapes.
template<std::size_t N>
constexpr std::array< std::size_t, N > mtl::array::broadcast_strides (const shape< N > &original, const std::array< std::size_t, N > &strides, const shape< N > &target)
 Compute broadcast strides: dimension with extent 1 gets stride 0 (repeat).
template<std::size_t N>
constexpr bool mtl::array::detail_shape::same_layout (const shape< N > &sh, const std::array< std::size_t, N > &strides, const std::array< std::size_t, N > &dense)
 Whether strides lay the elements out as dense does.
template<std::size_t N>
constexpr bool mtl::array::is_contiguous_c (const shape< N > &sh, const std::array< std::size_t, N > &strides)
 Check if strides correspond to a contiguous C-order layout.
template<std::size_t N>
constexpr bool mtl::array::is_contiguous_f (const shape< N > &sh, const std::array< std::size_t, N > &strides)
 Check if strides correspond to a contiguous F-order layout.
template<std::size_t N>
constexpr bool mtl::array::is_contiguous (const shape< N > &sh, const std::array< std::size_t, N > &strides)
 Check if the array is contiguous in any order.