BioDynaMo
v1.05.120-25dc9790
|
Go to the documentation of this file.
15 #ifndef CORE_CONTAINER_MATH_ARRAY_H_
16 #define CORE_CONTAINER_MATH_ARRAY_H_
35 template <
class T, std::
size_t N>
41 for (
size_t i = 0; i < N; i++) {
50 assert(l.size() <= N);
52 for (uint64_t i = 0; i < N; i++) {
55 for (uint64_t i = l.size(); i < N; i++) {
66 inline const size_t size()
const {
return N; }
70 inline const bool empty()
const {
return N == 0; }
88 T&
at(
size_t idx) noexcept(
false) {
89 if (idx >
size() || idx < 0) {
90 throw std::out_of_range(
"The index is out of range");
110 auto tmp = this->
end();
119 if (
this != &other) {
120 assert(other.
size() == N);
130 if (other.
size() != N) {
133 for (
size_t i = 0; i < N; i++) {
134 if (other[i] !=
data_[i]) {
145 for (
size_t i = 0; i < N; i++) {
159 for (
size_t i = 0; i < N; i++) {
172 assert(N == rhs.
size());
174 for (
size_t i = 0; i < N; i++) {
184 for (
size_t i = 0; i < N; i++) {
185 tmp[i] =
data_[i] + rhs[i];
194 for (
size_t i = 0; i < N; i++) {
195 tmp[i] =
data_[i] + rhs[i];
202 for (
size_t i = 0; i < N; i++) {
211 for (
size_t i = 0; i < N; i++) {
212 tmp[i] =
data_[i] + rhs;
220 for (
size_t i = 0; i < N; i++) {
230 for (
size_t i = 0; i < N; i++) {
231 tmp[i] =
data_[i] - rhs[i];
240 for (
size_t i = 0; i < N; i++) {
241 tmp[i] =
data_[i] - rhs[i];
248 for (
size_t i = 0; i < N; i++) {
257 for (
size_t i = 0; i < N; i++) {
258 tmp[i] =
data_[i] - rhs;
269 for (
size_t i = 0; i < N; i++) {
270 result +=
data_[i] * rhs[i];
279 for (
size_t i = 0; i < N; i++) {
280 result +=
data_[i] * rhs[i];
287 for (
size_t i = 0; i < N; i++) {
296 for (
size_t i = 0; i < N; i++) {
297 tmp[i] =
data_[i] * k;
305 for (
size_t i = 0; i < N; i++) {
306 tmp[i] =
data_[i] * k;
313 for (
size_t i = 0; i < N; i++) {
322 for (
size_t i = 0; i < N; i++) {
323 tmp[i] =
data_[i] / k;
332 std::fill(std::begin(
data_), std::end(
data_), k);
342 for (
size_t i = 0; i < N; i++) {
355 for (
size_t i = 0; i < N; i++) {
358 result = std::sqrt(result);
376 "You tried to normalize a zero vector. "
377 "This cannot be done. Exiting.");
380 for (
size_t i = 0; i < N; i++) {
389 return normalized_array;
397 assert(rhs.
size() == N);
400 for (
size_t i = 0; i < N; ++i) {
401 tmp[i] =
data_[i] * rhs[i];
411 template <
class T, std::
size_t N>
413 for (
size_t i = 0; i < N; i++) {
428 template <
class T, std::
size_t N>
430 return array *= scalar;
445 #endif // CORE_CONTAINER_MATH_ARRAY_H_
const T & operator[](size_t idx) const
const MathArray operator+(const MathArray &rhs) const
MathArray operator/(const T &k)
const MathArray operator*(const T &k) const
MathArray & operator=(const MathArray &other)
MathArray & operator-=(const T &rhs)
MathArray & operator*=(const T &k)
MathArray< T, N > operator*(T const &scalar, MathArray< T, N > array)
Template function to multiply array with scalar from the left.
MathArray operator+(const MathArray &rhs)
const T operator*(const MathArray &rhs) const
bool operator==(const MathArray &other) const
MathArray & fill(const T &k)
MathArray & operator+=(const T &rhs)
MathArray & operator-=(const MathArray &rhs)
MathArray & operator/=(const T &k)
MathArray operator++(int)
bool operator!=(const MathArray &other) const
MathArray operator-(const MathArray &rhs)
T & operator[](size_t idx)
MathArray operator*(const T &k)
BDM_CLASS_DEF_NV(MathArray, 1)
static void Fatal(const std::string &location, const Args &... parts)
Prints fatal error message.
constexpr MathArray(std::initializer_list< T > l)
std::ostream & operator<<(std::ostream &o, const MathArray< T, N > &arr)
MathArray operator--(int)
MathArray()
Default constructor.
MathArray operator+(const T &rhs)
bool IsZero() const
Checks if vector is a zero vector, e.g. if all entries are zero.
MathArray EntryWiseProduct(const MathArray &rhs) const
const size_t size() const
MathArray operator-(const T &rhs)
MathArray & operator+=(const MathArray &rhs)
const MathArray operator-(const MathArray &rhs) const
T & at(size_t idx) noexcept(false)
void Normalize()
Normalize the array in-place.
MathArray GetNormalizedArray() const
Get a nomalized copy of the MathArray.
T & operator*=(const MathArray &rhs)=delete
T operator*(const MathArray &rhs)