11#ifndef NUMERICAL_VECTOR_HPP
12#define NUMERICAL_VECTOR_HPP
19#include <initializer_list>
53 if (a != 0 && b > (std::numeric_limits<std::size_t>::max() / a)) {
65 template <
typename It>
69 if (std::find(first,
last, std::size_t {0}) !=
last) {
72 std::size_t count {1};
73 for (; first !=
last; ++first) {
93 vector(std::initializer_list<T> elements)
104 explicit vector(
const std::vector<T>& elements)
123 return data_.begin();
144 template <
typename T>
152 std::transform(a.
begin(), a.
end(), b.
begin(),
out.begin(), std::plus<T> {});
157 template <
typename T>
165 std::transform(a.
begin(), a.
end(), b.
begin(),
out.begin(), std::minus<T> {});
170 template <
typename T>
176 [&scalar](
const T&
element) { return scalar * element; });
181 template <
typename T>
189 template <
typename T>
208 template <
typename T>
216 for (std::size_t i {0}; i < a.
size(); ++i) {
219 if (!(a[i] == b[i]) && !(std::abs(a[i] - b[i]) <=
tolerance)) {
numerical::buffer, the storage of the library's vectors, matrices and tensors: a std::vector whose el...
Thrown when an operation's operands have incompatible shapes.
dimension_error(const std::string &message)
Builds the error.
A dense vector of T with value semantics.
vector(buffer< T > elements)
From an existing buffer.
buffer< T >::const_iterator end() const noexcept
Const iterator past the last element.
const T & operator[](std::size_t index) const
The element at index.
vector(const std::vector< T > &elements)
From a std::vector, copied into the storage (a buffer moves in instead).
bool operator==(const vector &other) const
Exact element-wise equality (same size, equal elements).
buffer< T > data_
The elements.
std::size_t size() const noexcept
The number of elements.
vector(std::initializer_list< T > elements)
From a braced list of elements.
buffer< T >::const_iterator begin() const noexcept
Const iterator to the first element.
vector()=default
An empty vector (size 0).
std::size_t checked_mul(std::size_t a, std::size_t b)
a * b, throwing numerical::dimension_error if the product overflows std::size_t. Guards dimension/sha...
std::size_t element_count(It first, It last)
The elements a shape's extents [first, last) hold: 0 where one of them is 0, whatever the others,...
The NumericAL public API.
std::vector< T, detail::default_init_allocator< T > > buffer
The storage of vector, matrix and tensor, namely a std::vector whose buffer<T>(n) and resize(n) leave...
matrix< T > operator+(const matrix< T > &a, const matrix< T > &b)
Element-wise sum.
T dot(const vector< T > &a, const vector< T > &b)
Dot product.
matrix< T > operator*(const T &scalar, const matrix< T > &m)
Scalar times matrix.
@ amx
The Apple AMX coprocessor, fused multiply-adds; the products it does not suit on the NEON path's tile...
matrix< T > operator-(const matrix< T > &a, const matrix< T > &b)
Element-wise difference.
bool approx_equal(const matrix< T > &a, const matrix< T > &b, double tolerance=1e-9)
Element-wise closeness within a tolerance (for inexact scalars).