36 #include <boost/shared_ptr.hpp>
39 #include "../exceptions/WOutOfBounds.h"
47 template<
typename T >
60 typedef boost::shared_ptr< WMatrixSym < T > >
SPtr;
115 const std::vector< T >&
getData()
const;
144 template<
typename T >
146 : m_data( ( n * ( n - 1 ) ) / 2, 0.0 ),
151 template<
typename T >
157 template<
typename T >
160 if( i == j || i >= m_n || j >= m_n )
162 std::stringstream ss;
163 ss <<
"Invalid Element Access ( " << i <<
", " << j <<
" ). No diagonal elements or indices bigger than " << m_n <<
" are allowed.";
170 return m_data[( i * m_n + j - ( i + 1 ) * ( i + 2 ) / 2 )];
174 template<
typename T >
177 if( i == j || i >= m_n || j >= m_n )
179 std::stringstream ss;
180 ss <<
"Invalid Element Access ( " << i <<
", " << j <<
" ). No diagonal elements or indices bigger than " << m_n <<
" are allowed.";
187 return m_data[( i * m_n + j - ( i + 1 ) * ( i + 2 ) / 2 )];
191 template<
typename T >
194 std::stringstream ss;
195 ss << std::setprecision( 9 ) << std::fixed;
209 template<
typename T >
212 std::vector< T > l = lhs.
getData();
213 std::vector< T > r = rhs.
getData();
226 template<
typename T >
227 inline std::ostream& operator<<( std::ostream& os, const WMatrixSym< T >& m )
230 for(
size_t i = 0; i < n; ++i )
232 for(
size_t j = 0; j < n; ++j )
268 template<
typename T >
269 inline std::istream& operator>>( std::istream& is,
WMatrixSym< T >& m )
271 std::vector< T > elements;
275 elements.push_back( elm );
277 if( m.
size() * m.
size() != elements.size() )
279 std::stringstream ss;
280 ss <<
"Error: Input stream has: " << elements.size() <<
" elements, while matrix given to accommodate expected: ";
281 ss << m.
size() * m.
size() <<
" elements.";
284 typename std::vector< T >::const_iterator it = elements.begin();
285 for(
size_t i = 0; i < m.
size(); ++i )
287 for(
size_t j = 0; j < m.
size(); ++j )
299 template<
typename T >
302 return m_data.size();
305 template<
typename T >
311 template<
typename T >
317 template<
typename T >
320 if( m_n * ( m_n - 1 ) / 2 != data.size() )
322 std::stringstream ss;
323 ss <<
"Data vector length: " << data.size() <<
" doesn't fit to number of rows and cols: " << m_n;
326 m_data = std::vector< T >( data );
332 #endif // WMATRIXSYM_H
Unit test this LookUp table class.
size_t m_n
Number of rows and cols.
T value_type
Type of stored elements.
Symmetric square matrix, storing only the elements of the triangular matrix without the main diagonal...
std::vector< T > m_data
Internal data structure to store the elements.
Indicates invalid element access of a container.
const std::vector< T > & getData() const
Returns the elements stored inside of this container.
T & operator()(size_t i, size_t j)
Element acces operator as if the elements where stored as a normal matrix.
void setData(const std::vector< T > &data)
Resets the internal data to the given vector of elements.
WMatrixSym()
Default constructor leaving all empty.
boost::shared_ptr< WMatrixSym< T > > SPtr
Shorthand for shared pointers.
std::string toString(void) const
Renders the matrix to a full nxn matrix, where the main diagonal is set to 0.0 and the m(i...
size_t numElements() const
Returns the number of elements stored in this matrix.
size_t size() const
Returns the number of rows and cols of the matrix.