50 #ifndef MERCURY_SMALLVECTOR_H
51 #define MERCURY_SMALLVECTOR_H
60 template<
unsigned int numberOfRows>
84 std::copy(array, array + numberOfRows,
data_.begin());
90 logger.assert_debug(data.size() == numberOfRows,
"provided array has size %, but should have size %",
91 data.size(), numberOfRows);
92 std::copy(data.begin(), data.end(),
data_.begin());
103 std::copy(l.begin(), l.end(),
data_.begin());
110 std::transform(
data_.begin(),
data_.end(), right.
data_.begin(), result.
data_.begin(), std::plus<Mdouble>());
117 std::transform(
data_.begin(),
data_.end(), right.
data_.begin(), result.
data_.begin(), std::minus<Mdouble>());
124 std::transform(
data_.begin(),
data_.end(), result.
data_.begin(), std::bind(std::multiplies<Mdouble>(),
125 std::placeholders::_1, right));
132 return std::inner_product(right.
data_.begin(), right.
data_.end(),
data_.begin(), 0.0);
137 std::transform(
data_.begin(),
data_.end(),
data_.begin(), std::bind(std::divides<Mdouble>(),
138 std::placeholders::_1, right));
145 std::transform(
data_.begin(),
data_.end(), result.
data_.begin(), std::bind(std::divides<Mdouble>(),
146 std::placeholders::_1, right));
152 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
162 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
176 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
182 if (
data_[i] > right[i])
192 std::transform(
data_.begin(),
data_.end(), right.
data_.begin(),
data_.begin(), std::plus<Mdouble>());
198 std::transform(
data_.begin(),
data_.end(), right.
data_.begin(),
data_.begin(), std::minus<Mdouble>());
204 std::transform(
data_.begin(),
data_.end(),
data_.begin(), std::bind(std::multiplies<Mdouble>(),
205 std::placeholders::_1, right));
211 logger.assert_debug(n < numberOfRows,
"Requested entry %, but there are only % entries", n, numberOfRows);
217 logger.assert_debug(n < numberOfRows,
"Requested entry %, but there are only % entries", n, numberOfRows);
223 logger.assert_debug(n < numberOfRows,
"Requested entry %, but there are only % entries", n, numberOfRows);
229 logger.assert_debug(n < numberOfRows,
"Requested entry %, but there are only % entries", n, numberOfRows);
261 return std::sqrt(sum);
266 return (*
this) /
length();
270 std::array<Mdouble, numberOfRows>
data_;
274 template<
unsigned int numberOfRows>
280 template<
unsigned int numberOfRows>
281 std::ostream& operator<<(std::ostream& os, const SmallVector<numberOfRows>&
A)
284 for (std::size_t
i = 0;
i < numberOfRows; ++
i)
292 #endif //MERCURY_SMALLVECTOR_H
SmallVector & operator=(const SmallVector &right)
SmallVector operator-() const
std::array< Mdouble, numberOfRows > data_
SmallVector operator-(const SmallVector &right) const
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
const Mdouble & operator()(unsigned int n) const
SmallVector & operator*=(const double &right)
SmallVector< numberOfRows > operator*(const Mdouble &left, const SmallVector< numberOfRows > &right)
const std::complex< Mdouble > i
Implementation of a 3D vector (by Vitaliy).
SmallVector(SmallVector &&other)
SmallVector & operator/=(const Mdouble &right)
Mdouble & operator[](unsigned int n)
const Mdouble & operator[](unsigned int n) const
SmallVector & operator-=(const SmallVector &right)
SmallVector operator/(const Mdouble &right) const
const Mdouble * data() const
SmallVector & operator+=(const SmallVector &right)
SmallVector< numberOfRows > getNormalised() const
SmallVector(const Mdouble array[])
SmallVector & operator=(const std::array< Mdouble, numberOfRows > l)
bool operator==(const SmallVector &right) const
This function is dangerous to use, since it compares doubles without a tolerance interval to see if t...
SmallVector(const SmallVector &other)
SmallVector operator*(const Mdouble &right) const
Mdouble & operator()(unsigned int n)
bool operator<(const SmallVector &right) const
This function is dangerous to use, since it compares doubles without a tolerance interval to see if t...
unsigned int size() const
void axpy(Mdouble a, const SmallVector &x)
SmallVector(std::initializer_list< Mdouble > data)
Mdouble operator*(const SmallVector &right) const
Computes inner product between two vectors.
SmallVector operator+(const SmallVector &right) const