17 #ifndef MAGNESMATHTOOLS_H 18 #define MAGNESMATHTOOLS_H 24 #include "exception.h" 27 #define M_PI 3.14159265358979323846 30 #include "arrays_defines.h" 32 #include "toolsexport.h" 50 for(
size_t i=0;i<N;++i)
73 operator const X*()
const 106 D1Array (
size_t i,
const X& x );
118 void Initialize (
size_t i,
const X& x );
142 operator const X*()
const 150 void operator*=(
const X& x);
152 void operator/=(
const X& x);
168 for (
size_t k=0;k<i;k++ )
175 if ( x.m_data !=NULL )
177 m_data=
new X[m_size];
179 memcpy ( m_data,x,m_size*
sizeof ( X ) );
190 if ( x.m_data != NULL )
192 m_data=
new X[m_size];
193 memcpy ( m_data,x,m_size*
sizeof ( X ) );
205 for (
size_t k=0;k<i;k++ )
211 assert ( i < m_size );
217 assert ( i < m_size );
223 for(
size_t i=0;i<this->size();++i)
231 for(
size_t i=0;i<this->size();++i)
254 explicit D2Array (
size_t i,
size_t j ) : m_rows ( i ), m_columns ( j )
259 D2Array (
size_t i,
size_t j,
const X& x );
265 void operator+=(
const D2Array& x);
267 void operator-=(
const D2Array& x);
269 void operator*=(
const X& x);
271 void operator /=(
const X& x);
275 assert( i > 0 && j > 0 );
285 return ( m_data == NULL );
288 void Initialize (
size_t i,
size_t j,
const X& x );
303 X& operator() (
size_t i,
size_t j );
305 const X& operator() (
size_t i,
size_t j )
const;
312 operator const X*()
const 328 void SwapRows (
size_t i,
size_t j );
330 void SwapColumns (
size_t i,
size_t j );
358 m_data =
new X[total];
359 for (
size_t k=0;k<total;++k )
370 m_data =
new X[total];
371 for (
size_t k=0;k<total;++k )
380 if ( x.m_data != NULL )
382 m_data=
new X[m_rows*m_columns];
383 memcpy ( m_data,x,m_rows*m_columns*
sizeof ( X ) );
394 if ( x.m_data == NULL )
400 m_data=
new X[m_rows*m_columns];
401 memcpy ( m_data,x,m_rows*m_columns*
sizeof ( X ) );
408 assert ( this->m_rows == x.m_rows && this->m_columns == x.m_columns );
409 for(
size_t i=0;i<m_rows;++i)
410 for(
size_t j=0;j<m_columns;++j)
411 (*
this)(i,j)+=x(i,j);
416 assert ( this->m_rows == x.m_rows && this->m_columns == x.m_columns );
417 for(
size_t i=0;i<m_rows;++i)
418 for(
size_t j=0;j<m_columns;++j)
419 (*
this)(i,j)-=x(i,j);
424 for(
size_t i=0;i<this->
NRows();++i)
425 for(
size_t j=0;j<this->
NColumns();++j)
433 for(
size_t i=0;i<this->
NRows();++i)
434 for(
size_t j=0;j<this->
NColumns();++j)
442 return m_data[j*m_rows+i];
448 return m_data[j*m_rows+i];
454 for (
size_t k=0;k<m_columns;++k )
456 X tmp=m_data[k*m_rows+j];
457 m_data[k*m_rows+j]=m_data[k*m_rows+i];
458 m_data[k*m_rows+i]=tmp;
464 for (
size_t k=0;k<m_rows;++k )
466 X tmp= ( *this ) ( k,i );
467 ( *this ) ( k,i ) = ( *
this ) ( k,j );
468 ( *this ) ( k,j ) =tmp;
477 for (
size_t i=0;i<m_rows;i++ )
481 for (
size_t j=0;j<m_columns;j++ )
482 nmat ( k,j ) = ( *this ) ( i,j );
496 for (
size_t i=0;i<m_rows;i++ )
499 for (
size_t j=0;j<m_columns;j++ )
502 nmat ( i,k++ ) = ( *this ) ( i,j );
511 for (
size_t i=0;i<m_columns;i++ )
512 fila ( i ) = ( *this ) ( row,i );
520 for (
size_t i=0;i<m_rows;i++ )
521 columna ( i ) = ( *this ) ( i,column );
529 for(
size_t i=0;i<this->
NRows();++i)
530 for(
size_t j=i+1;j<this->
NColumns();++j)
532 X mean=(t(i,j)+t(j,i))/2;
541 for(
size_t i=0;i<this->
NRows();++i)
542 for(
size_t j=i;j<this->
NColumns();++j)
548 X mean=(t(i,j)-t(j,i))/2;
562 for(
size_t i=0;i<n;++i)
564 for(
size_t j=i+1;j<n;++j)
577 for(
size_t i=0;i<this->
NRows();++i)
589 for(
size_t i=0;i<n;++i)
604 cblas_dgemm ( CblasColMajor,CblasNoTrans,CblasNoTrans,a.
NRows(),b.
NColumns(),a.
NRows(),1.0,a,stride,b,b.
NColumns(),0.0,c,stride );
611 cblas_dgemm ( CblasColMajor,CblasNoTrans,CblasNoTrans,a.
NRows(),b.NColumns(),a.
NRows(),1.0,a,stride,b,b.
NColumns(),0.0,c,stride );
626 dgemm(&transa,&transb,&m,&n,&k,&alpha,const_cast<double*> ( static_cast<const double*> ( a )),&lda,const_cast<double*> ( static_cast<const double*> ( b )),&ldb,&beta,c,&ldc);
640 cblas_dgemv ( CblasColMajor,CblasNoTrans,a.
NRows(),a.
NColumns(),1.0,a,a.
NRows(),b,1,0.0,c,1 );
644 cblas_dgemv ( CblasColMajor,CblasNoTrans,a.
NRows(),a.
NColumns(),1.0,a,a.
NRows(),b,1,0.0,c,1 );
655 dgemv(&trans,&nrows,&ncolumns,&alpha,const_cast<double*> ( static_cast<const double*> ( a ) ),&lda,const_cast<double*> ( static_cast<const double*> ( b ) ),&incx,&beta,c,&incy);
660 #if defined WITH_MKL || defined WITH_VECLIB || defined WITH_LAPACK 672 dsyev_ ( &jobz,&uplo,&n,a,&lda,e,work,&ldwork,&info );
679 dsyev ( &jobz,&uplo,&n,a,&lda,e,work,&ldwork,&info );
687 #if defined WITH_MKL || defined WITH_LAPACK 701 dgelss ( &m,&n,&nrhs,A,&lda,b,&ldb,s,&rcond,&rank,work,&ldwork,&info );
704 throw magnes::Exception(
"Illegal entry to dgelss routine in SVDFit");
706 throw magnes::Exception(
"dgelss routine has not converged in SVDFit");
718 __CLPK_integer m=A.
NRows();
720 __CLPK_integer nrhs=1;
721 __CLPK_integer lda=A.
NRows();
722 __CLPK_integer ldb=b.
size();
724 __CLPK_integer ldwork=7*m;
729 dgelss_ ( &m,&n,&nrhs,A,&lda,b,&ldb,s,&rcond,&rank,work,&ldwork,&info );
731 throw magnes::Exception(
"Illegal entry to dgelss routine in SVDFit");
733 throw magnes::Exception(
"dgelss routine has not converged in SVDFit");
740 throw magnes::Exception(
"SVD fit not implemented");
747 __CLPK_integer m=a.
NRows();
749 __CLPK_integer lda=m;
751 __CLPK_integer* ipiv =
new __CLPK_integer[m];
752 dgetrf_ ( &m,&n,a,&lda,ipiv,&info );
758 int* ipiv =
new int[m];
759 dgetrf ( &m,&n,a,&lda,ipiv,&info );
764 __CLPK_integer lwork=n;
765 dgetri_ ( &n,a,&lda,ipiv,work,&lwork,&info );
768 dgetri ( &n,a,&lda,ipiv,work,&lwork,&info );
782 Scalar() : m_value(NULL) {}
784 ~
Scalar() {
delete m_value; }
785 X Value()
const {
return *m_value; }
798 m_value =
new X(v.Value());
823 m_value =
new X(e.Value());
837 if ( m_value ) *m_value=v;
844 typedef void (
Scalar::*bool_type) ()
const;
845 void helperfunction()
const {}
851 operator bool_type ()
const 853 if ( m_value != 0 )
return &Scalar::helperfunction;
880 m_eigenvalues.Clear();
882 bool Empty()
const {
return m_lftensor.Empty() && m_pftensor.Empty(); }
890 void SetPrincipalFrame();
896 Eigen(this->PrincipalFrame(),this->EigenValues());
897 this->PrincipalFrame().Transpose();
910 library=
"veclib macosx";
924 #endif //MAGNESMATHTOOLS_H monodimensional dynamically allocated array
Definition: mathtools.h:89
void operator/=(const X &x)
Definition: mathtools.h:431
size_t NRows() const
Definition: mathtools.h:318
Scalar(X v)
Definition: mathtools.h:788
void SwapRows(size_t i, size_t j)
Definition: mathtools.h:451
~D2Array()
Definition: mathtools.h:290
void SwapColumns(size_t i, size_t j)
Definition: mathtools.h:462
D1StaticArray(const X &x)
Definition: mathtools.h:48
void operator-=(const D2Array &x)
Definition: mathtools.h:414
size_t size() const
Definition: mathtools.h:79
the global magnes namespace
Definition: ccchequation.h:38
D2Array< X > SymmetricPart() const
Definition: mathtools.h:526
D1Array()
Definition: mathtools.h:96
D1Array< X > GetRow(size_t row) const
Definition: mathtools.h:508
X & operator()(size_t i)
Definition: mathtools.h:63
Definition: mathtools.h:779
void operator*=(const X &x)
Definition: mathtools.h:422
D2Array(size_t i, size_t j)
Definition: mathtools.h:254
monodimensional array
Definition: mathtools.h:242
X & operator()(size_t i, size_t j)
Definition: mathtools.h:440
bool Empty() const
Definition: mathtools.h:283
D2Array< X > RemoveColumn(size_t column)
Definition: mathtools.h:492
D2Array< X > RemoveRow(size_t row)
Definition: mathtools.h:473
const X & operator()(size_t i) const
Definition: mathtools.h:56
void Transpose()
Definition: mathtools.h:557
void Initialize(size_t i, size_t j)
Definition: mathtools.h:273
size_t size() const
Definition: mathtools.h:154
D2Array< X > AntiSymmetricPart() const
Definition: mathtools.h:538
~D1Array()
Definition: mathtools.h:120
D1Array(size_t i)
Definition: mathtools.h:101
D2Array & operator=(const D2Array &x)
Definition: mathtools.h:388
D2Array()
Definition: mathtools.h:248
size_t NColumns() const
Definition: mathtools.h:323
void operator+=(const D2Array &x)
Definition: mathtools.h:406
X Trace() const
Definition: mathtools.h:573
Definition: mathtools.h:38
int Eigen(D2Array< double > &a, D1Array< double > &e)
Definition: mathtools.h:662
Definition: mathtools.h:866
Scalar(const Scalar &v)
Definition: mathtools.h:793
std::string MathInfo()
Definition: mathtools.h:901
Coordinate operator*(float f, Coordinate a)
Definition: coordinate.h:102
D1Array< X > GetColumn(size_t column) const
Definition: mathtools.h:517
void Initialize(size_t i)
Definition: mathtools.h:110