Пример #1
0
inline void
MakeNormalUniformSpectrum
( Matrix<Complex<R> >& A, Complex<R> center, R radius )
{
#ifndef RELEASE
    PushCallStack("MakeNormalUniformSpectrum");
#endif
    typedef Complex<R> C;
    if( A.Height() != A.Width() )
        throw std::logic_error("Cannot make a non-square matrix normal");

    // Sample the diagonal matrix D from the ball B_radius(center)
    // and then rotate it with a random Householder similarity transformation:
    //
    //  (I-2uu^H) D (I-2uu^H)^H = D - 2(u (conj(D) u)^H + (D u) u^H) + 
    //                                (4 u^H D u) u u^H
    //

    // Form d and D
    const int n = A.Height();
    std::vector<C> d( n );
    for( int j=0; j<n; ++j )
        d[j] = center + radius*SampleUnitBall<C>();
    Diagonal( d, A );

    // Form u 
    Matrix<C> u( n, 1 );
    MakeUniform( u );
    const R origNorm = Nrm2( u );
    Scale( 1/origNorm, u );

    // Form v := D u
    Matrix<C> v( n, 1 );
    for( int i=0; i<n; ++i )
        v.Set( i, 0, d[i]*u.Get(i,0) );

    // Form w := conj(D) u
    Matrix<C> w( n, 1 );
    for( int i=0; i<n; ++i )
        w.Set( i, 0, Conj(d[i])*u.Get(i,0) );

    // Update A := A - 2(u w^H + v u^H)
    Ger( C(-2), u, w, A );
    Ger( C(-2), v, u, A );

    // Form \gamma := 4 u^H (D u) = 4 (u,Du)
    const C gamma = 4*Dot(u,v);

    // Update A := A + gamma u u^H
    Ger( gamma, u, u, A );
#ifndef RELEASE
    PopCallStack();
#endif
}
Пример #2
0
inline void
Uniform( int m, int n, Matrix<T>& A, T center, typename Base<T>::type radius )
{
#ifndef RELEASE
    PushCallStack("Uniform");
#endif
    A.ResizeTo( m, n );
    MakeUniform( A, center, radius );
#ifndef RELEASE
    PopCallStack();
#endif
}
Пример #3
0
void Uniform( Matrix<T>& A, Int m, Int n, T center, Base<T> radius )
{
    EL_DEBUG_CSE
    A.Resize( m, n );
    MakeUniform( A, center, radius );
}