MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SmallVector< numberOfRows > Class Template Reference

Implementation of a 3D vector (by Vitaliy). More...

#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
 This function is dangerous to use, since it compares doubles without a tolerance interval to see if they are equal. More...
 
bool operator< (const SmallVector &right) const
 This function is dangerous to use, since it compares doubles without a tolerance interval to see if they are equal. More...
 
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

Definition at line 61 of file SmallVector.h.

Constructor & Destructor Documentation

template<unsigned int numberOfRows>
SmallVector< numberOfRows >::SmallVector ( )
inline

Definition at line 66 of file SmallVector.h.

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

Definition at line 71 of file SmallVector.h.

72  : data_(other.data_)
73  {
74  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
template<unsigned int numberOfRows>
SmallVector< numberOfRows >::SmallVector ( SmallVector< numberOfRows > &&  other)
inline

Definition at line 76 of file SmallVector.h.

77  : data_(std::move(other.data_))
78  {
79  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
template<unsigned int numberOfRows>
SmallVector< numberOfRows >::SmallVector ( const Mdouble  array[])
inline

Definition at line 81 of file SmallVector.h.

References SmallVector< numberOfRows >::data_.

82  : data_()
83  {
84  std::copy(array, array + numberOfRows, data_.begin());
85  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
template<unsigned int numberOfRows>
SmallVector< numberOfRows >::SmallVector ( std::initializer_list< Mdouble data)
inline

Definition at line 87 of file SmallVector.h.

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

88  : data_()
89  {
90  logger.assert(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  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
const Mdouble * data() const
Definition: SmallVector.h:238

Member Function Documentation

template<unsigned int numberOfRows>
void SmallVector< numberOfRows >::axpy ( Mdouble  a,
const SmallVector< numberOfRows > &  x 
)
inline

Definition at line 150 of file SmallVector.h.

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

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

Definition at line 243 of file SmallVector.h.

References SmallVector< numberOfRows >::data_.

244  {
245  return data_.data();
246  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
template<unsigned int numberOfRows>
SmallVector<numberOfRows> SmallVector< numberOfRows >::getNormalised ( ) const
inline

Definition at line 264 of file SmallVector.h.

References SmallVector< numberOfRows >::length().

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

Definition at line 253 of file SmallVector.h.

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

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

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  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
template<unsigned int numberOfRows>
Mdouble& SmallVector< numberOfRows >::operator() ( unsigned int  n)
inline

Definition at line 221 of file SmallVector.h.

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

222  {
223  logger.assert(n < numberOfRows, "Requested entry %, but there are only % entries", n, numberOfRows);
224  return data_[n];
225  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
template<unsigned int numberOfRows>
const Mdouble& SmallVector< numberOfRows >::operator() ( unsigned int  n) const
inline

Definition at line 227 of file SmallVector.h.

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

228  {
229  logger.assert(n < numberOfRows, "Requested entry %, but there are only % entries", n, numberOfRows);
230  return data_[n];
231  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
template<unsigned int numberOfRows>
SmallVector SmallVector< numberOfRows >::operator* ( const Mdouble right) const
inline

Definition at line 121 of file SmallVector.h.

References SmallVector< numberOfRows >::data_.

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  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
Implementation of a 3D vector (by Vitaliy).
Definition: SmallVector.h:61
template<unsigned int numberOfRows>
Mdouble SmallVector< numberOfRows >::operator* ( const SmallVector< numberOfRows > &  right) const
inline

Computes inner product between two vectors.

Definition at line 130 of file SmallVector.h.

References SmallVector< numberOfRows >::data_.

131  {
132  return std::inner_product(right.data_.begin(), right.data_.end(), data_.begin(), 0.0);
133  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
template<unsigned int numberOfRows>
SmallVector& SmallVector< numberOfRows >::operator*= ( const double &  right)
inline

Definition at line 202 of file SmallVector.h.

References SmallVector< numberOfRows >::data_.

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

Definition at line 107 of file SmallVector.h.

References SmallVector< numberOfRows >::data_.

108  {
109  SmallVector result;
110  std::transform(data_.begin(), data_.end(), right.data_.begin(), result.data_.begin(), std::plus<Mdouble>());
111  return result;
112  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
Implementation of a 3D vector (by Vitaliy).
Definition: SmallVector.h:61
template<unsigned int numberOfRows>
SmallVector& SmallVector< numberOfRows >::operator+= ( const SmallVector< numberOfRows > &  right)
inline

Definition at line 190 of file SmallVector.h.

References SmallVector< numberOfRows >::data_.

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

Definition at line 114 of file SmallVector.h.

References SmallVector< numberOfRows >::data_.

115  {
116  SmallVector result;
117  std::transform(data_.begin(), data_.end(), right.data_.begin(), result.data_.begin(), std::minus<Mdouble>());
118  return result;
119  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
Implementation of a 3D vector (by Vitaliy).
Definition: SmallVector.h:61
template<unsigned int numberOfRows>
SmallVector SmallVector< numberOfRows >::operator- ( ) const
inline

Definition at line 248 of file SmallVector.h.

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

Definition at line 196 of file SmallVector.h.

References SmallVector< numberOfRows >::data_.

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

Definition at line 142 of file SmallVector.h.

References SmallVector< numberOfRows >::data_.

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  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
Implementation of a 3D vector (by Vitaliy).
Definition: SmallVector.h:61
template<unsigned int numberOfRows>
SmallVector& SmallVector< numberOfRows >::operator/= ( const Mdouble right)
inline

Definition at line 135 of file SmallVector.h.

References SmallVector< numberOfRows >::data_.

136  {
137  std::transform(data_.begin(), data_.end(), data_.begin(), std::bind(std::divides<Mdouble>(),
138  std::placeholders::_1, right));
139  return *this;
140  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
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.

Definition at line 174 of file SmallVector.h.

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

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  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
template<unsigned int numberOfRows>
SmallVector& SmallVector< numberOfRows >::operator= ( const SmallVector< numberOfRows > &  right)
inline

Definition at line 95 of file SmallVector.h.

References SmallVector< numberOfRows >::data_.

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

Definition at line 101 of file SmallVector.h.

References SmallVector< numberOfRows >::data_.

102  {
103  std::copy(l.begin(), l.end(), data_.begin());
104  return *this;
105  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
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.

Definition at line 160 of file SmallVector.h.

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

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  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
template<unsigned int numberOfRows>
Mdouble& SmallVector< numberOfRows >::operator[] ( unsigned int  n)
inline

Definition at line 209 of file SmallVector.h.

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

210  {
211  logger.assert(n < numberOfRows, "Requested entry %, but there are only % entries", n, numberOfRows);
212  return data_[n];
213  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
template<unsigned int numberOfRows>
const Mdouble& SmallVector< numberOfRows >::operator[] ( unsigned int  n) const
inline

Definition at line 215 of file SmallVector.h.

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

216  {
217  logger.assert(n < numberOfRows, "Requested entry %, but there are only % entries", n, numberOfRows);
218  return data_[n];
219  }
std::array< Mdouble, numberOfRows > data_
Definition: SmallVector.h:270
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
template<unsigned int numberOfRows>
unsigned int SmallVector< numberOfRows >::size ( ) const
inline

Definition at line 233 of file SmallVector.h.

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

234  {
235  return numberOfRows;
236  }

Member Data Documentation


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