void GetImagPartOfDiagonal ( const DistMatrix<T,U,V>& A, AbstractDistMatrix<Base<T>>& d, Int offset ) { DEBUG_ONLY(CallStackEntry cse("GetImagPartOfDiagonal")) std::function<Base<T>(T)> imagPart ( []( T alpha ) { return ImagPart(alpha); } ); GetMappedDiagonal( A, d, imagPart, offset ); }
void GetImagPartOfDiagonal ( const DistMatrix<T,U,V>& A, ElementalMatrix<Base<T>>& d, Int offset ) { DEBUG_ONLY(CSE cse("GetImagPartOfDiagonal")) function<Base<T>(T)> imagPart ( []( T alpha ) { return ImagPart(alpha); } ); GetMappedDiagonal( A, d, imagPart, offset ); }
void ImagPart( const Matrix<T>& A, Matrix<Base<T>>& AImag ) { EL_DEBUG_CSE const Int m = A.Height(); const Int n = A.Width(); AImag.Resize( m, n ); for( Int j=0; j<n; ++j ) for( Int i=0; i<m; ++i ) AImag(i,j) = ImagPart(A(i,j)); }
bool HasNan( const Matrix<F>& H ) { DEBUG_CSE bool hasNan = false; const Int m = H.Height(); const Int n = H.Width(); for( Int j=0; j<n; ++j ) for( Int i=0; i<m; ++i ) if( !limits::IsFinite(RealPart(H(i,j))) || !limits::IsFinite(ImagPart(H(i,j))) ) hasNan = true; return hasNan; }
void MatrixMarket( const SparseMatrix<T>& A, string basename="matrix" ) { EL_DEBUG_CSE string filename = basename + "." + FileExtension(MATRIX_MARKET); ofstream file( filename.c_str(), std::ios::binary ); if( !file.is_open() ) RuntimeError("Could not open ",filename); // Write the header // ================ { ostringstream os; os << "%%MatrixMarket matrix coordinate "; if( IsComplex<T>::value ) os << "complex "; else os << "real "; os << "general\n"; file << os.str(); } // Write the size line // =================== const Int m = A.Height(); const Int n = A.Width(); const Int numNonzeros = A.NumEntries(); file << BuildString(m," ",n," ",numNonzeros,"\n"); // Write the entries // ================= for( Int e=0; e<numNonzeros; ++e ) { const Int i = A.Row(e); const Int j = A.Col(e); const T value = A.Value(e); if( IsComplex<T>::value ) { file << BuildString(i," ",j," ",RealPart(value)," ",ImagPart(value),"\n"); } else { file << BuildString(i," ",j," ",RealPart(value),"\n"); } } }
static Complex<T> Cast( S alpha ) { return Complex<T>( T(RealPart(alpha)), T(ImagPart(alpha)) ); }
inline Base<F> Arg( const F& alpha ) { return Atan2( ImagPart(alpha), RealPart(alpha) ); }
inline Base<F> FastAbs( const F& alpha ) { return Abs(RealPart(alpha)) + Abs(ImagPart(alpha)); }
void ImagPart ( const AbstractDistMatrix<T>& A, AbstractDistMatrix<Base<T>>& AImag ) { auto imagPart = []( const T& alpha ) { return ImagPart(alpha); }; EntrywiseMap( A, AImag, MakeFunction(imagPart) ); }