|
NumericAL
A header-only C++20 lexer built on REAL
|
A dense, row-major, N-dimensional tensor and Einstein summation. More...
#include <algorithm>#include <array>#include <cctype>#include <cmath>#include <complex>#include <cstddef>#include <deque>#include <initializer_list>#include <map>#include <memory>#include <mutex>#include <numeric>#include <optional>#include <ranges>#include <stdexcept>#include <string>#include <string_view>#include <type_traits>#include <utility>#include <vector>#include "gemm.hpp"#include "matrix.hpp"#include "parallel.hpp"#include "vector.hpp"Go to the source code of this file.
Classes | |
| class | numerical::einsum_error |
| Thrown when an einsum specification is malformed or inconsistent. More... | |
| class | numerical::tensor< T > |
A dense N-dimensional tensor of T with value semantics, read row-major. Its elements are immutable once built, so tensors share them: a copy, a tensor of another shape over the same elements (reshaped), one with its axes permuted (transposed) and a slice of them (sliced), views reading them along other strides, hold the one buffer, freed with the last of them. A view's elements in row-major order (data) are copied out on first need, once, and shared with the view's copies. More... | |
| struct | numerical::tensor< T >::row_major_copy |
| A view's elements in row-major order, copied out by the first data call and shared with the view's copies. More... | |
| struct | numerical::detail::pairwise_tree< T > |
The shape of NumPy's pairwise summation tree over the values of type T: below lanes values summed in order; up to block in lanes interleaved partial sums, added pairwise, then the remainder in order; above, the first half and the rest summed apart. NumPy counts in reals: a real's 8 partial sums and blocks of 128 are a complex number's 4 (its parts side by side) and 64, its half a multiple of 4. More... | |
| struct | numerical::detail::pairwise_tree< C > |
| pairwise_tree of complex numbers, as NumPy's sums their parts interleaved. More... | |
| struct | numerical::detail::operand_span< T > |
| The elements of an operand of einsum_pair, row-major along its labels: a tensor's, or an array's read where it lies. More... | |
| struct | numerical::detail::contraction_step |
One step of a contraction path: the operands at first and second of the current list, whose result goes to the list's end. More... | |
Namespaces | |
| namespace | numerical |
| The NumericAL public API. | |
| namespace | numerical::detail |
Concepts | |
| concept | numerical::detail::element_product |
The element types each_product takes: those each_rounded rounds as a product of depth one. | |
Functions | |
| template<typename T > | |
| buffer< T > | numerical::detail::permuted (const T *data, std::size_t count, const std::string &from, const std::string &to, const std::map< char, std::size_t > &sizes, std::size_t ld) |
The elements of data, whose axes carry the labels from (extents in sizes), laid out row-major along the labels to, a permutation of from that differs from it (so at least one label): a transpose of the last two labels by tiles, each slice of the leading ones; any other row by row of to's last label, a strided sweep. The threads share the work. data holds count elements, the product of the extents; a matrix (two labels) may have its rows ld elements apart (a NumPy array of every other row), 0 for contiguous ones. | |
| template<typename T > | |
| bool | numerical::approx_equal (const tensor< T > &a, const tensor< T > &b, double tolerance=1e-9) |
| Element-wise closeness within a tolerance (for inexact scalars). | |
| std::string | numerical::detail::shape_text (const std::vector< std::size_t > &shape) |
A shape as NumPy prints it, (2, 3), for a message. | |
| std::vector< std::size_t > | numerical::detail::broadcast_strides (const std::vector< std::size_t > &shape, std::size_t rank) |
The row-major strides of shape, with a stride of 0 on each axis of extent 1 (it broadcasts), aligned on the last axis of a result of rank rank (missing leading axes stride 0 too). | |
| std::vector< std::size_t > | numerical::broadcast_shape (const std::vector< std::size_t > &a, const std::vector< std::size_t > &b) |
The shape two shapes broadcast to, as NumPy's broadcast_shapes. | |
| template<typename Body > | |
| void | numerical::detail::run_fused (const Body &body) |
body(0), where std::fma is the instruction (with_fma_instruction) on an x86-64 processor with AVX2 and FMA: a body whose multiply-adds are all std::fma's, NUMERICAL_INLINE_LAMBDA, as what it calls must be. | |
| std::vector< std::ptrdiff_t > | numerical::detail::row_major_strides (const std::vector< std::size_t > &shape) |
The row-major strides of shape, in elements. | |
| bool | numerical::detail::lies_row_major (const std::vector< std::size_t > &shape, const std::vector< std::ptrdiff_t > &strides) |
Whether elements strides apart along the axes of shape lie row-major from the first (an axis of fewer than two elements stepping anything). | |
| template<typename T , typename Op , typename R = std::invoke_result_t<const Op&, const T&, const T&>> | |
| tensor< R > | numerical::detail::pairs_into (const T *a, const T *b, const std::vector< std::size_t > &shape, const Op &op) |
op(a, b) element by element of the row-major a and b, both of shape shape, in op's result type R, by chunks of elementwise_chunk among the threads. | |
| template<typename T , typename Op , typename R = std::invoke_result_t<const Op&, const T&, const T&>> | |
| tensor< R > | numerical::detail::broadcast_into (const T *a, const std::vector< std::size_t > &a_shape, const std::vector< std::ptrdiff_t > &a_strides, const T *b, const std::vector< std::size_t > &b_shape, const std::vector< std::ptrdiff_t > &b_strides, const Op &op) |
op(a, b) element by element of a, of shape a_shape, its elements a_strides apart along each axis from a (negative along an axis it reverses), and of b likewise, broadcast against each other (broadcast_apply's, its operands read where they lie), in op's result type R, row-major. Each element alone: the bits of the same operands laid row-major. | |
| template<typename T , typename Op , typename R = std::invoke_result_t<const Op&, const T&, const T&>> | |
| tensor< R > | numerical::detail::broadcast_into (const T *a, const std::vector< std::size_t > &a_shape, const T *b, const std::vector< std::size_t > &b_shape, const Op &op) |
op(a, b) element by element of the row-major a (a_shape) and b (b_shape), broadcast against each other, in op's result type R. | |
| template<typename T > | |
| T | numerical::detail::pairwise_quad (const T *p, std::size_t width) |
Four partial sums at p, width apart, added pairwise: (p₀ + p₁) + (p₂ + p₃). | |
| template<typename T > | |
| T | numerical::detail::pairwise_sum (const T *first, std::size_t count, std::size_t stride) |
Sum of count values from first at stride stride, by NumPy's pairwise summation (pairwise_tree). | |
| template<typename T > | |
| void | numerical::detail::pairwise_leaves (std::size_t count, std::vector< std::size_t > &out) |
The lengths of pairwise_sum's subtrees of at most pairwise_leaf values of type T over count, in order. | |
| template<typename T > | |
| T | numerical::detail::pairwise_combine (std::size_t count, const T *&next) |
The subtrees' sums from next on (pairwise_leaves' order) added as pairwise_sum's tree over count values adds its halves. | |
| template<typename T > | |
| T | numerical::detail::parallel_pairwise_sum (const T *first, std::size_t count) |
pairwise_sum of count contiguous values on the threads, to the bit: the tree's subtrees of at most pairwise_leaf values summed in parallel, each as pairwise_sum sums it, then added in the tree's order. The subtrees follow from the count alone. Four subtrees or fewer: on the caller (2¹⁶ doubles, ten AVX-512 cores: 11.7 µs alone, 14.5 shared; 2²⁰ 247 → 44 µs, 2²⁴ 12.5 → 2.2 ms). | |
| template<typename T > | |
| void | numerical::detail::pairwise_sum_rows (const T *first, std::size_t count, std::size_t stride, std::size_t width, T *out) |
pairwise_sum of width neighbouring columns at once, into out: column q's sum that of pairwise_sum(first + q, count, stride), to the bit, each step adding a whole row of the columns (contiguous, stride apart) where a column was walked down stride at a time. | |
| template<typename T > | |
| void | numerical::detail::pairwise_sums (const T *data, std::size_t outer, std::size_t count, std::size_t inner, T *out) |
The pairwise sums of outer blocks of count rows of inner elements (row-major), each column of a block summed down its rows, into out (outer × inner): one column at a time where inner is 1, else by rows (pairwise_sum_rows), the same bits. The blocks, and their runs of pairwise_columns columns, shared among the threads: each sum computed alike by whichever thread. | |
| bool | numerical::detail::is_label (char ch) |
Is ch an ASCII letter (a valid index label)? | |
| std::vector< std::string > | numerical::detail::split_inputs (const std::string &lhs) |
| Splits an einsum left-hand side into per-operand subscripts. | |
| template<typename T > | |
| tensor< T > | numerical::detail::tile_gemm (const T *a, std::size_t lda, const T *b, std::size_t ldb, std::size_t rows, std::size_t inner, std::size_t cols, std::vector< std::size_t > out_shape) |
Matrix product C(M×N) = A(M×K) · B(K×N), row-major. | |
| template<typename T > | |
| void | numerical::detail::add_column_term (std::true_type, T &sum, const T &f, const T &x) |
sum += f · x of strided_column_group, one fused multiply-add. | |
| template<typename T > | |
| void | numerical::detail::add_column_term (std::false_type, T &sum, const T &f, const T &x) |
sum += f · x of strided_column_group, as gemm_rows' plain loop rounds a term where it fuses none (rounded_apart_add, a complex product's infinities recovered as the library's). | |
| template<std::size_t Width, bool Fused = false, typename T > | |
| void | numerical::detail::strided_column_group (const T *a, const T *b, std::size_t row_step, std::size_t column_step, std::size_t inner, std::size_t j, T *y) |
Columns j to j + Width of vector_times_columns into y, their sums held through the rows: each term one fused multiply-add where Fused (as add_product adds each row on the arm64 fused paths), else add_one_product. | |
| template<typename T , bool Fused = false> | |
| buffer< T > | numerical::detail::vector_times_columns (const T *a, const T *b, std::size_t row_step, std::size_t column_step, std::size_t inner, std::size_t cols) |
canonical_product's vector a (inner) times a matrix b whose element B[k][j] is b[(k · row_step) + (j · column_step)]: each element of the product the sum canonical_product forms, a[k] · B[k][j] added in ascending order of k with add_product's arithmetic (add_one_product), so the same bits; strided_columns columns' sums held at once, where add_product stores and reloads them for every row of B. | |
| buffer< float > | numerical::detail::vector_times_columns (const float *a, const float *b, std::size_t row_step, std::size_t column_step, std::size_t inner, std::size_t cols) |
vector_times_columns for float: each term as gemm_rows rounds it, fused on the x86-64 AVX paths (avx2_strided_columns) and on arm64's NEON and AMX paths, elsewhere the template's arithmetic. | |
| buffer< double > | numerical::detail::vector_times_columns (const double *a, const double *b, std::size_t row_step, std::size_t column_step, std::size_t inner, std::size_t cols) |
vector_times_columns for double: on the x86-64 fused paths, where add_product adds each row by fused multiply-adds, by avx2_strided_columns; on the arm64 NEON and AMX paths, where it does too, by fused terms; elsewhere the template's arithmetic. | |
| template<split_complex C> | |
| buffer< C > | numerical::detail::complex_vector_times_columns (const C *a, const C *b, std::size_t row_step, std::size_t column_step, std::size_t inner, std::size_t cols) |
The complex vector a (inner) times a matrix b whose element B[k][j] is b[(k · row_step) + (j · column_step)], each element of the product rounded as the path's complex product rounds it (complex_terms, past complex_term::compiler): so the bits of its row in any product of a matrix by B. On the x86-64 complex tiles by their panels (avx2_complex_row_panels), on arm64 by gemm_split's blocks (split_row_columns). | |
| template<typename T > | |
| buffer< T > | numerical::detail::vector_times_transposed (const T *a, const T *bt, std::size_t ldbt, std::size_t inner, std::size_t cols) |
vector_times_columns of a matrix given as its transpose bt (cols × inner, its rows ldbt apart, B's columns); a complex one past complex_term::compiler by complex_vector_times_columns. | |
| template<typename T > | |
| void | numerical::detail::add_row_terms (T *y, const T *a, const T *b, std::size_t ldb, std::size_t inner, std::size_t count) |
y[j] += Σₖ a[k] · b[(k · ldb) + j] for count columns, B's inner rows added in order to a vector times a matrix by add_product, an integer's exact. | |
| template<split_complex C> | |
| bool | numerical::detail::parts_finite (const C *x, std::size_t count) noexcept |
Whether every part of count complex numbers from x is finite. | |
| template<split_complex C> | |
| void | numerical::detail::add_row_terms (C *y, const C *a, const C *b, std::size_t ldb, std::size_t inner, std::size_t count) |
add_row_terms of complex numbers as gemm_rows' plain loop rounds them (rounded_apart_add): a row by add_product's vectors where its factor and itself are finite, whose products are then the library's (both of a product's parts are NaN only from an infinite or NaN operand); else term by term, the library recovering a product of infinities. | |
| template<typename T > | |
| tensor< T > | numerical::detail::canonical_product (const T *a, std::size_t lda, const T *b, std::size_t ldb, std::size_t rows, std::size_t inner, std::size_t cols, std::vector< std::size_t > out_shape) |
The product of the row-major rows × inner a and inner × cols b, shaped out_shape: the canonical two-operand contraction of einsum_impl (a matrix times a vector, a vector times a matrix, a matrix product, a dot product). A matrix's rows lie lda (a) and ldb (b) apart, each row's elements together; a vector's elements together (b of one column: ldb then 1). | |
| template<typename T > | |
| std::optional< tensor< T > > | numerical::detail::diagonal_labels (const std::string &in, const std::string &output, std::size_t distinct, const std::vector< std::size_t > &shape, const T *data) |
einsum of one row-major operand data (shape, labelled in, distinct labels in all) whose last two labels are one (…ii), the others each once and output those in order, with that label (…ii->…i, each matrix's diagonal) or without (…ii->…, its sum by pairwise halving, as pairwise_sums adds a run: the same bits as trace's sum of the diagonal). None for any other spec. | |
| template<typename T > | |
| std::optional< tensor< T > > | numerical::detail::sum_over_run (const std::string &in, const std::string &output, const std::vector< std::size_t > &shape, const T *data) |
einsum of one row-major operand data (shape, its axes labelled in, each label once) into the labels output, where those it sums are one run of its axes and output the others in order (ij->i, ij->, ij->j, ijk->ik): each output element the sum of evenly spaced elements, by pairwise halving as sum() adds them (pairwise_sums), where einsum's general loop added them one after another. None for any other spec (nothing summed, the summed labels apart, the output reordered). | |
| template<typename T > | |
| buffer< T > | numerical::detail::permuted (const buffer< T > &data, const std::string &from, const std::string &to, const std::map< char, std::size_t > &sizes) |
| permuted of a buffer's elements. | |
| template<std::floating_point T> | |
| T | numerical::detail::fused_from_zero (T p, T q) noexcept |
std::fma(p, q, +0) without the instruction (in code built for any x86-64, std::fma is a call to the library, 40 000 elements of an outer product 18 → 114 µs on four AVX2 cores): the rounded product, which keeps the sign of a product that underflows to zero, plus +0 where an operand is zero, as the fused sum of an exact zero product and +0 is. | |
| template<std::floating_point R> | |
| std::complex< R > | numerical::detail::tile_product (const std::complex< R > &p, const std::complex< R > &q) noexcept |
0 + p·q of complex numbers as the x86-64 complex tiles round it (complex_term::tiles): each part's product from zero, their difference and their sum, each added to 0. | |
| template<std::floating_point R> | |
| std::complex< R > | numerical::detail::split_product (const std::complex< R > &p, const std::complex< R > &q) noexcept |
0 + p·q of complex numbers as arm64's real kernel rounds it (complex_term::split), a product of [Re p | −Im p] by [[Re q, Im q], [Im q, −Re q]]: each part's first product from zero, the second fused into it. | |
| template<typename T > requires std::is_arithmetic_v<T> | |
| tensor< T > | numerical::detail::each_rounded (const T *x, const std::vector< std::size_t > &x_shape, const T *y, const std::vector< std::size_t > &y_shape) |
The products that sum nothing of each_product, x and y broadcast against each other (broadcast_into), for a real or integer T: a fused first term where gemm_rows fuses one (rows_terms_fuse), else as the compiler rounds 0 + x·y. | |
| template<split_complex T> | |
| tensor< T > | numerical::detail::each_rounded (const T *x, const std::vector< std::size_t > &x_shape, const T *y, const std::vector< std::size_t > &y_shape) |
| each_rounded for complex numbers: as the path's complex product rounds a first term (complex_terms). | |
| template<typename T > | |
| tensor< T > | numerical::detail::each_product (const std::string &sa, operand_span< T > a, const std::string &sb, operand_span< T > b, const std::string &output, const std::map< char, std::size_t > &sizes) |
A batch of two-operand products that sum nothing (ij,j->ij, ijk,ik->ijk), each element of the output its operands' product added to 0 as gemm_rows rounds a product's first term (rows_terms_fuse), a complex one as the path's complex product rounds it (complex_terms): the bits of contract_pair's products of depth one. Each operand's axes in the output's order (a copy only where they lie otherwise), broadcast against the other (broadcast_into), where those products went one matrix product of depth one per element of the batch (1000 × 1000 times a row of 1000, six AVX2 cores: 19.7 → 0.5 ms). | |
| template<typename T > | |
| tensor< T > | numerical::detail::contract_pair (const std::string &sa, operand_span< T > a, const std::string &sb, operand_span< T > b, const std::string &output, const std::string &summed, const std::map< char, std::size_t > &sizes) |
A two-operand contraction as matrix products: the labels both operands and the output carry (batch), those one operand and the output carry (free), and those both operands carry alone (summed, in ascending order, the order the general loop sums them in, so each element takes the same terms in the same order) regroup each operand as a stack of matrices, A as batch × free_a × summed and B as batch × summed × free_b, multiplied batch by batch through the packed kernel, batches in parallel; the result is laid out in the output's order; a dot product per batch by dot_product. Each label of an operand once, and each in the other operand or the output: einsum_impl sums an operand's own labels and reads a repeated one's diagonal first. | |
| std::string | numerical::detail::pair_keeps (const std::vector< std::string > &labels, std::size_t i, std::size_t j, const std::string &output) |
The labels of labels[i] and labels[j] that the output or another operand carries, in their order of appearance, once each: what their contraction keeps. | |
| double | numerical::detail::extent_product (const std::string &labels, const std::map< char, std::size_t > &sizes) |
The product of the extents of labels' distinct labels, as a double (a cost: it may pass size_t). | |
| std::vector< std::string > | numerical::detail::after_step (const std::vector< std::string > &labels, contraction_step step, const std::string &output) |
| The list after a contraction step: the two operands' labels removed, their result's appended. | |
| void | numerical::detail::cheapest_path (const std::vector< std::string > &labels, const std::string &output, const std::map< char, std::size_t > &sizes, std::vector< contraction_step > &path, double &cost, double &largest) |
The cheapest order of contraction from labels, and its cost and largest intermediate: every order tried, the first found kept among equals. | |
| std::vector< contraction_step > | numerical::detail::contraction_path (std::vector< std::string > labels, const std::string &output, const std::map< char, std::size_t > &sizes) |
The order in which to contract operands labelled labels into output, as opt_einsum chooses it: the cheapest in multiply-adds (the product of the extents a pair's labels span), the smaller largest intermediate among equals, over every order up to exhaustive_path_operands operands; past it, the cheapest pair at each step among those sharing a label (an outer product, cheap in itself, would leave its labels to every later step), the smaller result, then the first pair, among equals. It depends on the shapes alone, so a result is the same on any number of threads. | |
| std::size_t | numerical::detail::ellipsis_in (const std::string &subscripts) |
| Evaluates a parsed einsum over its operands. | |
| template<typename T > | |
| tensor< T > | numerical::detail::einsum_pair (const std::string &s0, operand_span< T > a, const std::string &s1, operand_span< T > b, const std::string &output, const std::string &summed, const std::map< char, std::size_t > &sizes) |
einsum of two operands a (labels s0) and b (s1) into output, summed the labels neither the output carries (ascending), sizes each label's extent: each label of an operand once, and each in the other operand or the output (einsum_impl sums an operand's own labels and reads a repeated one's diagonal first). A tensor's elements or an array's read where it lies, the same bits either way. | |
| template<typename T > | |
| tensor< T > | numerical::detail::einsum_impl (const std::string &spec_in, const std::vector< const tensor< T > * > &operands) |
Einstein summation of operands as spec_in reads it (einsum): einsum_spec. | |
| template<typename T > | |
| tensor< T > | numerical::detail::einsum_ellipsis (const std::string &spec, const std::vector< const tensor< T > * > &operands) |
einsum_impl of a spec with ellipses, as NumPy reads them: each ... stands for an operand's axes its letters leave, aligned from the right across the operands and broadcast (an extent of 1 repeated), named by letters the spec does not use. An operand's axis of extent 1 under the ellipsis where another's is longer is dropped with its letter, so that operand repeats along it. The output: its ... the broadcast axes (an output without one, where an operand has such axes, is refused, as NumPy refuses it); with no ->, the broadcast axes then the letters that appear once, in order. | |
| template<typename To , typename From > | |
| tensor< To > | numerical::detail::converted (const tensor< From > &t) |
A copy of t, each element converted to To (between a signed integer type and its unsigned one, the same bits, modulo 2ⁿ), by chunks of elementwise_chunk among the threads: one thread's copy and its pages' first touches were most of an int64 dot (10⁶ elements, M1 Pro: 0.49 of 0.61 ms). | |
| template<typename T > | |
| tensor< T > | numerical::detail::einsum_spec (const std::string &spec_in, const std::vector< const tensor< T > * > &operands) |
| einsum_impl of a type whose sums and products are defined past its range: a float, a complex, an unsigned integer. | |
| template<typename T , typename ... Rest> | |
| tensor< T > | numerical::einsum (const std::string &spec, const tensor< T > &first, const Rest &... rest) |
| Einstein summation over one or more tensor operands. | |
| template<typename T > | |
| tensor< T > | numerical::einsum (const std::string &spec, const std::vector< const tensor< T > * > &operands) |
Einstein summation over operands counted at run time: einsum for a caller that holds them in a container (an interpreter evaluating einsum("ij,jk->ik", a, b) from a parse). | |
| template<typename T > | |
| tensor< T > | numerical::detail::stacked_matmul (const tensor< T > &a, const tensor< T > &b) |
| numerical::matmul of a type whose sums and products are defined past its range: a float, a complex, an unsigned integer. | |
| template<typename T > | |
| tensor< T > | numerical::matmul (const tensor< T > &a, const tensor< T > &b) |
The matrix product of two tensors, as NumPy's matmul: each operand a stack of matrices along its leading axes, those axes broadcast against the other's (aligned from the right, an extent of 1 repeated), one product per matrix of the broadcast stack through the packed kernel, the products in parallel. A vector first is a row (its axis absent from the result), a vector second a column (likewise); two vectors give their dot product, of rank 0. The broadcast operands are not copied: a repeated matrix is read where it is. | |
Variables | |
| constexpr std::size_t | numerical::sliced_copy_most {512} |
| The most elements tensor::sliced copies at once rather than viewing (4 KiB of doubles). | |
| constexpr std::size_t | numerical::detail::pairwise_lanes {8} |
| The partial sums pairwise_sum interleaves, and the multiple of which its first half is long. | |
| constexpr std::size_t | numerical::detail::pairwise_leaf {std::size_t {1} << 15U} |
The longest subtree of pairwise_sum's tree parallel_pairwise_sum sums on one thread: 256 KiB of double. | |
| constexpr std::size_t | numerical::detail::pairwise_columns {512} |
| The columns pairwise_sum_rows sums at once: its partial sums of eight rows, 32 KiB of doubles, stay in the L1 cache. | |
| constexpr std::size_t | numerical::detail::vector_chunk {128} |
| The columns a thread takes of a vector times a matrix: each of its rows added to them in order. | |
| template<typename T > | |
| constexpr std::size_t | numerical::detail::term_work {is_complex_number<T> ? 4 : 1} |
The real multiply-adds of a term a · b of T, as parallel_for counts work: four for a complex one. | |
| constexpr std::size_t | numerical::detail::strided_columns {8} |
| The columns of B one task of vector_times_columns sums together: their sums' chains interleaved, each waiting on its own last addition. | |
| constexpr std::size_t | numerical::detail::complex_row_columns {32} |
The columns of a task of complex_vector_times_columns divide: the most its kernels hold in registers at once (sixteen NEON registers of complex float). | |
| constexpr std::size_t | numerical::detail::column_sums_below {9} |
The columns under which canonical_product sums a vector times a matrix by vector_times_columns, the same bits as its rows added in order: below it faster for every type from a depth of a hundred (a few nanoseconds either way under it), from it slower for a real type. On x86-64 the rows' vectors of eight float (AVX2) make the rows' loop the faster sooner. | |
| constexpr std::size_t | numerical::detail::exhaustive_path_operands {4} |
| The operands at most whose contraction order contraction_path searches exhaustively; more take the cheapest pair at each step. | |
A dense, row-major, N-dimensional tensor and Einstein summation.
numerical::tensor is generic over its element type T (the scalar) and over its rank: rank-1 is a vector, rank-2 a matrix, rank-0 a scalar. It is the unifying primitive of the library's vector/tensor algebra. A tensor is built directly from a shape and a row-major buffer, or from a numerical::vector or numerical::matrix (its rank-1 / rank-2 special cases).
numerical::einsum evaluates an Einstein-summation specification such as "ij,jk->ik" (matrix product), "i,i->" (dot product), "ij->ji" (transpose), "ii->" (trace) or "i,j->ij" (outer product), over one or more operands. Each single letter is an index label; a label shared by several axes ties them together; a label absent from the output is summed over. Labels are ASCII letters. Summation runs in a deterministic order (labels sorted ascending), so results are reproducible; a plain dot product ("i,i->") sums in a fixed vectorised order instead, the same on any number of threads (detail::chunked_dot).
Definition in file tensor.hpp.