11#ifndef NUMERICAL_VECTOR_HPP
12#define NUMERICAL_VECTOR_HPP
19#include <initializer_list>
59 template <
typename Std>
67 [[nodiscard]]
const char*
what() const noexcept
override
118 std::size_t extent)
noexcept
123 if (first >= extent) {
126 const std::size_t room {step >= 0 ? extent - 1 - first : first};
127 const std::size_t magnitude {step >= 0 ?
static_cast<std::size_t
>(step) : std::size_t {0} -
static_cast<std::size_t
>(step)};
128 return magnitude == 0 || count - 1 <= room / magnitude;
138 if (a != 0 && b > (std::numeric_limits<std::size_t>::max() / a)) {
150 template <
typename It>
154 if (std::find(first, last, std::size_t {0}) != last) {
157 std::size_t count {1};
158 for (; first != last; ++first) {
169 template <
typename T>
178 vector(std::initializer_list<T> elements)
184 : data_(std::move(elements))
189 explicit vector(
const std::vector<T>& elements)
190 : data_(elements.begin(), elements.end())
194 [[nodiscard]] std::size_t
size() const noexcept
208 return data_.begin();
220 return data_ == other.
data_;
229 template <
typename T>
237 std::transform(a.
begin(), a.
end(), b.
begin(), out.begin(), std::plus<T> {});
242 template <
typename T>
250 std::transform(a.
begin(), a.
end(), b.
begin(), out.begin(), std::minus<T> {});
255 template <
typename T>
260 std::transform(v.
begin(), v.
end(), out.begin(),
261 [&scalar](
const T&
element) { return scalar * element; });
266 template <
typename T>
274 template <
typename T>
293 template <
typename T>
301 for (std::size_t i {0}; i < a.
size(); ++i) {
304 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 argument is outside what an operation takes (a tolerance below 0, an FFT type past 4).
argument_error(const std::string &message)
Builds the error.
A standard exception Std that numerical::error tags too, its one what answering for both bases.
const char * what() const noexcept override
The message.
Thrown when an operation's operands have incompatible shapes.
dimension_error(const std::string &message)
Builds the error.
What every exception NumericAL throws is, beside its standard base (all but std::bad_alloc and std::s...
virtual const char * what() const noexcept=0
The message, as std::exception::what gives it.
Thrown when an index or a range leaves its axis.
index_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).
constexpr bool range_within(std::size_t first, std::size_t count, std::ptrdiff_t step, std::size_t extent) noexcept
Whether count indices from first, step apart, all lie in [0, extent): none is out for a count of 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).