MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin_VecOps.h
Go to the documentation of this file.
1// ========================================================================================================
2// _______ _______ ______ ___ ___ _______ _______
3// | | | _ | __ \ | |_ _| | |
4// | | | < | |_| |_| |
5// |__|_|__|___|___|___|__|\_____/|_______|__|____|
6//
7// This file is part of the Marvin open source library and is licensed under the terms of the MIT License.
8//
9// ========================================================================================================
10#ifndef MARVIN_SIMDOPS_H
11#define MARVIN_SIMDOPS_H
13#include <marvin/library/marvin_Literals.h>
14#include <type_traits>
15#include <cstring>
16#include <cassert>
18
26 template <FloatType T>
27 void add(T* lhs, const T* rhs, size_t size) noexcept;
35 template <FloatType T>
36 void add(T* arr, T scalar, size_t size) noexcept;
43 template <FloatArrayLike T>
44 void add(T& lhs, T& rhs) noexcept {
45 assert(lhs.size() == rhs.size());
46 add(lhs.data(), rhs.data(), lhs.size());
47 }
48
55 template <FloatArrayLike T>
56 void add(T& arr, typename T::value_type scalar) noexcept {
57 add(arr.data(), scalar, arr.size());
58 }
59
67 template <FloatType T>
68 void subtract(T* lhs, const T* rhs, size_t size) noexcept;
76 template <FloatType T>
77 void subtract(T* arr, T scalar, size_t size) noexcept;
78
85 template <FloatArrayLike T>
86 requires std::is_floating_point_v<typename T::value_type>
87 void subtract(T& lhs, const T& rhs) noexcept {
88 assert(lhs.size() == rhs.size());
89 subtract(lhs.data(), rhs.data(), lhs.size());
90 }
91
98 template <FloatArrayLike T>
99 void subtract(T& arr, typename T::value_type scalar) noexcept {
100 subtract(arr.data(), scalar, arr.size());
101 }
102
110 template <FloatType T>
111 void multiply(T* lhs, const T* rhs, size_t size) noexcept;
112
120 template <FloatType T>
121 void multiply(T* arr, T scalar, size_t size) noexcept;
122
129 template <FloatArrayLike T>
130 void multiply(T& lhs, const T& rhs) noexcept {
131 assert(lhs.size() == rhs.size());
132 multiply(lhs.data(), rhs.data(), lhs.size());
133 }
134
141 template <FloatArrayLike T>
142 void multiply(T& arr, typename T::value_type scalar) noexcept {
143 multiply(arr.data(), scalar, arr.size());
144 }
145
153 template <FloatType T>
154 void divide(T* lhs, const T* rhs, size_t size) noexcept;
155
163 template <FloatType T>
164 void divide(T* arr, T scalar, size_t size) noexcept;
165
172 template <FloatArrayLike T>
173 void divide(T& lhs, const T& rhs) noexcept {
174 assert(lhs.size() == rhs.size());
175 divide(lhs.data(), rhs.data(), lhs.size());
176 }
177
184 template <FloatArrayLike T>
185 void divide(T& arr, typename T::value_type scalar) noexcept {
186 divide(arr.data(), scalar, arr.size());
187 }
188
195 template <NumericType T>
196 void copy(T* lhs, const T* rhs, size_t size) noexcept {
197 std::memcpy(lhs, rhs, sizeof(T) * size);
198 }
199
200
207 template <ArrayLike T>
208 void copy(T& lhs, const T& rhs) noexcept {
209 assert(lhs.size() == rhs.size());
210 copy(lhs.data(), rhs.data(), lhs.size());
211 }
212} // namespace marvin::math::vecops
213#endif
Collection of basic arithmetic operations on vectors, SIMD accelerated where possible.
Definition marvin_VecOps.h:17
void multiply(T *lhs, const T *rhs, size_t size) noexcept
void subtract(T *lhs, const T *rhs, size_t size) noexcept
void copy(T *lhs, const T *rhs, size_t size) noexcept
Definition marvin_VecOps.h:196
void add(T *lhs, const T *rhs, size_t size) noexcept
void divide(T *lhs, const T *rhs, size_t size) noexcept