5#include "GaudiKernel/StatusCode.h"
21charAddress(
auto &val){
22 return reinterpret_cast<char *
> (&
val);
73 if( nr != m.nrow() || nc != m.ncol() ) {
74 throw std::range_error(
"AlMat::copy: sizes do not match!" );
77 for(
int i=0; i<nr; i++ ) {
78 for(
int j=0; j<nc; j++ ) {
79 elemr(i, j) = m.elemc(i, j);
85 long int n = m.size();
87 throw std::range_error(
"AlMat::copy: sizes do not match!" );
90 for(
int i=0; i<n; i++ ) {
91 for(
int j=0; j<n; j++ ) {
99 if( i<0 ) {
throw std::out_of_range(
"AlMat::elemr: Index 1 < zero! " ); };
100 if( i>=size ) {
throw std::out_of_range(
"AlMat::elemr: Index 1 too large!" ); };
101 if( j<0 ) {
throw std::out_of_range(
"AlMat::elemr: Index 2 < zero! " ); };
102 if( j>=size ) {
throw std::out_of_range(
"AlMat::elemr: Index 2 too large!" ); };
111 if( i<0 ) {
throw std::out_of_range(
"AlMat::elemr: Index 1 < zero! " ); };
112 if( i>=size ) {
throw std::out_of_range(
"AlMat::elemr: Index 1 too large!" ); };
113 if( j<0 ) {
throw std::out_of_range(
"AlMat::elemr: Index 2 < zero! " ); };
114 if( j>=size ) {
throw std::out_of_range(
"AlMat::elemr: Index 2 too large!" ); };
123 if( i<0 ) {
throw std::out_of_range(
"AlMat::elemr: Index 1 < zero! " ); };
124 if( i>=size ) {
throw std::out_of_range(
"AlMat::elemr: Index 1 too large!" ); };
125 if( j<0 ) {
throw std::out_of_range(
"AlMat::elemr: Index 2 < zero! " ); };
126 if( j>=size ) {
throw std::out_of_range(
"AlMat::elemr: Index 2 too large!" ); };
143 if (
this==&m)
return *
this;
147 throw std::range_error(
"AlMat=AlMat Assignment: size do not match!" );
151 reSize(m.nrow(), m.ncol());
160 throw std::range_error(
"AlMat=AlSymMatBase Assignment: size do not match!" );
164 reSize(m.size(), m.size());
173 throw std::range_error(
"AlMat: operator+: size do not match!" );
179 double* q = m.m_ptr_data +
m_nele;
180 double*
r = b.m_ptr_data +
m_nele;
190 throw std::range_error(
"AlMat: operator+=: size do not match!" );
194 double* q = m.m_ptr_data +
m_nele;
203 throw std::range_error(
"AlMat: operator-: size do not match!" );
209 double* q = m.m_ptr_data +
m_nele;
210 double*
r = b.m_ptr_data +
m_nele;
219 throw std::range_error(
"AlMat: operator-=: size do not match!");
223 double* q = m.m_ptr_data +
m_nele;
230 if(
ncol() != m.nrow() )
232 throw std::range_error(
"AlMat: operator*: size do not match!" );
240 for(
int i=0; i<k; i++ ) {
241 for(
int j=0; j<l; j++ ) {
242 for(
int n=0; n<f; n++) b.elemr(i, j) +=
elemc(i, n)*m.elemc(n, j);
249 if(
ncol() != m.size())
251 throw std::range_error(
"AlMat: operator*: size do not match!" );
258 for(
int i=0; i<k; i++ ) {
259 for(
int j=0; j<l; j++ ) {
260 for(
int n=0; n<l; n++) b.elemr(i, j) +=
elemc(i, n)*m.elemc(n, j);
268 if(
ncol() !=
v.size() )
270 throw std::range_error(
"AlMat: operator*: size do not match! " );
279 for(
int i=0; i<k; i++ ) {
282 for(
int j=0; j<l; j++ ) *p += (*(q+j))*(*(
v.ptrData()+j));
299 for(
int i=0; i<b.m_nrow; i++ ) {
300 for(
int j=0; j<b.m_ncol; j++ ) {
327 throw std::range_error(
"AlMat invertS: non-square matrix!" );
331 for(
int i=0; i<b.size(); i++ ) {
332 for(
int j=0; j<=i; j++ ) {
333 b.elemr(i, j) =
elemc(i, j);
341 if (ierr==0) (*this).copy(b);
361 for(
int i=0; i<k; i++ ) {
362 for(
int j=0; j<l; j++ ) {
373 std::ifstream inmat(filename.c_str(), std::ios::binary);
375 return StatusCode::FAILURE;
378 inmat.read(charAddress(mNrow),
sizeof (mNrow));
380 inmat.read(charAddress(mNcol),
sizeof (mNcol));
390 for(
int i=0; i<
m_nrow; i++) {
391 for(
int j=0; j<
m_ncol; j++) {
392 inmat.read(charAddress(melem),
sizeof (melem));
398 return StatusCode::SUCCESS;
414StatusCode
AlMat::Write(
const std::string &filename,
bool binary,
unsigned int precision)
416 std::ofstream outmat;
419 outmat.open((
m_pathbin+filename).c_str(), std::ios::binary);
421 return StatusCode::FAILURE;
424 outmat.write(charAddress(mNrow),
sizeof (mNrow));
426 outmat.write(charAddress(mNcol),
sizeof (mNcol));
429 outmat.open((
m_pathtxt+filename).c_str());
431 return StatusCode::FAILURE;
432 outmat.setf(std::ios::fixed);
434 outmat.setf(std::ios::showpoint);
435 outmat.precision(precision);
440 for(
int i=0; i<
m_nrow; i++) {
441 for(
int j=0; j<
m_ncol; j++) {
444 outmat.write(charAddress(melem),
sizeof (melem));
446 outmat <<
" " << std::setw(12) << melem;
453 return StatusCode::SUCCESS;
459 std::ostringstream textmatrix;
461 int LastCol = NColsPerSet;
463 int NSets = (
ncol()/NColsPerSet);
464 if (
ncol()%NColsPerSet>0) NSets++;
465 textmatrix << std::endl;
466 textmatrix <<
" ++++++++++++++ AlMat ++ "
470 <<
" +++++++++++++++++++++++++++++"<< std::endl;
472 FirstCol =
set*NColsPerSet;
473 LastCol = (
set+1)*NColsPerSet;
474 if (LastCol>
ncol()) LastCol =
ncol();
475 textmatrix <<
" |row\\col| ";
476 for (
int col=FirstCol; col < LastCol; col++) {
477 textmatrix << std::setw(6) << col <<
" | ";
479 textmatrix << std::endl;
480 textmatrix <<
" |-------|";
481 for (
int col=FirstCol; col < LastCol; col++) {
482 textmatrix <<
"--------|";
484 textmatrix << std::endl;
485 for (
int row=0; row<
nrow(); row++) {
486 textmatrix <<
" |" << std::setw(6) << row <<
" | ";
487 for (
int col=FirstCol; col<LastCol; col++) {
489 textmatrix << std::setprecision(5) << std:: setw(6) << melem <<
" | ";
491 textmatrix << std::endl;
493 if (
set != (NSets-1)) textmatrix << std::endl;
495 textmatrix <<
" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<< std::endl;
496 return textmatrix.str();
AlMat operator+(const AlMat &m) const
AlMat & operator=(const double &)
StatusCode ReadScalaPack(const std::string &)
AlMat & operator+=(const AlMat &m)
AlMat operator*(const AlMat &m) const
virtual long int elem(long int, long int) const
double elemc(long int, long int) const
StatusCode Write(const std::string &, bool, unsigned int precision=6)
void reSize(int Nnew, int Mnew)
void copy(const AlMat &m)
void SetPathBin(const std::string &)
void SetPathTxt(const std::string &)
void invertS(int &ierr, double Norm)
AlMat & operator*=(const double &d)
double & elemr(long int, long int)
AlMat operator-(const AlMat &m) const
const std::string Print(const int NColsPerSet=10)
AlMat & operator-=(const AlMat &m)
contains the base implementation for handling symmertic matrices
contains the implementation for handling symmetric matrices in triangular representation
void Norm(TH1 *h, double scale)
Ensure that the ATLAS eigen extensions are properly loaded.