34 #include "../WAssert.h"
35 #include "../WStringUtils.h"
42 template<
typename S >
friend class WValue;
46 template<
typename U >
friend std::ostream& operator<<( std::ostream& os,
const WValue< U > &rhs );
47 template<
typename U >
friend std::istream& operator>>( std::istream& in,
WValue< U >& rhs );
55 explicit WValue(
size_t nbComponents )
86 explicit WValue(
const Eigen::VectorXd& newValues )
96 explicit WValue(
const Eigen::VectorXf& newValues )
106 explicit WValue(
const Eigen::VectorXi& newValues )
129 WAssert( i <
m_components.size(),
"Index out of bounds." );
141 WAssert( i <
m_components.size(),
"Index out of bounds." );
263 result -= subtrahend;
319 double currentNorm =
norm();
322 WAssert( currentNorm > 0.0,
"Norm is non-positive!" );
344 WAssert( !
m_components.empty(),
"WValue has no entries." );
350 return ( sum /
static_cast< T
>(
m_components.size() ) );
359 WAssert( !
m_components.empty(),
"WValue has no entries. " );
361 std::sort( components.begin(), components.end() );
362 return components[ components.size() / 2 ];
381 template<
typename EigenDataType >
443 template<
typename U >
inline std::ostream& operator<<( std::ostream& os,
const WValue< U > &rhs )
456 template<
typename U >
inline std::istream& operator>>( std::istream& in,
WValue< U >& rhs )
Base class for all higher level values like tensors, vectors, matrices and so on.
WValue normalized() const
Return a normalized version of the current WValue without modifying it.
bool operator!=(const WValue &rhs) const
Compares two WValues and returns true if they contain the different data.
WValue & operator/=(const double rhs)
Scales each component of this WValue with the given scalar argument.
void resize(size_t size)
Changes the number of scalars held by this WValue.
WValue & operator*=(const WValue &rhs)
Scales each component of this WValue with the corresponding component of the given argument WValue.
WValue(const Eigen::VectorXf &newValues)
Create a WValue from the given Eigen::VectorXf.
WValue(const WValue &newValue)
Create a WValue as copy of the one given as parameter.
size_t size() const
Get number of components the value consists of.
const WValue operator-(const WValue &subtrahend) const
Component-wise subtraction.
WValue(const WValue< S > &newValue)
Create a WValue as copy of the one given as parameter but with another template type.
bool operator==(const WValue &rhs) const
Compares two WValues and returns true if they contain the same data.
const WValue operator+(const WValue &summand2) const
Component-wise addition.
WValue(const Eigen::VectorXd &newValues)
Create a WValue from the given Eigen::VectorXd.
WValue & operator+=(const WValue &rhs)
Adds a the argument component-wise to the components of this WValue.
WValue & operator-=(const WValue &rhs)
Subtracts the argument component-wise from the components of this WValue.
const WValue operator*(const WValue &factor2) const
Component-wise multiplication.
double norm() const
Square root of sum of squares of elements.
WValue & operator=(const WValue &rhs)
Assigns the contents of its argument to the contents of this WValue.
T median() const
Returns the median of all values stored in this WValue.
T mean() const
Returns the mean value of all values stored in this WValue.
void copyFromEigenVector(const Eigen::Matrix< EigenDataType, Eigen::Dynamic, 1 > &newValues)
This function is used by the constructors that have the different Eigen::MatrixX types as parameter.
std::vector< T > m_components
The components the value is composed of.
void normalize()
Make the norm of this WValue be 1 by dividing by WValue::norm()
WValue(const Eigen::VectorXi &newValues)
Create a WValue from the given Eigen::VectorXi.
WValue & operator*=(double rhs)
Scales each component of this WValue with the given scalar argument.
double normSquare() const
Sum of squares of elements.
T & operator[](size_t i)
Returns a reference to the i-th component in order to provide access to the component.
const T & operator[](size_t i) const
Returns a CONST reference to the i-th component in order to provide read-only access to the component...
WValue(size_t nbComponents)
Create a WValue with the given number of components.
std::ostream & operator<<(std::ostream &os, const std::vector< T > &v)
Writes every vector to an output stream such as cout, if its elements have an output operator defined...
std::istream & operator>>(std::istream &in, std::vector< T > &v)
Write an input stream into the given vector.