|
C(++)ECCO
C++ Error Control COding: a header-only library for ECC simulations and experiments, modeling complete coding systems across arbitrary finite fields and complex inter-field relationships - Christian Senger <senger@inue.uni-stuttgart.de>
|
Vector v = (v₀, v₁, …, vₙ₋₁) over a CECCO::ComponentType. More...
#include <vectors.hpp>
Public Types | |
| enum | CacheIds { Weight = 0 } |
Public Member Functions | |
| template<FiniteFieldType S> | |
| Vector< T > & | operator= (const Vector< S > &other) |
| template<typename U> requires std::constructible_from<Vector<T>, U> | |
| Vector< T > & | append (U &&rhs) |
| template<typename U> requires std::constructible_from<Vector<T>, U> | |
| Vector< T > & | prepend (U &&lhs) |
| template<typename U> requires std::convertible_to<std::decay_t<U>, T> | |
| Vector< T > & | set_component (size_t i, U &&c) |
Constructors | |
| constexpr | Vector () noexcept |
| Default constructor: empty vector (length 0). | |
| Vector (size_t n) | |
| Length-n vector with default-initialised components (T() = 0). | |
| Vector (size_t n, const T &l) | |
| Length-n vector with every component equal to l. | |
| Vector (const std::initializer_list< T > &l) | |
| From an initializer list of components, in order. | |
| Vector (const Vector &other) | |
| constexpr | Vector (Vector &&other) noexcept |
| template<FiniteFieldType S> requires FiniteFieldType<T> && ExtensionOf<S, T> | |
| Vector (const Matrix< S > &mat) | |
| From a matrix over a subfield: each column becomes one T component. | |
| template<FiniteFieldType S> | |
| Vector (const Vector< S > &other) | |
| Cross-field conversion between two finite fields of the same characteristic. | |
| Vector (const Polynomial< T > &poly) | |
| From polynomial coefficients: component i becomes poly[i]. | |
Assignment Operators | |
| constexpr Vector & | operator= (const Vector &rhs) |
| constexpr Vector & | operator= (Vector &&rhs) noexcept |
| constexpr Vector & | operator= (const T &rhs) noexcept |
| Set every component to rhs. | |
| template<FiniteFieldType S> | |
| Vector & | operator= (const Vector< S > &other) |
| Cross-field assignment (same semantics as the cross-field constructor). | |
Unary Arithmetic Operations | |
| constexpr Vector | operator+ () const &noexcept |
| Unary + (lvalue): returns a copy. | |
| constexpr Vector | operator+ () &&noexcept |
| Unary + (rvalue): returns the rvalue itself. | |
| constexpr Vector | operator- () const & |
| Unary − (lvalue): returns a new vector with each component negated. | |
| constexpr Vector | operator- () &&noexcept |
| Unary − (rvalue): negates components in place. | |
Compound Assignment Operations | |
| Vector & | operator+= (const Vector &rhs) |
| Component-wise addition this[i] += rhs[i]. | |
| Vector & | operator-= (const Vector &rhs) |
| Component-wise subtraction this[i] -= rhs[i]. | |
| constexpr Vector & | operator*= (const T &s) noexcept |
| Multiply every component by the scalar s. | |
| Vector & | operator/= (const T &s) |
| Divide every component by the scalar s. | |
Randomization | |
| Vector & | randomize () noexcept |
| Replace components with random values appropriate for T. | |
| Vector & | randomize_nonzero () noexcept |
| Like randomize but every component is guaranteed non-zero. | |
| Vector & | randomize_pairwise_distinct () |
| Fill with pairwise distinct field elements (shuffled labels 0, …, q − 1). | |
Information and Properties | |
| constexpr size_t | get_n () const noexcept |
| Vector length (number of components). | |
| constexpr bool | is_empty () const noexcept |
| True iff length is 0 (distinct from a non-empty all-zero vector). | |
| constexpr bool | is_zero () const noexcept |
| True iff every component equals T(0); also true for the empty vector. | |
| constexpr bool | is_pairwise_distinct () const |
| True iff no two components are equal. | |
| std::vector< size_t > | supp () const |
| Sorted indices of non-zero components (empty vector for an all-zero input). | |
| size_t | wH () const noexcept |
| Hamming weight: number of non-zero, non-erased components; cached on first call. | |
| constexpr size_t | burst_length () const noexcept |
| Burst length R − L + 1, where L, R are the first and last non-zero indices; 0 for an all-zero or empty vector. | |
| constexpr size_t | cyclic_burst_length () const noexcept |
| Cyclic burst length: shortest circular arc covering all non-zero positions; 0 for an all-zero or empty vector. | |
Component Access and Manipulation | |
| template<typename U> requires std::convertible_to<std::decay_t<U>, T> | |
| Vector & | set_component (size_t i, U &&c) |
| Set component i by perfect-forwarding c. | |
| const T & | operator[] (size_t i) const |
| Read access to component i. | |
| Vector | get_subvector (size_t i, size_t w) const & |
| Extract the contiguous subvector [i, i + w). | |
| Vector & | get_subvector (size_t i, size_t w) && |
| In-place rvalue overload of get_subvector (truncates to [i, i + w)). | |
| Vector & | set_subvector (const Vector &v, size_t i) |
| Overwrite components [i, i + v.get_n()) with v. | |
| Vector & | set_subvector (Vector &&v, size_t i) |
| Rvalue overload of set_subvector (move-assigns components from v). | |
| Vector & | append (const Vector &rhs) |
| Append rhs: result becomes [*this | rhs]. | |
| Vector & | append (Vector &&rhs) |
| Rvalue overload of append (moves components from rhs). | |
| template<typename U> requires std::constructible_from<Vector<T>, U> | |
| Vector & | append (U &&rhs) |
| Append after converting rhs to Vector<T>. | |
| Vector & | prepend (const Vector &rhs) |
| Prepend rhs: result becomes [rhs | *this]. | |
| Vector & | prepend (Vector &&rhs) |
| Rvalue overload of prepend (moves components from rhs). | |
| template<typename U> requires std::constructible_from<Vector<T>, U> | |
| Vector & | prepend (U &&lhs) |
| Prepend after converting lhs to Vector<T>. | |
| Vector & | delete_components (const std::vector< size_t > &v) |
| Delete the components whose indices appear in v and compact. | |
| Vector & | delete_component (size_t i) |
| Delete component i (single-index convenience for delete_components). | |
| Vector & | erase_components (const std::vector< size_t > &v) |
| Mark every component whose index appears in v as erased. | |
| Vector & | erase_component (size_t i) |
| Erase component i (single-index convenience for erase_components). | |
| Vector & | unerase_components (const std::vector< size_t > &v) |
| Clear the erasure flag on every component whose index appears in v (resets to T(0)). | |
| Vector & | unerase_component (size_t i) |
| Un-erase component i (single-index convenience for unerase_components). | |
| Vector & | pad_front (size_t n) |
| Prepend zeros so the vector has length at least n (no-op if already ≥ n). | |
| Vector & | pad_back (size_t n) |
| Append zeros so the vector has length at least n (no-op if already ≥ n). | |
Transformations | |
| constexpr Vector & | rotate_left (size_t i) noexcept |
| Circular left shift by i positions: j ↦ (j − i) mod n. | |
| constexpr Vector & | rotate_right (size_t i) noexcept |
| Circular right shift by i positions: j ↦ (j + i) mod n. | |
| constexpr Vector & | reverse () noexcept |
| Reverse component order: i ↦ n − 1 − i. | |
| constexpr Vector & | fill (const T &value) noexcept |
| Set every component to value. | |
Finite Field Specific Operations | |
| size_t | as_integer () const noexcept |
| Interpret as a base-q integer, where q = T::get_size(). | |
| Vector & | from_integer (size_t value, size_t n) |
| Replace *this with the length-n base-q encoding of value. | |
| template<FiniteFieldType S> requires FiniteFieldType<T> && SubfieldOf<T, S> && (!std::is_same_v<T, S>) | |
| Matrix< S > | as_matrix () const |
| Expand each component into its S-coefficient column. | |
| Matrix< T > | to_matrix (size_t m) const |
| Reshape into an m × (n/m) matrix, row-major. | |
Friends | |
| class | Matrix< T > |
| template<ReliablyComparableType U> | |
| constexpr bool | operator== (const Vector< U > &lhs, const Vector< U > &rhs) noexcept |
| constexpr T | inner_product (const Vector< T > &lhs, const Vector< T > &rhs) |
| Inner product ⟨lhs, rhs⟩ = Σᵢ lhs[i] · rhs[i]. | |
| constexpr Vector< T > | Schur_product (const Vector< T > &lhs, const Vector< T > &rhs) |
| Schur (component-wise) product. | |
| Vector | unit_vector (size_t length, size_t i) |
| Length-length vector with T(1) at index i and zeros elsewhere. | |
| std::ostream & | operator<< (std::ostream &os, const Vector &rhs) |
| Stream output as ( c₀, c₁, …, cₙ₋₁ ). | |
| double | dE (const Vector< std::complex< double > > &lhs, const Vector< std::complex< double > > &rhs) |
| Euclidean distance ‖lhs − rhs‖₂ = √(Σᵢ |lhs[i] − rhs[i]|²) for complex vectors. | |
Vector v = (v₀, v₁, …, vₙ₋₁) over a CECCO::ComponentType.
| T | Component type satisfying CECCO::ComponentType (finite field, double, std::complex<double>, or signed integer including InfInt) |
Components are stored contiguously; length is fixed except via the explicit resizers (pad_front, pad_back, append, prepend, delete_components, …). Dimension mismatches in arithmetic throw std::invalid_argument. Hamming weight is computed lazily and cached; the cache is invalidated on any mutation. Methods that compare against zero (wH, supp, burst_length, …) are gated by requires ReliablyComparableType<T>.
Cross-field constructors and assignment operators between two finite fields of the same characteristic route through CECCO::details::largest_common_subfield_t, so vectors over fields from disjoint construction towers can interoperate.
Definition at line 115 of file vectors.hpp.
| enum CECCO::Vector::CacheIds |
| Enumerator | |
|---|---|
| Weight | |
Definition at line 127 of file vectors.hpp.
|
inlineconstexprnoexcept |
Default constructor: empty vector (length 0).
Definition at line 134 of file vectors.hpp.
|
inlineexplicit |
Length-n vector with default-initialised components (T() = 0).
Definition at line 137 of file vectors.hpp.
| CECCO::Vector< T >::Vector | ( | size_t | n, |
| const T & | l ) |
Length-n vector with every component equal to l.
Definition at line 522 of file vectors.hpp.
|
inline |
From an initializer list of components, in order.
Definition at line 143 of file vectors.hpp.
| CECCO::Vector< T >::Vector | ( | const Vector< T > & | other | ) |
Definition at line 525 of file vectors.hpp.
|
constexprnoexcept |
Definition at line 528 of file vectors.hpp.
| CECCO::Vector< T >::Vector | ( | const Matrix< S > & | mat | ) |
From a matrix over a subfield: each column becomes one T component.
| S | Subfield of T (in the construction tower) |
| std::invalid_argument | if mat.get_m() does not match [T:S] (the extension degree of T over S) |
Definition at line 532 of file vectors.hpp.
| CECCO::Vector< T >::Vector | ( | const Vector< S > & | other | ) |
Cross-field conversion between two finite fields of the same characteristic.
| S | Source field type (Vector<S>); must share characteristic with T |
Converts component by component via T's cross-field constructor, which routes through CECCO::details::largest_common_subfield_t and so handles disjoint construction towers. Propagates std::invalid_argument if any component is not representable in T.
Definition at line 547 of file vectors.hpp.
| CECCO::Vector< T >::Vector | ( | const Polynomial< T > & | poly | ) |
From polynomial coefficients: component i becomes poly[i].
Resulting length is poly.degree() + 1. For cross-field conversion, convert the polynomial first.
Definition at line 555 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::append | ( | const Vector< T > & | rhs | ) |
Append rhs: result becomes [*this | rhs].
Definition at line 649 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::append | ( | U && | rhs | ) |
Definition at line 696 of file vectors.hpp.
| Vector & CECCO::Vector< T >::append | ( | U && | rhs | ) |
Append after converting rhs to Vector<T>.
| Vector< T > & CECCO::Vector< T >::append | ( | Vector< T > && | rhs | ) |
Rvalue overload of append (moves components from rhs).
Definition at line 662 of file vectors.hpp.
|
noexcept |
Interpret as a base-q integer, where q = T::get_size().
Component data[n − 1 − i] is the i-th digit (least-significant first), so the value is Σ data[n − 1 − i] · qⁱ.
Definition at line 1062 of file vectors.hpp.
| Matrix< S > CECCO::Vector< T >::as_matrix | ( | ) | const |
Expand each component into its S-coefficient column.
| S | Subfield of T |
Definition at line 1092 of file vectors.hpp.
|
constexprnoexcept |
Burst length R − L + 1, where L, R are the first and last non-zero indices; 0 for an all-zero or empty vector.
Definition at line 953 of file vectors.hpp.
|
constexprnoexcept |
Cyclic burst length: shortest circular arc covering all non-zero positions; 0 for an all-zero or empty vector.
Definition at line 969 of file vectors.hpp.
|
inline |
Delete component i (single-index convenience for delete_components).
| std::invalid_argument | if i is out of bounds |
Definition at line 394 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::delete_components | ( | const std::vector< size_t > & | v | ) |
Delete the components whose indices appear in v and compact.
| v | Indices (deduplicated internally) |
| std::invalid_argument | if any index in v is out of bounds |
Definition at line 721 of file vectors.hpp.
|
inline |
Erase component i (single-index convenience for erase_components).
Definition at line 411 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::erase_components | ( | const std::vector< size_t > & | v | ) |
Mark every component whose index appears in v as erased.
| v | Indices (deduplicated internally) |
| std::invalid_argument | if any index in v is out of bounds |
Definition at line 746 of file vectors.hpp.
|
constexprnoexcept |
Set every component to value.
Definition at line 818 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::from_integer | ( | size_t | value, |
| size_t | n ) |
Replace *this with the length-n base-q encoding of value.
Left inverse of as_integer: v.from_integer(v.as_integer(), v.get_n()) == v.
| std::out_of_range | if value does not fit into n base-q digits |
Definition at line 1072 of file vectors.hpp.
|
inlineconstexprnoexcept |
Vector length (number of components).
Definition at line 278 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::get_subvector | ( | size_t | i, |
| size_t | w ) && |
In-place rvalue overload of get_subvector (truncates to [i, i + w)).
Definition at line 882 of file vectors.hpp.
| Vector< T > CECCO::Vector< T >::get_subvector | ( | size_t | i, |
| size_t | w ) const & |
Extract the contiguous subvector [i, i + w).
| std::invalid_argument | if [i, i + w) exceeds the vector |
Definition at line 871 of file vectors.hpp.
|
inlineconstexprnoexcept |
True iff length is 0 (distinct from a non-empty all-zero vector).
Definition at line 281 of file vectors.hpp.
|
constexpr |
True iff no two components are equal.
Definition at line 927 of file vectors.hpp.
|
constexprnoexcept |
True iff every component equals T(0); also true for the empty vector.
Definition at line 920 of file vectors.hpp.
|
constexprnoexcept |
Multiply every component by the scalar s.
Definition at line 630 of file vectors.hpp.
|
inlineconstexprnoexcept |
Unary + (rvalue): returns the rvalue itself.
Definition at line 206 of file vectors.hpp.
|
inlineconstexprnoexcept |
Unary + (lvalue): returns a copy.
Definition at line 204 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::operator+= | ( | const Vector< T > & | rhs | ) |
Component-wise addition this[i] += rhs[i].
| std::invalid_argument | if this->get_n() != rhs.get_n() |
Definition at line 611 of file vectors.hpp.
|
constexprnoexcept |
Unary − (rvalue): negates components in place.
Definition at line 605 of file vectors.hpp.
|
constexpr |
Unary − (lvalue): returns a new vector with each component negated.
Definition at line 598 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::operator-= | ( | const Vector< T > & | rhs | ) |
Component-wise subtraction this[i] -= rhs[i].
| std::invalid_argument | if this->get_n() != rhs.get_n() |
Definition at line 619 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::operator/= | ( | const T & | s | ) |
Divide every component by the scalar s.
| std::invalid_argument | if s == T(0) |
Definition at line 642 of file vectors.hpp.
|
constexprnoexcept |
Set every component to rhs.
Definition at line 579 of file vectors.hpp.
|
constexpr |
Definition at line 563 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::operator= | ( | const Vector< S > & | other | ) |
Definition at line 588 of file vectors.hpp.
| Vector & CECCO::Vector< T >::operator= | ( | const Vector< S > & | other | ) |
Cross-field assignment (same semantics as the cross-field constructor).
|
constexprnoexcept |
Definition at line 571 of file vectors.hpp.
| const T & CECCO::Vector< T >::operator[] | ( | size_t | i | ) | const |
Read access to component i.
| std::invalid_argument | if i is out of bounds |
Definition at line 865 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::pad_back | ( | size_t | n | ) |
Append zeros so the vector has length at least n (no-op if already ≥ n).
Definition at line 809 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::pad_front | ( | size_t | n | ) |
Prepend zeros so the vector has length at least n (no-op if already ≥ n).
Definition at line 798 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::prepend | ( | const Vector< T > & | rhs | ) |
Prepend rhs: result becomes [rhs | *this].
Definition at line 672 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::prepend | ( | U && | lhs | ) |
Definition at line 709 of file vectors.hpp.
| Vector & CECCO::Vector< T >::prepend | ( | U && | lhs | ) |
Prepend after converting lhs to Vector<T>.
| Vector< T > & CECCO::Vector< T >::prepend | ( | Vector< T > && | rhs | ) |
Rvalue overload of prepend (moves components from rhs).
Definition at line 685 of file vectors.hpp.
|
noexcept |
Replace components with random values appropriate for T.
Distribution per component: finite-field types draw uniformly from the field; signed integers from [−100, 100]; double and the parts of std::complex<double> from [−1, 1].
Definition at line 1013 of file vectors.hpp.
|
noexcept |
Like randomize but every component is guaranteed non-zero.
Definition at line 1032 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::randomize_pairwise_distinct | ( | ) |
Fill with pairwise distinct field elements (shuffled labels 0, …, q − 1).
| std::invalid_argument | if the vector length exceeds the field cardinality q |
Definition at line 1044 of file vectors.hpp.
|
constexprnoexcept |
Reverse component order: i ↦ n − 1 − i.
Definition at line 841 of file vectors.hpp.
|
constexprnoexcept |
Circular left shift by i positions: j ↦ (j − i) mod n.
Definition at line 829 of file vectors.hpp.
|
constexprnoexcept |
Circular right shift by i positions: j ↦ (j + i) mod n.
Definition at line 835 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::set_component | ( | size_t | i, |
| U && | c ) |
Definition at line 848 of file vectors.hpp.
| Vector & CECCO::Vector< T >::set_component | ( | size_t | i, |
| U && | c ) |
Set component i by perfect-forwarding c.
| std::invalid_argument | if i is out of bounds |
| Vector< T > & CECCO::Vector< T >::set_subvector | ( | const Vector< T > & | v, |
| size_t | i ) |
Overwrite components [i, i + v.get_n()) with v.
| std::invalid_argument | if the replacement region exceeds the vector |
Definition at line 894 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::set_subvector | ( | Vector< T > && | v, |
| size_t | i ) |
Rvalue overload of set_subvector (move-assigns components from v).
Definition at line 907 of file vectors.hpp.
|
inline |
Sorted indices of non-zero components (empty vector for an all-zero input).
| std::invalid_argument | if *this is empty (length 0) |
Definition at line 296 of file vectors.hpp.
| Matrix< T > CECCO::Vector< T >::to_matrix | ( | size_t | m | ) | const |
Reshape into an m × (n/m) matrix, row-major.
Inverse of Matrix::to_vector: index k of this vector lands at (k/cols, kcols) with cols = n/m.
| std::invalid_argument | if m does not divide the vector length |
Definition at line 1125 of file vectors.hpp.
|
inline |
Un-erase component i (single-index convenience for unerase_components).
Definition at line 427 of file vectors.hpp.
| Vector< T > & CECCO::Vector< T >::unerase_components | ( | const std::vector< size_t > & | v | ) |
Clear the erasure flag on every component whose index appears in v (resets to T(0)).
| v | Indices (deduplicated internally) |
| std::invalid_argument | if any index in v is out of bounds |
Definition at line 764 of file vectors.hpp.
|
inlinenoexcept |
Hamming weight: number of non-zero, non-erased components; cached on first call.
Definition at line 307 of file vectors.hpp.
|
friend |
Euclidean distance ‖lhs − rhs‖₂ = √(Σᵢ |lhs[i] − rhs[i]|²) for complex vectors.
| std::invalid_argument | if lengths differ |
Definition at line 1651 of file vectors.hpp.
|
friend |
Inner product ⟨lhs, rhs⟩ = Σᵢ lhs[i] · rhs[i].
For complex inputs this is the standard product (not the conjugate inner product).
| std::invalid_argument | if lengths differ |
Definition at line 1513 of file vectors.hpp.
|
friend |
Definition at line 122 of file vectors.hpp.
|
friend |
Stream output as ( c₀, c₁, …, cₙ₋₁ ).
Definition at line 1562 of file vectors.hpp.
|
friend |
|
friend |
Schur (component-wise) product.
| std::invalid_argument | if lengths differ |
Definition at line 1526 of file vectors.hpp.
|
friend |
Length-length vector with T(1) at index i and zeros elsewhere.
| std::invalid_argument | if i >= length |
Definition at line 1552 of file vectors.hpp.