11 #ifndef PRIMATOLOGIST_MATH_MATRIX_D_H
12 #define PRIMATOLOGIST_MATH_MATRIX_D_H
15 #include <aims/data/data_g.h>
16 #include <aims/math/gausslu.h>
31 carto::VolumeRef<T>( nrow, ncol )
39 carto::VolumeRef<T>( volume.template copy<T>() )
46 carto::VolumeRef<T>( vector.size() )
48 for(
int i = 0; i < vector.size(); ++i )
49 this->
at(i) = vector[i];
60 template <
typename T,
typename U>
63 static bool equal(
const carto::VolumeRef<T> *,
64 const carto::VolumeRef<U> * )
73 static bool equal(
const carto::VolumeRef<T> * a,
74 const carto::VolumeRef<T> * b )
88 *
this = volume.copy();
97 this->reallocate( vector.size() );
98 for(
int i = 0; i < vector.size(); ++i )
99 this->
at(i) = vector[i];
107 template <
typename T>
109 carto::VolumeRef<T>( volume )
116 template <
typename T>
117 template <
typename U>
127 template <
typename T>
128 template <
typename U>
135 template <
typename T,
typename U>
139 typedef typename carto::volumeutil::multiplies<T,U>::result_type
146 for(
int i = 0; i < a.
nrow(); ++i )
147 for(
int j = 0; j < b.
ncol(); ++j )
150 for(
int k = 0; k < a.
ncol(); ++k )
151 value += a(i, k) * b(k, j);
152 result(i, j) = value;
157 template <
typename T>
164 template <
typename T>
168 for(
int i = 0; i < m.
nrow(); ++i )
169 for(
int j = 0; j < m.
ncol(); ++j )
170 result( j, i ) = m( i, j );
174 template <
typename T>
181 template <
typename T>
185 AimsData<float> aimsFloat( matrix.template copy<float>() );
186 AimsData<float> invertedAimsFloat = AimsInversionLU( aimsFloat );
187 carto::VolumeRef<T> volume = carto::VolumeRef<float>( invertedAimsFloat.volume() ).copy<T>();
195 template <
typename T,
typename U>
200 for(
int i = 0; i < vol.
nrow(); ++i )
201 for(
int j = 0; j < vol.
ncol(); ++j )
202 if( vol(i, j) != other(i, j) )
207 template <
typename T,
typename U>
210 return !( vol == other );
213 template <
typename T>
216 carto::VolumeRef<T> volresult = -(carto::VolumeRef<T> &)vol;
220 template <
typename T,
typename U>
221 MatrixBase<typename carto::volumeutil::plus<T,U>::result_type >
224 carto::VolumeRef<typename carto::volumeutil::plus<T,U>::result_type> volresult = (carto::VolumeRef<T>&)vol + value;
228 template <
typename T,
typename U>
229 MatrixBase<typename carto::volumeutil::minus<T,U>::result_type >
232 carto::VolumeRef<typename carto::volumeutil::minus<T,U>::result_type> volresult = (carto::VolumeRef<T>&)vol - value;
236 template <
typename T,
typename U>
237 MatrixBase<typename carto::volumeutil::multiplies<T,U>::result_type >
240 carto::VolumeRef<typename carto::volumeutil::multiplies<T,U>::result_type> volresult = (carto::VolumeRef<T>&)vol * value;
244 template <
typename T,
typename U>
245 MatrixBase<typename carto::volumeutil::divides<T,U>::result_type >
248 carto::VolumeRef<typename carto::volumeutil::divides<T,U>::result_type> volresult = (carto::VolumeRef<T>&)vol / value;
252 template <
typename T,
typename U>
253 MatrixBase<typename carto::volumeutil::plus<U,T>::result_type >
256 carto::VolumeRef<typename carto::volumeutil::plus<T,U>::result_type> volresult = value + (carto::VolumeRef<T>&)vol;
260 template <
typename T,
typename U>
261 MatrixBase<typename carto::volumeutil::minus<U,T>::result_type >
264 carto::VolumeRef<typename carto::volumeutil::minus<T,U>::result_type> volresult = value - (carto::VolumeRef<T>&)vol;
268 template <
typename T,
typename U>
269 MatrixBase<typename carto::volumeutil::multiplies<U,T>::result_type >
272 carto::VolumeRef<typename carto::volumeutil::multiplies<T,U>::result_type> volresult = value * (carto::VolumeRef<T>&)vol;
276 template <
typename T,
typename U>
277 MatrixBase<typename carto::volumeutil::divides<U,T>::result_type >
280 carto::VolumeRef<typename carto::volumeutil::divides<T,U>::result_type> volresult = value / (carto::VolumeRef<T>&)vol;
284 template <
typename T,
typename U>
285 MatrixBase<typename carto::volumeutil::plus<T,U>::result_type >
288 carto::VolumeRef<typename carto::volumeutil::plus<T,U>::result_type> volresult = (carto::VolumeRef<T>&)vol + (carto::VolumeRef<U>&)other;
292 template <
typename T,
typename U>
293 MatrixBase<typename carto::volumeutil::minus<T,U>::result_type >
296 carto::VolumeRef<typename carto::volumeutil::minus<T,U>::result_type> volresult = (carto::VolumeRef<T>&)vol - (carto::VolumeRef<U>&)other;
304 template <
typename T>
307 return this->getSizeX();
310 template <
typename T>
313 return this->getSizeY();
316 template <
typename T>
319 return this->getSizeX() * this->getSizeY();
326 template <
typename T>
330 return out << (carto::VolumeRef<T> &)matrix;
340 template <
typename T>
Matrix class implementing matrix operations.
MatrixBase< T > & transpose()
Matrix transposition.
int size() const
Number of elements.
MatrixBase< T > & invert()
Matrix inversion.
int ncol() const
Number of columns.
MatrixBase< T > & operator*=(const MatrixBase< U > &)
Matrix product.
int nrow() const
Number of rows.
MatrixBase(int nrow=1, int ncol=1)
Standard constructor Allocate a matrix of size nrow x ncol.
MatrixBase< T > & operator=(const carto::VolumeRef< U > &matrix)
Assignment operator The content from other is entirely copied.
This exception is thrown when an attempt is made at multiplying two matrices with incompatible dimens...
const T & at(const carto::VolumeRef< T > &vol, long px, long py, long pz, long pt, const Point4dl &fullsize, const Point4dl &binf)
MatrixBase< T > transpose(const MatrixBase< T > &)
Matrix transposition.
MatrixBase< T > asMatrix(carto::VolumeRef< T > &volume)
Interprets the volume as a matrix.
MatrixBase< typename carto::volumeutil::multiplies< T, U >::result_type > operator*(const MatrixBase< T > &a, const MatrixBase< U > &b)
Matrix product.
MatrixBase< T > invert(const MatrixBase< T > &)
Matrix inversion.
bool operator!=(const MatrixBase< T > &vol, const MatrixBase< U > &other)
Returns false if dimensions are not the same or if any couple of elements is not equal.
bool operator==(const MatrixBase< T > &vol, const MatrixBase< U > &other)
Returns true if the dimensions are the same and if all elements are equal.
MatrixBase< T > operator-(const MatrixBase< T > &vol)
Returns a Matrix filled with opposite elements.
MatrixBase< typename carto::volumeutil::divides< T, U >::result_type > operator/(const MatrixBase< T > &vol, const U &value)
Matrix / Scalar.
std::ostream & operator<<(std::ostream &out, const MatrixBase< T > &matrix)
Print the matrix content on the standard output.
MatrixBase< typename carto::volumeutil::plus< T, U >::result_type > operator+(const MatrixBase< T > &vol, const U &value)
Matrix + Scalar.
static bool equal(const carto::VolumeRef< T > *a, const carto::VolumeRef< T > *b)
static bool equal(const carto::VolumeRef< T > *, const carto::VolumeRef< U > *)