pair<Base<F>,Base<F>> HermitianExtremalSingValEst( const SparseMatrix<F>& A, Int basisSize ) { EL_DEBUG_CSE typedef Base<F> Real; Matrix<Real> T; Lanczos( A, T, basisSize ); const Int k = T.Height(); if( k == 0 ) return pair<Real,Real>(0,0); Matrix<Real> d, dSub; d = GetDiagonal( T ); dSub = GetDiagonal( T, -1 ); Matrix<Real> w; HermitianTridiagEig( d, dSub, w ); pair<Real,Real> extremal; extremal.second = MaxNorm(w); extremal.first = extremal.second; for( Int i=0; i<k; ++i ) extremal.first = Min(extremal.first,Abs(w(i))); return extremal; }
pair<Base<F>,Base<F>> HermitianHelper( const DistSparseMatrix<F>& A, Int basisSize ) { typedef Base<F> Real; Grid grid( A.Comm() ); DistMatrix<Real,STAR,STAR> T(grid); Lanczos( A, T, basisSize ); const Int k = T.Height(); if( k == 0 ) return pair<Real,Real>(0,0); auto d = GetDiagonal( T.Matrix() ); auto dSub = GetDiagonal( T.Matrix(), -1 ); Matrix<Real> w; HermitianTridiagEig( d, dSub, w ); pair<Real,Real> extremal; extremal.second = MaxNorm(w); extremal.first = extremal.second; for( Int i=0; i<k; ++i ) extremal.first = Min(extremal.first,Abs(w.Get(i,0))); return extremal; }
SafeProduct<Base<F>> AfterCholesky ( UpperOrLower uplo, const ElementalMatrix<F>& APre ) { DEBUG_CSE DistMatrixReadProxy<F,F,MC,MR> AProx( APre ); auto& A = AProx.GetLocked(); typedef Base<F> Real; const Int n = A.Height(); const Grid& g = A.Grid(); DistMatrix<F,MD,STAR> d(g); GetDiagonal( A, d ); Real localKappa = 0; if( d.Participating() ) { const Real scale = Real(n)/Real(2); const Int nLocalDiag = d.LocalHeight(); for( Int iLoc=0; iLoc<nLocalDiag; ++iLoc ) { const Real delta = RealPart(d.GetLocal(iLoc,0)); localKappa += Log(delta)/scale; } } SafeProduct<Real> det( n ); det.kappa = mpi::AllReduce( localKappa, g.VCComm() ); det.rho = Real(1); return det; }
DistMatrix<T,DiagCol<U,V>(),DiagRow<U,V>()> GetDiagonal( const DistMatrix<T,U,V>& A, Int offset ) { DistMatrix<T,DiagCol<U,V>(),DiagRow<U,V>()> d(A.Grid()); GetDiagonal( A, d, offset ); return d; }
inline LDLPivot BunchParlett( const DistMatrix<F>& A, Base<F> gamma ) { DEBUG_CSE typedef Base<F> Real; if( gamma == Real(0) ) gamma = LDLPivotConstant<Real>( BUNCH_PARLETT ); const ValueInt<Real> diagMax = VectorMaxAbsLoc( GetDiagonal(A) ); const Entry<Real> offDiagMax = SymmetricMaxAbsLoc( LOWER, A ); LDLPivot pivot; if( diagMax.value >= gamma*offDiagMax.value ) { pivot.nb = 1; pivot.from[0] = diagMax.index; return pivot; } else { pivot.nb = 2; pivot.from[0] = offDiagMax.i; pivot.from[1] = offDiagMax.j; return pivot; } }
bool TriangIsNormal( const Matrix<F>& U, Base<F> tol ) { const Base<F> diagFrob = FrobeniusNorm(GetDiagonal(U)); const Base<F> upperFrob = FrobeniusNorm( U ); const Base<F> offDiagFrob = Sqrt(upperFrob*upperFrob-diagFrob*diagFrob); return offDiagFrob <= tol*diagFrob; }
void CheckRealSchur( const AbstractDistMatrix<Real>& UPre, bool standardForm ) { EL_DEBUG_CSE DistMatrixReadProxy<Real,Real,MC,MR> UProx( UPre ); auto& U = UProx.GetLocked(); auto uMain = GetDiagonal(U); auto uSub = GetDiagonal(U,-1); DistMatrix<Real,STAR,STAR> uMain_STAR_STAR( uMain ), uSub_STAR_STAR( uSub ); auto& uMainLoc = uMain_STAR_STAR.Matrix(); auto& uSubLoc = uSub_STAR_STAR.Matrix(); const Int n = U.Height(); if( standardForm ) { auto uSup = GetDiagonal(U,+1); DistMatrix<Real,STAR,STAR> uSup_STAR_STAR( uSup ); auto& uSupLoc = uSup_STAR_STAR.Matrix(); for( Int j=0; j<n-1; ++j ) { const Real thisDiag = uMainLoc(j); const Real nextDiag = uMainLoc(j+1); const Real thisSub = uSubLoc(j); const Real thisSup = uSupLoc(j); if( thisSub != Real(0) && thisDiag != nextDiag ) LogicError ("Diagonal of 2x2 block was not constant: ",thisDiag," and ", nextDiag); if( thisSub*thisSup >= 0 ) LogicError("b*c >= 0: b=",thisSup," and c=",thisSub); } } if( n < 3 ) return; for( Int j=0; j<n-2; ++j ) { const Real thisSub = uSubLoc(j); const Real nextSub = uSubLoc(j+1); if( thisSub != Real(0) && nextSub != Real(0) ) LogicError ("Quasi-triangular assumption broken at j=",j, ": subdiagonals were ",thisSub," and ",nextSub); } }
bool TriangIsNormal( const ElementalMatrix<F>& UPre, Base<F> tol ) { DistMatrixReadProxy<F,F,MC,MR> UProx( UPre ); auto& U = UProx.GetLocked(); const Base<F> diagFrob = FrobeniusNorm(GetDiagonal(U)); const Base<F> upperFrob = FrobeniusNorm( U ); const Base<F> offDiagFrob = Sqrt(upperFrob*upperFrob-diagFrob*diagFrob); return offDiagFrob <= tol*diagFrob; }
inline bool TriangIsNormal( const ElementalMatrix<F>& UPre, Base<F> tol ) { auto UPtr = ReadProxy<F,MC,MR>( &UPre ); auto& U = *UPtr; const Base<F> diagFrob = FrobeniusNorm(GetDiagonal(U)); const Base<F> upperFrob = FrobeniusNorm( U ); const Base<F> offDiagFrob = Sqrt(upperFrob*upperFrob-diagFrob*diagFrob); return offDiagFrob <= tol*diagFrob; }
pair<Base<F>,Base<F>> Helper( const DistSparseMatrix<F>& A, Int basisSize ) { typedef Base<F> Real; Grid grid( A.Comm() ); DistMatrix<Real,STAR,STAR> T(grid); ProductLanczos( A, T, basisSize ); const Int k = T.Height(); if( k == 0 ) return pair<Real,Real>(0,0); auto d = GetDiagonal( T.Matrix() ); auto dSub = GetDiagonal( T.Matrix(), -1 ); Matrix<Real> w; HermitianTridiagEig( d, dSub, w, ASCENDING ); pair<Real,Real> extremal; extremal.first = Sqrt( Max(w.Get(0,0),Real(0)) ); extremal.second = Sqrt( Max(w.Get(k-1,0),Real(0)) ); return extremal; }
pair<Base<F>,Base<F>> Helper( const SparseMatrix<F>& A, Int basisSize ) { typedef Base<F> Real; Matrix<Real> T; ProductLanczos( A, T, basisSize ); const Int k = T.Height(); if( k == 0 ) return pair<Real,Real>(0,0); Matrix<Real> d, dSub; d = GetDiagonal( T ); dSub = GetDiagonal( T, -1 ); Matrix<Real> w; HermitianTridiagEig( d, dSub, w, ASCENDING ); pair<Real,Real> extremal; extremal.first = Sqrt( Max(w.Get(0,0),Real(0)) ); extremal.second = Sqrt( Max(w.Get(k-1,0),Real(0)) ); return extremal; }
pair<Base<F>,Base<F>> ExtremalSingValEst( const SparseMatrix<F>& A, Int basisSize ) { EL_DEBUG_CSE typedef Base<F> Real; Matrix<Real> T; ProductLanczos( A, T, basisSize ); const Int k = T.Height(); if( k == 0 ) return pair<Real,Real>(0,0); Matrix<Real> d, dSub; d = GetDiagonal( T ); dSub = GetDiagonal( T, -1 ); Matrix<Real> w; HermitianTridiagEig( d, dSub, w ); pair<Real,Real> extremal; extremal.first = Sqrt( Max(w(0),Real(0)) ); extremal.second = Sqrt( Max(w(k-1),Real(0)) ); return extremal; }
void CheckRealSchur( const Matrix<Real>& U, bool standardForm ) { EL_DEBUG_CSE const Int n = U.Height(); auto uMain = GetDiagonal(U); auto uSub = GetDiagonal(U,-1); if( standardForm ) { auto uSup = GetDiagonal(U,+1); for( Int j=0; j<n-1; ++j ) { const Real thisDiag = uMain(j); const Real nextDiag = uMain(j+1); const Real thisSub = uSub(j); const Real thisSup = uSup(j); if( uSub(j) != Real(0) && thisDiag != nextDiag ) LogicError ("Diagonal of 2x2 block was not constant: ",thisDiag," and ", nextDiag); if( thisSub*thisSup >= 0 ) LogicError("b*c >= 0: b=",thisSup," and c=",thisSub); } } if( n < 3 ) return; for( Int j=0; j<n-2; ++j ) { const Real thisSub = uSub(j); const Real nextSub = uSub(j+1); if( thisSub != Real(0) && nextSub != Real(0) ) LogicError ("Quasi-triangular assumption broken at j=",j, ": subdiagonals were ",thisSub," and ",nextSub); } }
SafeProduct<Base<F>> AfterCholesky ( UpperOrLower uplo, const Matrix<F>& A ) { DEBUG_CSE typedef Base<F> Real; const Int n = A.Height(); Matrix<F> d; GetDiagonal( A, d ); SafeProduct<Real> det( n ); det.rho = Real(1); const Real scale = Real(n)/Real(2); for( Int i=0; i<n; ++i ) { const Real delta = RealPart(d(i)); det.kappa += Log(delta)/scale; } return det; }
( Matrix<F>& U, const Matrix<F>& shifts, Matrix<F>& X, Matrix<F>& scales ) { typedef Base<F> Real; DEBUG_ONLY( CSE cse("safemstrsm::LUNBlock"); if( U.Height() != U.Width() ) LogicError("Triangular matrix must be square"); if( U.Width() != X.Height() ) LogicError("Matrix dimensions do not match"); if( shifts.Height() != X.Width() ) LogicError("Incompatible number of shifts"); ) auto diag = GetDiagonal(U); const Int n = U.Height(); const Int numShifts = shifts.Height(); auto overflowPair = OverflowParameters<Real>(); const Real smallNum = overflowPair.first; const Real bigNum = overflowPair.second; const Real oneHalf = Real(1)/Real(2); const Real oneQuarter = Real(1)/Real(4); // Default scale is 1 scales.Resize( numShifts, 1 ); Fill( scales, F(1) ); // Compute infinity norms of columns of U (excluding diagonal)
http://opensource.org/licenses/BSD-2-Clause */ #pragma once #ifndef EL_SCHUR_CHECkREAL_HPP #define EL_SCHUR_CHECkREAL_HPP namespace El { namespace schur { template<typename Real> void CheckRealSchur( const Matrix<Real>& U, bool standardForm ) { DEBUG_ONLY(CSE cse("CheckRealSchur")) const Int n = U.Height(); auto uMain = GetDiagonal(U); auto uSub = GetDiagonal(U,-1); if( standardForm ) { auto uSup = GetDiagonal(U,+1); for( Int j=0; j<n-1; ++j ) { const Real thisDiag = uMain.Get(j, 0); const Real nextDiag = uMain.Get(j+1,0); const Real thisSub = uSub.Get(j,0); const Real thisSup = uSup.Get(j,0); if( uSub.Get(j,0) != Real(0) && thisDiag != nextDiag ) LogicError ("Diagonal of 2x2 block was not constant: ",thisDiag," and ", nextDiag); if( thisSub*thisSup >= 0 )
Matrix<T> GetDiagonal( const Matrix<T>& A, Int offset ) { Matrix<T> d; GetDiagonal( A, d, offset ); return d; }
http://opensource.org/licenses/BSD-2-Clause */ #ifndef EL_CHOLESKY_LVAR3PIVOTED_HPP #define EL_CHOLESKY_LVAR3PIVOTED_HPP namespace El { namespace cholesky { namespace pivot { template<typename F> inline LDLPivot Full( const Matrix<F>& A ) { DEBUG_ONLY(CSE cse("cholesky::pivot::Full")) const auto diagMax = VectorMaxAbsLoc( GetDiagonal(A) ); LDLPivot pivot; pivot.nb = 1; pivot.from[0] = diagMax.index; return pivot; } template<typename F> inline LDLPivot Full( const DistMatrix<F>& A ) { DEBUG_ONLY(CSE cse("cholesky::pivot::Full")) const auto diagMax = VectorMaxAbsLoc( GetDiagonal(A) ); LDLPivot pivot; pivot.nb = 1; pivot.from[0] = diagMax.index;