37 #include "../exceptions/WOutOfBounds.h"
45 template<
typename T >
58 typedef std::shared_ptr< WMatrixSym < T > >
SPtr;
94 const T&
operator()(
size_t i,
size_t j )
const;
113 const std::vector< T >&
getData()
const;
120 void setData(
const std::vector< T > &data );
142 template<
typename T >
144 : m_data( ( n * ( n - 1 ) ) / 2, 0.0 ),
149 template<
typename T >
155 template<
typename T >
158 if( i == j || i >= m_n || j >= m_n )
160 std::stringstream ss;
161 ss <<
"Invalid Element Access ( " << i <<
", " << j <<
" ). No diagonal elements or indices bigger than " << m_n <<
" are allowed.";
168 return m_data[( i * m_n + j - ( i + 1 ) * ( i + 2 ) / 2 )];
172 template<
typename T >
175 if( i == j || i >= m_n || j >= m_n )
177 std::stringstream ss;
178 ss <<
"Invalid Element Access ( " << i <<
", " << j <<
" ). No diagonal elements or indices bigger than " << m_n <<
" are allowed.";
185 return m_data[( i * m_n + j - ( i + 1 ) * ( i + 2 ) / 2 )];
189 template<
typename T >
192 std::stringstream ss;
193 ss << std::setprecision( 9 ) << std::fixed;
207 template<
typename T >
210 std::vector< T > l = lhs.
getData();
211 std::vector< T > r = rhs.
getData();
224 template<
typename T >
225 inline std::ostream& operator<<( std::ostream& os,
const WMatrixSym< T >& m )
228 for(
size_t i = 0; i < n; ++i )
230 for(
size_t j = 0; j < n; ++j )
266 template<
typename T >
267 inline std::istream& operator>>( std::istream& is,
WMatrixSym< T >& m )
269 std::vector< T > elements;
273 elements.push_back( elm );
275 if( m.
size() * m.
size() != elements.size() )
277 std::stringstream ss;
278 ss <<
"Error: Input stream has: " << elements.size() <<
" elements, while matrix given to accommodate expected: ";
279 ss << m.
size() * m.
size() <<
" elements.";
282 typename std::vector< T >::const_iterator it = elements.begin();
283 for(
size_t i = 0; i < m.
size(); ++i )
285 for(
size_t j = 0; j < m.
size(); ++j )
297 template<
typename T >
300 return m_data.size();
303 template<
typename T >
309 template<
typename T >
315 template<
typename T >
318 if( m_n * ( m_n - 1 ) / 2 != data.size() )
320 std::stringstream ss;
321 ss <<
"Data vector length: " << data.size() <<
" doesn't fit to number of rows and cols: " << m_n;
324 m_data = std::vector< T >( data );
Unit test this LookUp table class.
Symmetric square matrix, storing only the elements of the triangular matrix without the main diagonal...
WMatrixSym()
Default constructor leaving all empty.
size_t numElements() const
Returns the number of elements stored in this matrix.
std::vector< T > m_data
Internal data structure to store the elements.
void setData(const std::vector< T > &data)
Resets the internal data to the given vector of elements.
T & operator()(size_t i, size_t j)
Element acces operator as if the elements where stored as a normal matrix.
T value_type
Type of stored elements.
size_t size() const
Returns the number of rows and cols of the matrix.
size_t m_n
Number of rows and cols.
const std::vector< T > & getData() const
Returns the elements stored inside of this container.
std::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,...
Indicates invalid element access of a container.