void NormalUniformSpectrum ( ElementalMatrix<Complex<Real>>& APre, Int n, Complex<Real> center, Real radius ) { EL_DEBUG_CSE typedef Complex<Real> C; DistMatrixWriteProxy<C,C,MC,MR> AProx( APre ); auto& A = AProx.Get(); const Grid& grid = A.Grid(); A.Resize( n, n ); // Form d and D vector<C> d( n ); if( grid.Rank() == 0 ) for( Int j=0; j<n; ++j ) d[j] = SampleBall<C>( center, radius ); mpi::Broadcast( d.data(), n, 0, grid.Comm() ); Diagonal( A, d ); // Apply a Haar matrix from both sides DistMatrix<C> Q(grid); DistMatrix<C,MD,STAR> t(grid); DistMatrix<Real,MD,STAR> s(grid); ImplicitHaar( Q, t, s, n ); // Copy the result into the correct distribution qr::ApplyQ( LEFT, NORMAL, Q, t, s, A ); qr::ApplyQ( RIGHT, ADJOINT, Q, t, s, A ); }
void HermitianUniformSpectrum ( Matrix<F>& A, Int n, Base<F> lower, Base<F> upper ) { DEBUG_ONLY(CallStackEntry cse("HermitianUniformSpectrum")) A.Resize( n, n ); typedef Base<F> Real; const bool isComplex = IsComplex<F>::val; // Form d and D std::vector<F> d( n ); for( Int j=0; j<n; ++j ) d[j] = SampleUniform<Real>( lower, upper ); Diagonal( A, d ); // Apply a Haar matrix from both sides Matrix<F> Q, t; Matrix<Real> s; ImplicitHaar( Q, t, s, n ); qr::ApplyQ( LEFT, NORMAL, Q, t, s, A ); qr::ApplyQ( RIGHT, ADJOINT, Q, t, s, A ); if( isComplex ) { const Int height = A.Height(); for( Int j=0; j<height; ++j ) A.SetImagPart( j, j, Real(0) ); } }
void HermitianUniformSpectrum ( DistMatrix<F,U,V>& A, Int n, Base<F> lower, Base<F> upper ) { DEBUG_ONLY(CallStackEntry cse("HermitianUniformSpectrum")) A.Resize( n, n ); const Grid& grid = A.Grid(); typedef Base<F> Real; const bool isComplex = IsComplex<F>::val; const bool standardDist = ( U == MC && V == MR ); // Form d and D std::vector<F> d( n ); if( grid.Rank() == 0 ) for( Int j=0; j<n; ++j ) d[j] = SampleUniform<Real>( lower, upper ); mpi::Broadcast( d.data(), n, 0, grid.Comm() ); DistMatrix<F> ABackup( grid ); ABackup.AlignWith( A ); Diagonal( ABackup, d ); // Apply a Haar matrix from both sides DistMatrix<F> Q(grid); DistMatrix<F,MD,STAR> t(grid); DistMatrix<Real,MD,STAR> s(grid); ImplicitHaar( Q, t, s, n ); // Copy the result into the correct distribution qr::ApplyQ( LEFT, NORMAL, Q, t, s, ABackup ); qr::ApplyQ( RIGHT, ADJOINT, Q, t, s, ABackup ); A = ABackup; // Force the diagonal to be real-valued if( isComplex ) { const Int localHeight = A.LocalHeight(); const Int localWidth = A.LocalWidth(); for( Int jLoc=0; jLoc<localWidth; ++jLoc ) { const Int j = A.GlobalCol(jLoc); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) { const Int i = A.GlobalRow(iLoc); if( i == j ) A.SetLocalImagPart( iLoc, jLoc, Real(0) ); } } } }
void NormalUniformSpectrum ( Matrix<Complex<Real>>& A, Int n, Complex<Real> center, Real radius ) { EL_DEBUG_CSE typedef Complex<Real> C; A.Resize( n, n ); // Form d and D vector<C> d( n ); for( Int j=0; j<n; ++j ) d[j] = SampleBall<C>( center, radius ); Diagonal( A, d ); // Apply a Haar matrix from both sides Matrix<C> Q, t; Matrix<Real> s; ImplicitHaar( Q, t, s, n ); qr::ApplyQ( LEFT, NORMAL, Q, t, s, A ); qr::ApplyQ( RIGHT, ADJOINT, Q, t, s, A ); }