Ejemplo n.º 1
0
void Overwrite
( Orientation orientation, 
        ElementalMatrix<F>& APre,
  const ElementalMatrix<F>& B, 
        ElementalMatrix<F>& X )
{
    DEBUG_ONLY(CSE cse("ls::Overwrite"))

    DistMatrixReadProxy<F,F,MC,MR> AProx( APre );
    auto& A = AProx.Get();

    DistMatrix<F,MD,STAR> t(A.Grid());
    DistMatrix<Base<F>,MD,STAR> d(A.Grid());

    const Int m = A.Height();
    const Int n = A.Width();
    if( m >= n )
    {
        QR( A, t, d );
        qr::SolveAfter( orientation, A, t, d, B, X );
    }
    else
    {
        LQ( A, t, d );
        lq::SolveAfter( orientation, A, t, d, B, X );
    }
}
Ejemplo n.º 2
0
inline void
HPSDCholesky( UpperOrLower uplo, DistMatrix<Complex<R>,MC,MR>& A )
{
#ifndef RELEASE
    PushCallStack("HPSDCholesky");
#endif
    HPSDSquareRoot( uplo, A );
    hpsd_cholesky::MakeExplicitlyHermitian( uplo, A );

    const Grid& g = A.Grid();
    if( uplo == LOWER )
    {
        DistMatrix<Complex<R>,MD,STAR> t(g);
        LQ( A, t );
        MakeTrapezoidal( LEFT, LOWER, 0, A );
    }
    else
    {
        DistMatrix<Complex<R>,MD,STAR> t(g);
        QR( A, t );
        MakeTrapezoidal( RIGHT, UPPER, 0, A );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Ejemplo n.º 3
0
void Overwrite
( Orientation orientation, 
        ElementalMatrix<F>& APre,
  const ElementalMatrix<F>& B, 
        ElementalMatrix<F>& X )
{
    DEBUG_CSE

    DistMatrixReadProxy<F,F,MC,MR> AProx( APre );
    auto& A = AProx.Get();

    DistMatrix<F,MD,STAR> phase(A.Grid());
    DistMatrix<Base<F>,MD,STAR> signature(A.Grid());

    const Int m = A.Height();
    const Int n = A.Width();
    if( m >= n )
    {
        QR( A, phase, signature );
        qr::SolveAfter( orientation, A, phase, signature, B, X );
    }
    else
    {
        LQ( A, phase, signature );
        lq::SolveAfter( orientation, A, phase, signature, B, X );
    }
}
Ejemplo n.º 4
0
void Explicit( AbstractDistMatrix<F>& L, AbstractDistMatrix<F>& APre )
{
    EL_DEBUG_CSE
    const Grid& g = APre.Grid();

    DistMatrixReadWriteProxy<F,F,MC,MR> AProx( APre );
    auto& A = AProx.Get();

    DistMatrix<F,MD,STAR> householderScalars(g);
    DistMatrix<Base<F>,MD,STAR> signature(g);
    LQ( A, householderScalars, signature );

    const Int m = A.Height();
    const Int n = A.Width();
    const Int minDim = Min(m,n);
    auto AL = A( IR(0,m), IR(0,minDim) );
    Copy( AL, L );
    MakeTrapezoidal( LOWER, L );

    // TODO: Replace this with an in-place expansion of Q
    DistMatrix<F> Q(g);
    Identity( Q, A.Height(), A.Width() );
    lq::ApplyQ( RIGHT, NORMAL, A, householderScalars, signature, Q );
    Copy( Q, APre );
}
Ejemplo n.º 5
0
void CCBuffer::writeData(const char* p_data, unsigned int u_len)
{
	DO_ASSERT(LQ(p_data, LD(u_len,0)), "LQ(p_data, LD(u_len,0))");
	_reallocBufferSizeInChanged(u_len);
	memcpy(CA(_p_buffer, _u_write_pos), p_data, u_len);
	AA(_u_write_pos, u_len);
	MAXA(_u_content_size, _u_write_pos);
}
Ejemplo n.º 6
0
void CCBuffer::readData(char* p_out_data, unsigned int u_len)
{
	BEGIN_IF(isReadable(u_len))
	memcpy(p_out_data, CA(_p_buffer, _u_read_pos), u_len);
	AA(_u_read_pos, u_len);
	BEGIN_ELSE_IF(LQ(LDE(CS(_u_content_size, _u_read_pos),0), LNE(u_len, 0)))
	DO_ASSIGN(u_len, CS(_u_content_size, _u_read_pos));
	memcpy(p_out_data, CA(_p_buffer, _u_read_pos), u_len);
	AA(_u_read_pos, u_len);
	END_IF
}
Ejemplo n.º 7
0
inline void
ExplicitLQHelper( Matrix<Real>& A )
{
    LQ( A );

    // TODO: Replace this with an in-place expansion of Q
    Matrix<Real> Q;
    Identity( A.Height(), A.Width(), Q );
    ApplyPackedReflectors( RIGHT, UPPER, HORIZONTAL, BACKWARD, 0, A, Q );
    A = Q;
}
Ejemplo n.º 8
0
void ExplicitUnitary( Matrix<F>& A )
{
    EL_DEBUG_CSE
    Matrix<F> householderScalars;
    Matrix<Base<F>> signature;
    LQ( A, householderScalars, signature );

    // TODO: Replace this with an in-place expansion of Q
    Matrix<F> Q;
    Identity( Q, A.Height(), A.Width() );
    lq::ApplyQ( RIGHT, NORMAL, A, householderScalars, signature, Q );
    A = Q;
}
Ejemplo n.º 9
0
inline void
ExplicitLQHelper( DistMatrix<Real>& A )
{
    LQ( A );

    // TODO: Replace this with an in-place expansion of Q
    const Grid& g = A.Grid();
    DistMatrix<Real> Q( g );
    Q.AlignWith( A );
    Identity( A.Height(), A.Width(), Q );
    ApplyPackedReflectors( RIGHT, UPPER, HORIZONTAL, BACKWARD, 0, A, Q );
    A = Q;
}
Ejemplo n.º 10
0
void ExplicitTriang( Matrix<F>& A )
{
    DEBUG_ONLY(CallStackEntry cse("lq::ExplicitTriang"))
    Matrix<F> t;
    Matrix<Base<F>> d;
    LQ( A, t, d );

    const Int m = A.Height();
    const Int n = A.Width();
    const Int minDim = Min(m,n);
    A.Resize( m, minDim );
    MakeTrapezoidal( LOWER, A );
}
Ejemplo n.º 11
0
void ExplicitTriang( Matrix<F>& A )
{
    EL_DEBUG_CSE
    Matrix<F> householderScalars;
    Matrix<Base<F>> signature;
    LQ( A, householderScalars, signature );

    const Int m = A.Height();
    const Int n = A.Width();
    const Int minDim = Min(m,n);
    A.Resize( m, minDim );
    MakeTrapezoidal( LOWER, A );
}
Ejemplo n.º 12
0
void ExplicitTriang( AbstractDistMatrix<F>& A )
{
    EL_DEBUG_CSE
    const Grid& g = A.Grid();
    DistMatrix<F,MD,STAR> householderScalars(g);
    DistMatrix<Base<F>,MD,STAR> signature(g);
    LQ( A, householderScalars, signature );

    const Int m = A.Height();
    const Int n = A.Width();
    const Int minDim = Min(m,n);
    A.Resize( m, minDim );
    MakeTrapezoidal( LOWER, A );
}
Ejemplo n.º 13
0
inline void
ExplicitLQHelper( Matrix<Complex<Real> >& L, Matrix<Complex<Real> >& A )
{
    Matrix<Complex<Real> > t;
    LQ( A, t );
    L = A;
    MakeTrapezoidal( LEFT, LOWER, 0, L );

    // TODO: Replace this with an in-place expansion of Q
    Matrix<Complex<Real> > Q;
    Identity( A.Height(), A.Width(), Q );
    ApplyPackedReflectors
    ( RIGHT, UPPER, HORIZONTAL, BACKWARD, UNCONJUGATED, 0, A, t, Q );
    A = Q;
}
Ejemplo n.º 14
0
inline void
ExplicitLQHelper( DistMatrix<Complex<Real> >& A )
{
    const Grid& g = A.Grid();
    DistMatrix<Complex<Real>,MD,STAR> t( g );
    LQ( A, t );

    // TODO: Replace this with an in-place expansion of Q
    DistMatrix<Complex<Real> > Q( g );
    Q.AlignWith( A );
    Identity( A.Height(), A.Width(), Q );
    ApplyPackedReflectors
    ( RIGHT, UPPER, HORIZONTAL, BACKWARD, UNCONJUGATED, 0, A, t, Q );
    A = Q;
}
Ejemplo n.º 15
0
inline void
Explicit( Matrix<F>& A )
{
#ifndef RELEASE
    CallStackEntry cse("lq::Explicit");
#endif
    Matrix<F> t;
    LQ( A, t );

    // TODO: Replace this with an in-place expansion of Q
    Matrix<F> Q;
    Identity( Q, A.Height(), A.Width() );
    lq::ApplyQ( RIGHT, NORMAL, A, t, Q );
    A = Q;
}
Ejemplo n.º 16
0
inline void
Explicit( DistMatrix<F>& A )
{
#ifndef RELEASE
    CallStackEntry cse("lq::Explicit");
#endif
    const Grid& g = A.Grid();
    DistMatrix<F,MD,STAR> t( g );
    LQ( A, t );

    // TODO: Replace this with an in-place expansion of Q
    DistMatrix<F> Q( g );
    Q.AlignWith( A );
    Identity( Q, A.Height(), A.Width() );
    lq::ApplyQ( RIGHT, NORMAL, A, t, Q );
    A = Q;
}
Ejemplo n.º 17
0
void ExplicitUnitary( AbstractDistMatrix<F>& APre )
{
    EL_DEBUG_CSE
    const Grid& g = APre.Grid();

    DistMatrixReadWriteProxy<F,F,MC,MR> AProx( APre );
    auto& A = AProx.Get();

    DistMatrix<F,MD,STAR> householderScalars(g);
    DistMatrix<Base<F>,MD,STAR> signature(g);
    LQ( A, householderScalars, signature );

    // TODO: Replace this with an in-place expansion of Q
    DistMatrix<F> Q(g);
    Q.AlignWith( A );
    Identity( Q, A.Height(), A.Width() );
    lq::ApplyQ( RIGHT, NORMAL, A, householderScalars, signature, Q );
    Copy( Q, APre );
}
Ejemplo n.º 18
0
inline void
HPSDCholesky( UpperOrLower uplo, DistMatrix<R>& A )
{
#ifndef RELEASE
    CallStackEntry entry("HPSDCholesky");
#endif
    HPSDSquareRoot( uplo, A );
    MakeHermitian( uplo, A );

    if( uplo == LOWER )
    {
        LQ( A );
        MakeTriangular( LOWER, A );
    }
    else
    {
        QR( A );
        MakeTriangular( UPPER, A );
    }
}
Ejemplo n.º 19
0
void Explicit( Matrix<F>& L, Matrix<F>& A )
{
    EL_DEBUG_CSE
    Matrix<F> householderScalars;
    Matrix<Base<F>> signature;
    LQ( A, householderScalars, signature );

    const Int m = A.Height();
    const Int n = A.Width();
    const Int minDim = Min(m,n);
    auto AL = A( IR(0,m), IR(0,minDim) );
    L = AL;
    MakeTrapezoidal( LOWER, L );

    // TODO: Replace this with an in-place expansion of Q
    Matrix<F> Q;
    Identity( Q, A.Height(), A.Width() );
    lq::ApplyQ( RIGHT, NORMAL, A, householderScalars, signature, Q );
    A = Q;
}
Ejemplo n.º 20
0
void Merge(int SR[], int TR[], int i, int m, int n) {
	// 将有序的SR[i..m]和SR[m+1..n]归并为有序的TR[i..n]
	int j, k;
	for (j = m + 1, k = i; i <= m&&j <= n; ++k) {
		if (LQ(SR[i], SR[j])) {
			TR[k] = SR[i++];
		} else {
			TR[k] = SR[j++];
		}
	}
	if (i <= m) {
		for (j = i; j <= m; j++) {
			TR[k++] = SR[j];
		}
	}
	if (j <= n) {
		for (i = j; i <= n; i++) {
			TR[k++] = SR[i];
		}
	}
}// Merge
Ejemplo n.º 21
0
inline void
HPSDCholesky( UpperOrLower uplo, DistMatrix<R,MC,MR>& A )
{
#ifndef RELEASE
    PushCallStack("HPSDCholesky");
#endif
    HPSDSquareRoot( uplo, A );
    hpsd_cholesky::MakeExplicitlyHermitian( uplo, A );

    if( uplo == LOWER )
    {
        LQ( A );
        MakeTrapezoidal( LEFT, LOWER, 0, A );
    }
    else
    {
        QR( A );
        MakeTrapezoidal( RIGHT, UPPER, 0, A );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Ejemplo n.º 22
0
inline void
HPSDCholesky( UpperOrLower uplo, DistMatrix<Complex<R> >& A )
{
#ifndef RELEASE
    CallStackEntry entry("HPSDCholesky");
#endif
    HPSDSquareRoot( uplo, A );
    MakeHermitian( uplo, A );

    const Grid& g = A.Grid();
    if( uplo == LOWER )
    {
        DistMatrix<Complex<R>,MD,STAR> t(g);
        LQ( A, t );
        MakeTriangular( LOWER, A );
    }
    else
    {
        DistMatrix<Complex<R>,MD,STAR> t(g);
        QR( A, t );
        MakeTriangular( UPPER, A );
    }
}
Ejemplo n.º 23
0
void Overwrite
( Orientation orientation, 
        Matrix<F>& A,
  const Matrix<F>& B, 
        Matrix<F>& X )
{
    DEBUG_ONLY(CSE cse("ls::Overwrite"))

    Matrix<F> t;
    Matrix<Base<F>> d;

    const Int m = A.Height();
    const Int n = A.Width();
    if( m >= n )
    {
        QR( A, t, d );
        qr::SolveAfter( orientation, A, t, d, B, X );
    }
    else
    {
        LQ( A, t, d );
        lq::SolveAfter( orientation, A, t, d, B, X );
    }
}
Ejemplo n.º 24
0
void Overwrite
( Orientation orientation, 
        Matrix<F>& A,
  const Matrix<F>& B, 
        Matrix<F>& X )
{
    DEBUG_CSE

    Matrix<F> phase;
    Matrix<Base<F>> signature;

    const Int m = A.Height();
    const Int n = A.Width();
    if( m >= n )
    {
        QR( A, phase, signature );
        qr::SolveAfter( orientation, A, phase, signature, B, X );
    }
    else
    {
        LQ( A, phase, signature );
        lq::SolveAfter( orientation, A, phase, signature, B, X );
    }
}
Ejemplo n.º 25
0
inline void
HouseholderSolve
( Orientation orientation, 
  DistMatrix<Complex<R> >& A, 
  const DistMatrix<Complex<R> >& B,
        DistMatrix<Complex<R> >& X )
{
#ifndef RELEASE
    PushCallStack("HouseholderSolve");
    if( A.Grid() != B.Grid() || A.Grid() != X.Grid() )
        throw std::logic_error("Grids do not match");
    if( orientation == TRANSPOSE )
        throw std::logic_error("Invalid orientation");
#endif
    typedef Complex<R> C;
    const Grid& g = A.Grid();

    // TODO: Add scaling
    const int m = A.Height();
    const int n = A.Width();
    DistMatrix<C,MD,STAR> t( g );
    if( orientation == NORMAL )
    {
        if( m != B.Height() )
            throw std::logic_error("A and B do not conform");

        if( m >= n )
        {
            // Overwrite A with its packed QR factorization (and store the 
            // corresponding Householder scalars in t)
            QR( A, t );

            // Copy B into X
            X = B;

            // Apply Q' to X
            ApplyPackedReflectors
            ( LEFT, LOWER, VERTICAL, FORWARD, CONJUGATED, 0, A, t, X );

            // Shrink X to its new height
            X.ResizeTo( n, X.Width() );

            // Solve against R (checking for singularities)
            DistMatrix<C> AT( g );
            LockedView( AT, A, 0, 0, n, n );
            Trsm( LEFT, UPPER, NORMAL, NON_UNIT, C(1), AT, X, true );
        }
        else
        {
            // Overwrite A with its packed LQ factorization (and store the
            // corresponding Householder scalars in it)
            LQ( A, t );

            // Copy B into X
            X.ResizeTo( n, B.Width() );
            DistMatrix<C> XT( g ),
                          XB( g );
            PartitionDown( X, XT,
                              XB, m );
            XT = B;
            Zero( XB );

            // Solve against L (checking for singularities)
            DistMatrix<C> AL( g );
            LockedView( AL, A, 0, 0, m, m );
            Trsm( LEFT, LOWER, NORMAL, NON_UNIT, C(1), AL, XT, true );

            // Apply Q' to X 
            ApplyPackedReflectors
            ( LEFT, UPPER, HORIZONTAL, BACKWARD, CONJUGATED, 0, A, t, X );
        }
    }
    else // orientation == ADJOINT
    {
        if( n != B.Height() )
            throw std::logic_error("A and B do not conform");

        if( m >= n )
        {
            // Overwrite A with its packed QR factorization (and store the 
            // corresponding Householder scalars in t)
            QR( A, t );

            // Copy B into X
            X.ResizeTo( m, B.Width() );
            DistMatrix<C> XT( g ),
                          XB( g );
            PartitionDown( X, XT,
                              XB, n );
            XT = B;
            Zero( XB );

            // Solve against R' (checking for singularities)
            DistMatrix<C> AT( g );
            LockedView( AT, A, 0, 0, n, n );
            Trsm( LEFT, UPPER, ADJOINT, NON_UNIT, C(1), AT, XT, true );

            // Apply Q to X
            ApplyPackedReflectors
            ( LEFT, LOWER, VERTICAL, BACKWARD, UNCONJUGATED, 0, A, t, X );
        }
        else
        {
            // Overwrite A with its packed LQ factorization (and store the
            // corresponding Householder scalars in t)
            LQ( A, t );

            // Copy B into X
            X = B;

            // Apply Q to X
            ApplyPackedReflectors
            ( LEFT, UPPER, HORIZONTAL, FORWARD, UNCONJUGATED, 0, A, t, X );

            // Shrink X to its new height
            X.ResizeTo( m, X.Width() );

            // Solve against L' (check for singularities)
            DistMatrix<C> AL( g );
            LockedView( AL, A, 0, 0, m, m );
            Trsm( LEFT, LOWER, ADJOINT, NON_UNIT, C(1), AL, X, true );
        }
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Ejemplo n.º 26
0
void CCBuffer::writeString(const char* p_data)
{
	DO_ASSERT(LQ(p_data, LD(strlen(p_data), 0)), "p_data, LD(strlen(p_data), 0)");
	writeData(p_data, strlen(p_data));
}
Ejemplo n.º 27
0
void CCBuffer::writeLengthAndString(const char* p_data)
{
	DO_ASSERT(LQ(p_data, LD(strlen(p_data), 0)), "p_data, LD(strlen(p_data), 0)");
	writeInt(strlen(p_data));
	writeString(p_data);
}
Ejemplo n.º 28
0
inline void
HouseholderSolve
( Orientation orientation, 
  Matrix<R>& A, const Matrix<R>& B,
                      Matrix<R>& X )
{
#ifndef RELEASE
    PushCallStack("HouseholderSolve");
#endif
    // TODO: Add scaling
    const int m = A.Height();
    const int n = A.Width();
    if( orientation == NORMAL )
    {
        if( m != B.Height() )
            throw std::logic_error("A and B do not conform");

        if( m >= n )
        {
            // Overwrite A with its packed QR factorization
            QR( A );

            // Copy B into X
            X = B;

            // Apply Q' to X
            ApplyPackedReflectors( LEFT, LOWER, VERTICAL, FORWARD, 0, A, X );

            // Shrink X to its new height
            X.ResizeTo( n, X.Width() );

            // Solve against R (checking for singularities)
            Matrix<R> AT;
            LockedView( AT, A, 0, 0, n, n );
            Trsm( LEFT, UPPER, NORMAL, NON_UNIT, R(1), AT, X, true );
        }
        else
        {
            // Overwrite A with its packed LQ factorization
            LQ( A );

            // Copy B into X
            X.ResizeTo( n, B.Width() );
            Matrix<R> XT,
                      XB;
            PartitionDown( X, XT,
                              XB, m );
            XT = B;
            Zero( XB );

            // Solve against L (checking for singularities)
            Matrix<R> AL;
            LockedView( AL, A, 0, 0, m, m );
            Trsm( LEFT, LOWER, NORMAL, NON_UNIT, R(1), AL, XT, true );

            // Apply Q' to X 
            ApplyPackedReflectors( LEFT, UPPER, HORIZONTAL, BACKWARD, 0, A, X );
        }
    }
    else // orientation == ADJOINT
    {
        if( n != B.Height() )
            throw std::logic_error("A and B do not conform");

        if( m >= n )
        {
            // Overwrite A with its packed QR factorization
            QR( A );

            // Copy B into X
            X.ResizeTo( m, B.Width() );
            Matrix<R> XT,
                      XB;
            PartitionDown( X, XT,
                              XB, n );
            XT = B; 
            Zero( XB );

            // Solve against R' (checking for singularities)
            Matrix<R> AT;
            LockedView( AT, A, 0, 0, n, n );
            Trsm( LEFT, UPPER, ADJOINT, NON_UNIT, R(1), AT, XT, true );

            // Apply Q to X
            ApplyPackedReflectors( LEFT, LOWER, VERTICAL, BACKWARD, 0, A, X );
        }
        else
        {
            // Overwrite A with its packed LQ factorization
            LQ( A );

            // Copy B into X
            X = B;

            // Apply Q to X
            ApplyPackedReflectors( LEFT, UPPER, HORIZONTAL, FORWARD, 0, A, X );

            // Shrink X to its new size
            X.ResizeTo( m, X.Width() );

            // Solve against L' (check for singularities)
            Matrix<R> AL;
            LockedView( AL, A, 0, 0, m, m );
            Trsm( LEFT, LOWER, ADJOINT, NON_UNIT, R(1), AL, X, true );
        }
    }
#ifndef RELEASE
    PopCallStack();
#endif
}