SmallVector< numberOfRows > Class Template Reference

#include <SmallVector.h>

Public Member Functions

 SmallVector ()
 
 SmallVector (const SmallVector &other)
 
 SmallVector (SmallVector &&other)
 
 SmallVector (const Mdouble array[])
 
 SmallVector (std::initializer_list< Mdouble > data)
 
SmallVectoroperator= (const SmallVector &right)
 
SmallVectoroperator= (const std::array< Mdouble, numberOfRows > l)
 
SmallVector operator+ (const SmallVector &right) const
 
SmallVector operator- (const SmallVector &right) const
 
SmallVector operator* (const Mdouble &right) const
 
Mdouble operator* (const SmallVector &right) const
 Computes inner product between two vectors. More...
 
SmallVectoroperator/= (const Mdouble &right)
 
SmallVector operator/ (const Mdouble &right) const
 
void axpy (Mdouble a, const SmallVector &x)
 
bool operator== (const SmallVector &right) const
 
bool operator< (const SmallVector &right) const
 
SmallVectoroperator+= (const SmallVector &right)
 
SmallVectoroperator-= (const SmallVector &right)
 
SmallVectoroperator*= (const double &right)
 
Mdoubleoperator[] (unsigned int n)
 
const Mdoubleoperator[] (unsigned int n) const
 
Mdoubleoperator() (unsigned int n)
 
const Mdoubleoperator() (unsigned int n) const
 
unsigned int size () const
 
const Mdoubledata () const
 
Mdoubledata ()
 
SmallVector operator- () const
 
Mdouble length () const
 
SmallVector< numberOfRows > getNormalised () const
 

Private Attributes

std::array< Mdouble, numberOfRows > data_
 

Detailed Description

template<unsigned int numberOfRows>
class SmallVector< numberOfRows >

Implementation of a 3D vector (by Vitaliy). Modifications 21:9:2009 - Added the inclusion guards and some include objects

Todo:
Need to generalize this to n-dimensional vectors of any type

Constructor & Destructor Documentation

◆ SmallVector() [1/5]

template<unsigned int numberOfRows>
SmallVector< numberOfRows >::SmallVector ( )
inline
67  : data_()
68  {
69  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270

◆ SmallVector() [2/5]

template<unsigned int numberOfRows>
SmallVector< numberOfRows >::SmallVector ( const SmallVector< numberOfRows > &  other)
inline
72  : data_(other.data_)
73  {
74  }

◆ SmallVector() [3/5]

template<unsigned int numberOfRows>
SmallVector< numberOfRows >::SmallVector ( SmallVector< numberOfRows > &&  other)
inline
77  : data_(std::move(other.data_))
78  {
79  }

◆ SmallVector() [4/5]

template<unsigned int numberOfRows>
SmallVector< numberOfRows >::SmallVector ( const Mdouble  array[])
inline
82  : data_()
83  {
84  std::copy(array, array + numberOfRows, data_.begin());
85  }

References SmallVector< numberOfRows >::data_.

◆ SmallVector() [5/5]

template<unsigned int numberOfRows>
SmallVector< numberOfRows >::SmallVector ( std::initializer_list< Mdouble data)
inline
88  : data_()
89  {
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());
93  }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
const Mdouble * data() const
Definition: SmallVector.h:238

References SmallVector< numberOfRows >::data(), SmallVector< numberOfRows >::data_, and logger.

Member Function Documentation

◆ axpy()

template<unsigned int numberOfRows>
void SmallVector< numberOfRows >::axpy ( Mdouble  a,
const SmallVector< numberOfRows > &  x 
)
inline
151  {
152  for (unsigned int i = 0; i < numberOfRows; ++i)
153  {
154  data_[i] += a * x[i];
155  }
156  }
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51

References SmallVector< numberOfRows >::data_, and constants::i.

Referenced by main().

◆ data() [1/2]

template<unsigned int numberOfRows>
Mdouble* SmallVector< numberOfRows >::data ( )
inline
244  {
245  return data_.data();
246  }

References SmallVector< numberOfRows >::data_.

◆ data() [2/2]

◆ getNormalised()

template<unsigned int numberOfRows>
SmallVector<numberOfRows> SmallVector< numberOfRows >::getNormalised ( ) const
inline
265  {
266  return (*this) / length();
267  }
Mdouble length() const
Definition: SmallVector.h:253

References SmallVector< numberOfRows >::length().

◆ length()

template<unsigned int numberOfRows>
Mdouble SmallVector< numberOfRows >::length ( ) const
inline
254  {
255  Mdouble sum = 0;
256  for (Mdouble x : data_)
257  {
258  sum += x * x;
259  logger(DEBUG, "x: %, sum: %", x, sum);
260  }
261  return std::sqrt(sum);
262  }
double Mdouble
Definition: GeneralDefine.h:34
@ DEBUG

References SmallVector< numberOfRows >::data_, DEBUG, and logger.

Referenced by SuperQuadricParticle::getCurvature(), and SmallVector< numberOfRows >::getNormalised().

◆ operator()() [1/2]

template<unsigned int numberOfRows>
Mdouble& SmallVector< numberOfRows >::operator() ( unsigned int  n)
inline
222  {
223  logger.assert_debug(n < numberOfRows, "Requested entry %, but there are only % entries", n, numberOfRows);
224  return data_[n];
225  }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32

References SmallVector< numberOfRows >::data_, logger, and n.

◆ operator()() [2/2]

template<unsigned int numberOfRows>
const Mdouble& SmallVector< numberOfRows >::operator() ( unsigned int  n) const
inline
228  {
229  logger.assert_debug(n < numberOfRows, "Requested entry %, but there are only % entries", n, numberOfRows);
230  return data_[n];
231  }

References SmallVector< numberOfRows >::data_, logger, and n.

◆ operator*() [1/2]

template<unsigned int numberOfRows>
SmallVector SmallVector< numberOfRows >::operator* ( const Mdouble right) const
inline
122  {
123  SmallVector result;
124  std::transform(data_.begin(), data_.end(), result.data_.begin(), std::bind(std::multiplies<Mdouble>(),
125  std::placeholders::_1, right));
126  return result;
127  }
Definition: SmallVector.h:62

References SmallVector< numberOfRows >::data_.

◆ operator*() [2/2]

template<unsigned int numberOfRows>
Mdouble SmallVector< numberOfRows >::operator* ( const SmallVector< numberOfRows > &  right) const
inline

Computes inner product between two vectors.

131  {
132  return std::inner_product(right.data_.begin(), right.data_.end(), data_.begin(), 0.0);
133  }

References SmallVector< numberOfRows >::data_.

◆ operator*=()

template<unsigned int numberOfRows>
SmallVector& SmallVector< numberOfRows >::operator*= ( const double right)
inline
203  {
204  std::transform(data_.begin(), data_.end(), data_.begin(), std::bind(std::multiplies<Mdouble>(),
205  std::placeholders::_1, right));
206  return *this;
207  }

References SmallVector< numberOfRows >::data_.

◆ operator+()

template<unsigned int numberOfRows>
SmallVector SmallVector< numberOfRows >::operator+ ( const SmallVector< numberOfRows > &  right) const
inline
108  {
109  SmallVector result;
110  std::transform(data_.begin(), data_.end(), right.data_.begin(), result.data_.begin(), std::plus<Mdouble>());
111  return result;
112  }

References SmallVector< numberOfRows >::data_.

◆ operator+=()

template<unsigned int numberOfRows>
SmallVector& SmallVector< numberOfRows >::operator+= ( const SmallVector< numberOfRows > &  right)
inline
191  {
192  std::transform(data_.begin(), data_.end(), right.data_.begin(), data_.begin(), std::plus<Mdouble>());
193  return *this;
194  }

References SmallVector< numberOfRows >::data_.

◆ operator-() [1/2]

template<unsigned int numberOfRows>
SmallVector SmallVector< numberOfRows >::operator- ( ) const
inline
249  {
250  return *this * -1.0;
251  }

◆ operator-() [2/2]

template<unsigned int numberOfRows>
SmallVector SmallVector< numberOfRows >::operator- ( const SmallVector< numberOfRows > &  right) const
inline
115  {
116  SmallVector result;
117  std::transform(data_.begin(), data_.end(), right.data_.begin(), result.data_.begin(), std::minus<Mdouble>());
118  return result;
119  }

References SmallVector< numberOfRows >::data_.

◆ operator-=()

template<unsigned int numberOfRows>
SmallVector& SmallVector< numberOfRows >::operator-= ( const SmallVector< numberOfRows > &  right)
inline
197  {
198  std::transform(data_.begin(), data_.end(), right.data_.begin(), data_.begin(), std::minus<Mdouble>());
199  return *this;
200  }

References SmallVector< numberOfRows >::data_.

◆ operator/()

template<unsigned int numberOfRows>
SmallVector SmallVector< numberOfRows >::operator/ ( const Mdouble right) const
inline
143  {
144  SmallVector result;
145  std::transform(data_.begin(), data_.end(), result.data_.begin(), std::bind(std::divides<Mdouble>(),
146  std::placeholders::_1, right));
147  return result;
148  }

References SmallVector< numberOfRows >::data_.

◆ operator/=()

template<unsigned int numberOfRows>
SmallVector& SmallVector< numberOfRows >::operator/= ( const Mdouble right)
inline
136  {
137  std::transform(data_.begin(), data_.end(), data_.begin(), std::bind(std::divides<Mdouble>(),
138  std::placeholders::_1, right));
139  return *this;
140  }

References SmallVector< numberOfRows >::data_.

◆ operator<()

template<unsigned int numberOfRows>
bool SmallVector< numberOfRows >::operator< ( const SmallVector< numberOfRows > &  right) const
inline

This function is dangerous to use, since it compares doubles without a tolerance interval to see if they are equal.

175  {
176  for (unsigned int i = 0; i < numberOfRows; ++i)
177  {
178  if (data_[i] < right[i])
179  {
180  return true;
181  }
182  if (data_[i] > right[i])
183  {
184  return false;
185  }
186  }
187  return false;
188  }

References SmallVector< numberOfRows >::data_, and constants::i.

◆ operator=() [1/2]

template<unsigned int numberOfRows>
SmallVector& SmallVector< numberOfRows >::operator= ( const SmallVector< numberOfRows > &  right)
inline
96  {
97  std::copy(right.data_.begin(), right.data_.end(), data_.begin());
98  return *this;
99  }

References SmallVector< numberOfRows >::data_.

◆ operator=() [2/2]

template<unsigned int numberOfRows>
SmallVector& SmallVector< numberOfRows >::operator= ( const std::array< Mdouble, numberOfRows >  l)
inline
102  {
103  std::copy(l.begin(), l.end(), data_.begin());
104  return *this;
105  }

References SmallVector< numberOfRows >::data_.

◆ operator==()

template<unsigned int numberOfRows>
bool SmallVector< numberOfRows >::operator== ( const SmallVector< numberOfRows > &  right) const
inline

This function is dangerous to use, since it compares doubles without a tolerance interval to see if they are equal.

161  {
162  for (unsigned int i = 0; i < numberOfRows; ++i)
163  {
164  if (data_[i] != right[i])
165  {
166  return false;
167  }
168  }
169  return true;
170  }

References SmallVector< numberOfRows >::data_, and constants::i.

◆ operator[]() [1/2]

template<unsigned int numberOfRows>
Mdouble& SmallVector< numberOfRows >::operator[] ( unsigned int  n)
inline
210  {
211  logger.assert_debug(n < numberOfRows, "Requested entry %, but there are only % entries", n, numberOfRows);
212  return data_[n];
213  }

References SmallVector< numberOfRows >::data_, logger, and n.

◆ operator[]() [2/2]

template<unsigned int numberOfRows>
const Mdouble& SmallVector< numberOfRows >::operator[] ( unsigned int  n) const
inline
216  {
217  logger.assert_debug(n < numberOfRows, "Requested entry %, but there are only % entries", n, numberOfRows);
218  return data_[n];
219  }

References SmallVector< numberOfRows >::data_, logger, and n.

◆ size()

template<unsigned int numberOfRows>
unsigned int SmallVector< numberOfRows >::size ( ) const
inline
234  {
235  return numberOfRows;
236  }

Referenced by main(), SmallMatrix< numberOfRows, numberOfColumns >::operator*(), and operator*().

Member Data Documentation

◆ data_


The documentation for this class was generated from the following file: