5#include "low_tri_mat.h"
34 for(
unsigned i =0; i < _dim;i++)
36 for(
unsigned j = i; j < _dim;j++)
38 operator()(i,j)=m(i,j);
53 memcpy(_data,m._data,size()*
sizeof(T));
68 void resize(
unsigned n)
78 for(
unsigned i =0; i < _dim; i++)
80 for(
unsigned j = 0; j < _dim; j++)
85 m(i,j)=operator()(i,j);
92 operator const mat<T>()
const
95 for(
unsigned i =0; i < _dim;i++)
97 for(
unsigned j = 0; j < _dim;j++)
102 m(i,j)=operator()(i,j);
118 unsigned size()
const
130 unsigned ncols()
const
136 unsigned nrows()
const
142 void fill(
const T& c)
144 for(
unsigned i=0;i < size();i++)
151 T& operator() (
unsigned i,
unsigned j)
153 assert( j >= i && j < _dim);
154 return _data[j*(j+1)/2+i];
158 const T& operator() (
unsigned i,
unsigned j)
const
160 assert( j >= i && j < _dim);
161 return _data[j*(j+1)/2+i];
168 for(
unsigned i = 0; i < size(); i++)
185 assert(m2.nrows() == nrows());
186 unsigned M = m2.ncols();
188 for(
unsigned i = 0; i < nrows(); i++)
189 for(
unsigned j = i; j < M;j++)
190 for(
unsigned k = i; k <= j; k++)
191 r(i,j) += operator()(i,k) * (T)(m2(k,j));
197 const mat<T> operator*(
const mat<T>& m2)
199 assert(m2.nrows() == nrows());
200 unsigned M = m2.ncols();
201 mat<T> r(nrows(),M,(T)0);
202 for(
unsigned i = 0; i < nrows(); i++)
203 for(
unsigned j = 0; j < M;j++)
204 for(
unsigned k = i; k < nrows(); k++)
205 r(i,j) += operator()(i,k) * (T)(m2(k,j));
215const low_tri_mat<T> transpose(
const up_tri_mat<T> &m)
217 low_tri_mat<T> r(m.nrows());
218 for(
unsigned j = 0; j < m.ncols();j++)
219 for(
unsigned i = j; i < m.nrows();i++)
229const up_tri_mat<T> transpose(
const low_tri_mat<T> &m)
231 up_tri_mat<T> r(m.nrows());
232 for(
unsigned j = 0; j < m.ncols();j++)
233 for(
unsigned i = j; i < m.nrows();i++)
246template <
typename T,
typename S>
247const vec<T> operator*(
const up_tri_mat<T>& m1,
const vec<S>& v)
249 assert(m1.ncols() == v.size());
250 unsigned M = v.size();
252 for(
unsigned i = 0; i < m1.nrows(); i++)
253 for(
unsigned k = i; k < m1.ncols(); k++)
254 r(i) += m1(i,k) * (T)(v(k));
260template <
typename T,
typename S>
261const mat<T> operator*(
const mat<S>& m1,
const up_tri_mat<T>& m2)
263 assert(m1.ncols() == m2.nrows());
264 unsigned M = m2.nrows();
265 mat<T> r(m1.nrows(),M,(T)0);
266 for(
unsigned i = 0; i < m1.nrows(); i++)
267 for(
unsigned j = 0; j < M;j++)
268 for(
unsigned k = 0; k <= j; k++)
269 r(i,j) += m1(i,k) * (T)(m2(k,j));
276const mat<T> operator*(
const low_tri_mat<T>& m1,
const up_tri_mat<T>& m2)
278 assert(m1.nrows() == m2.nrows());
280 mat<T> r(m1.nrows(),m2.nrows(),(T)0);
281 for(
unsigned i = 0; i < m1.nrows(); i++)
282 for(
unsigned j = 0; j < m1.nrows();j++)
284 unsigned h = std::min(i,j);
285 for(
unsigned k = 0; k <= h; k++)
286 r(i,j) += m1(i,k) * (T)(m2(k,j));
295mat<T> operator*(
const perm_mat& p,
const up_tri_mat<T>& m)
303mat<T> operator*(
const up_tri_mat<T>& m,
const perm_mat& p)
312std::ostream&
operator<<(std::ostream& out,
const up_tri_mat<T>& m)
315 for(
unsigned i =0;i< m.nrows() ;++i)
318 for (; j<m.ncols(); ++j)
322 out << m(i,j) <<
"\t";
A matrix type (full column major storage) The matrix can be loaded directly into OpenGL without need ...
unsigned ncols() const
number of columns
unsigned nrows() const
number of rows
up_tri_mat< T > operator/(const T &s)
division by a scalar
up_tri_mat< T > & operator/=(const T &s)
in place division by a scalar
up_tri_mat< T > & operator=(const up_tri_mat< T > &m)
assignment of a matrix with the same element type
void resize(unsigned dim)
resize the vector
unsigned size() const
number of elements
std::ostream & operator<<(std::ostream &os, const vr_device_info &di)
stream out operator for device infos