Example #1
0
inline typename Base<F>::type
EntrywiseOneNorm( const Matrix<F>& A )
{
#ifndef RELEASE
    PushCallStack("EntrywiseOneNorm");
#endif
    typedef typename Base<F>::type R;
    R norm = 0;
    const int width = A.Width();
    const int height = A.Height();
    for( int j=0; j<width; ++j )
        for( int i=0; i<height; ++i )
            norm += Abs(A.Get(i,j));
#ifndef RELEASE
    PopCallStack();
#endif
    return norm;
}
Example #2
0
TwoNormUpperBound( const Matrix<F>& A )
{
#ifndef RELEASE
    CallStackEntry entry("TwoNormUpperBound");
#endif
    typedef BASE(F) R;
    const R m = A.Height();
    const R n = A.Width();

    const R maxNorm = MaxNorm( A );
    const R oneNorm = OneNorm( A );
    const R infNorm = InfinityNorm( A );

    R upperBound = std::min( Sqrt(m*n)*maxNorm, Sqrt(m)*infNorm );
    upperBound = std::min( upperBound, Sqrt(n)*oneNorm );
    upperBound = std::min( upperBound, Sqrt( oneNorm*infNorm ) );
    return upperBound;
}
Example #3
0
InfinityNorm( const Matrix<F>& A )
{
#ifndef RELEASE
    CallStackEntry entry("InfinityNorm");
#endif
    typedef BASE(F) R;
    R maxRowSum = 0;
    const Int height = A.Height();
    const Int width = A.Width();
    for( Int i=0; i<height; ++i )
    {
        R rowSum = 0;
        for( Int j=0; j<width; ++j )
            rowSum += Abs(A.Get(i,j));
        maxRowSum = std::max( maxRowSum, rowSum );
    }
    return maxRowSum;
}
Example #4
0
void MakeTrapezoidal( UpperOrLower uplo, Matrix<T>& A, Int offset )
{
    EL_DEBUG_CSE
    const Int height = A.Height();
    const Int width = A.Width();
    const Int ldim = A.LDim();
    T* buffer = A.Buffer();

    if( uplo == LOWER )
    {
        EL_PARALLEL_FOR
        for( Int j=Max(0,offset+1); j<width; ++j )
        {
            const Int lastZeroRow = j-offset-1;
            const Int numZeroRows = Min( lastZeroRow+1, height );
            MemZero( &buffer[j*ldim], numZeroRows );
        }
    }
Example #5
0
void MaxEig
( const Matrix<Real>& x, 
        Matrix<Real>& maxEigs,
  const Matrix<Int>& orders, 
  const Matrix<Int>& firstInds )
{
    DEBUG_ONLY(CSE cse("soc::MaxEig"))
    soc::LowerNorms( x, maxEigs, orders, firstInds );

          Real* maxEigBuf = maxEigs.Buffer();
    const Real* xBuf = x.LockedBuffer();
    const Int* firstIndBuf = firstInds.LockedBuffer();

    const Int height = x.Height();
    for( Int i=0; i<height; ++i )
        if( i == firstIndBuf[i] ) 
            maxEigBuf[i] = xBuf[i]+maxEigBuf[i];
}
Example #6
0
inline void HermitianSVD
( UpperOrLower uplo, Matrix<F>& A, Matrix<BASE(F)>& s )
{
#ifndef RELEASE
    CallStackEntry entry("HermitianSVD");
#endif
#if 1
    // Grab the eigenvalues of A
    HermitianEig( uplo, A, s );

    // Set the singular values to the absolute value of the eigenvalues
    for( Int i=0; i<s.Height(); ++i )
        s.Set(i,0,Abs(s.Get(i,0)));
#else
    MakeHermitian( uplo, A );
    SVD( A, s );
#endif 
}
Example #7
0
void ImplicitQQuadraticSeed
( const Matrix<Real>& H,
  const Complex<Real>& shift0,
  const Complex<Real>& shift1,
        Real* v )
{
    EL_DEBUG_CSE
    const Real zero(0);
    const Int n = H.Height();
    EL_DEBUG_ONLY(
      if( n != 2 && n != 3 )
          LogicError("Expected n to be 2 or 3");
      const bool bothReal = ( shift0.imag() == zero && shift1.imag() == zero );
      const bool conjugate = ( shift0.imag() == -shift1.imag() );
      if( !bothReal && !conjugate )
          LogicError("Assumed shifts were either both real or conjugates");
    )
    if( n == 2 )
Example #8
0
void EntrywiseMap( Matrix<T>& A, function<T(const T&)> func )
{
    EL_DEBUG_CSE
    const Int m = A.Height();
    const Int n = A.Width();
    T* ABuf = A.Buffer();
    const Int ALDim = A.LDim();

    // Iterate over single loop if memory is contiguous. Otherwise
    // iterate over double loop.
    if( ALDim == m )
    {
        EL_PARALLEL_FOR
        for( Int i=0; i<m*n; ++i )
        {
            ABuf[i] = func(ABuf[i]);
        }
    }
Example #9
0
Base<Field> MinAbsNonzero( const Matrix<Field>& A, Base<Field> upperBound )
{
    EL_DEBUG_CSE
    typedef Base<Field> Real;
    const Int m = A.Height();
    const Int n = A.Width();
    Real minAbs = upperBound;
    for( Int j=0; j<n; ++j )
    {
        for( Int i=0; i<m; ++i )
        {
            const Real alphaAbs = Abs(A(i,j));
            if( alphaAbs > Real(0) )
                minAbs = Min(minAbs,alphaAbs);
        }
    }
    return minAbs;
}
Example #10
0
inline void
CheckInputNT
( Orientation orientationOfB,
  const Matrix<T>& A, const Matrix<T>& B, const Matrix<T>& C )
{
    if( orientationOfB == NORMAL )
        throw std::logic_error("B must be (Conjugate)Transpose'd");
    if( A.Height() != C.Height() || B.Height() != C.Width() ||
        A.Width()  != B.Width()  || A.Height() != B.Height() )
    {
        std::ostringstream msg;
        msg << "Nonconformal LocalTrrk: \n"
            << "  A ~ " << A.Height() << " x "
                        << A.Width()  << "\n"
            << "  B ~ " << B.Height() << " x "
                        << B.Width()  << "\n"
            << "  C ~ " << C.Height() << " x " << C.Width() << "\n";
        throw std::logic_error( msg.str().c_str() );
    }
}
Example #11
0
void TestCorrectness
( bool pivoted, bool print, 
  const Matrix<F>& A,
  const Matrix<Int>& p,
  const Matrix<F>& AOrig )
{
    typedef Base<F> Real;
    const Int m = AOrig.Height();

    cout << "Testing error..." << endl;

    // Generate random right-hand sides
    Matrix<F> X, Y;
    Uniform( X, m, 100 );
    Y = X;
    if( pivoted )
        ApplyRowPivots( Y, p );

    // Solve against the (pivoted) right-hand sides
    Trsm( LEFT, LOWER, NORMAL, UNIT, F(1), A, Y );
    Trsm( LEFT, UPPER, NORMAL, NON_UNIT, F(1), A, Y );

    // Now investigate the residual, ||AOrig Y - X||_oo
    const Real oneNormOfX = OneNorm( X );
    const Real infNormOfX = InfinityNorm( X );
    const Real frobNormOfX = FrobeniusNorm( X );
    Gemm( NORMAL, NORMAL, F(-1), AOrig, Y, F(1), X );
    const Real oneNormOfError = OneNorm( X );
    const Real infNormOfError = InfinityNorm( X );
    const Real frobNormOfError = FrobeniusNorm( X );
    const Real oneNormOfA = OneNorm( AOrig );
    const Real infNormOfA = InfinityNorm( AOrig );
    const Real frobNormOfA = FrobeniusNorm( AOrig );

    cout << "||A||_1                  = " << oneNormOfA << "\n"
         << "||A||_oo                 = " << infNormOfA << "\n"
         << "||A||_F                  = " << frobNormOfA << "\n"
         << "||X||_1                  = " << oneNormOfX << "\n"
         << "||X||_oo                 = " << infNormOfX << "\n"
         << "||X||_F                  = " << frobNormOfX << "\n"
         << "||A U^-1 L^-1 X - X||_1  = " << oneNormOfError << "\n"
         << "||A U^-1 L^-1 X - X||_oo = " << infNormOfError << "\n"
         << "||A U^-1 L^-1 X - X||_F  = " << frobNormOfError << endl;
}
Example #12
0
void TestCorrectness
( UpperOrLower uplo, const Matrix<F>& T, Base<F> alpha, const Matrix<F>& V,
  const Matrix<F>& A )
{
    typedef Base<F> Real;
    const Int m = V.Height();

    Matrix<F> B( A );
    Herk( uplo, NORMAL, alpha, V, Real(1), B );

    // Test correctness by multiplying a random set of vectors by 
    // A + alpha V V^H, then using the Cholesky factorization to solve.
    Matrix<F> X, Y;
    Uniform( X, m, 100 );
    Zeros( Y, m, 100 );
    Hemm( LEFT, uplo, F(1), B, X, F(0), Y );
    const Real maxNormT = MaxNorm( T );
    const Real maxNormB = HermitianMaxNorm( uplo, B );
    const Real infNormB = HermitianInfinityNorm( uplo, B );
    const Real frobNormB = HermitianFrobeniusNorm( uplo, B );
    const Real oneNormY = OneNorm( Y );
    const Real infNormY = InfinityNorm( Y );
    const Real frobNormY = FrobeniusNorm( Y );

    cholesky::SolveAfter( uplo, NORMAL, T, Y );
    X -= Y;
    const Real oneNormE = OneNorm( X );
    const Real infNormE = InfinityNorm( X );
    const Real frobNormE = FrobeniusNorm( X );

    if( mpi::WorldRank() == 0 )
    {
        cout << "||T||_max = " << maxNormT << "\n"
             << "||B||_max = " << maxNormB << "\n"
             << "||B||_1   = " << infNormB << "\n"
             << "||B||_F   = " << frobNormB << "\n"
             << "||Y||_1   = " << oneNormY << "\n"
             << "||Y||_oo  = " << infNormY << "\n"
             << "||Y||_F   = " << frobNormY << "\n"
             << "||X - inv(B) X||_1  = " << oneNormE << "\n"
             << "||X - inv(B) X||_oo = " << infNormE << "\n"
             << "||X - inv(B) X||_F  = " << frobNormE << endl;
    }
}
Example #13
0
inline void 
CheckInputNN
( const Matrix<T>& A, const Matrix<T>& B, const Matrix<T>& C )
{
    if( A.Height() != C.Height() || B.Width()  != C.Width() ||
        A.Width()  != B.Height() || A.Height() != B.Width() )
    {
        std::ostringstream msg;
        msg << "Nonconformal LocalTrrk: \n"
            << "  A ~ " << A.Height() << " x "
                        << A.Width()  << "\n"
            << "  B ~ " << B.Height() << " x "
                        << B.Width()  << "\n"
            << "  C ~ " << C.Height() << " x " << C.Width() << "\n";
        throw std::logic_error( msg.str().c_str() );
    }
}
Example #14
0
void SOCApply
( const Matrix<Real>& x, 
  const Matrix<Real>& y,
        Matrix<Real>& z,
  const Matrix<Int>& orders, 
  const Matrix<Int>& firstInds )
{
    DEBUG_ONLY(CSE cse("SOCApply"))
    SOCDots( x, y, z, orders, firstInds );
    auto xRoots = x;
    auto yRoots = y;
    ConeBroadcast( xRoots, orders, firstInds );
    ConeBroadcast( yRoots, orders, firstInds );
    const Int height = x.Height();
    for( Int i=0; i<height; ++i )
        if( i != firstInds.Get(i,0) )
            z.Update( i, 0, xRoots.Get(i,0)*y.Get(i,0) +
                            yRoots.Get(i,0)*x.Get(i,0) );
}
Example #15
0
inline void
TrrkTNKernel
( UpperOrLower uplo,
  Orientation orientationOfA,
  T alpha, const Matrix<T>& A, const Matrix<T>& B,
  T beta,        Matrix<T>& C )
{
#ifndef RELEASE
    PushCallStack("TrrkTNKernel");
    CheckInputTN( orientationOfA, A, B, C );
#endif
    Matrix<T> AL, AR;
    Matrix<T> BL, BR;
    Matrix<T> CTL, CTR,
              CBL, CBR;
    Matrix<T> DTL, DBR;

    const int half = C.Height()/2;
    ScaleTrapezoid( beta, LEFT, uplo, 0, C );
    LockedPartitionRight( A, AL, AR, half );
    LockedPartitionRight( B, BL, BR, half );
    PartitionDownDiagonal
    ( C, CTL, CTR,
         CBL, CBR, half );

    DTL.ResizeTo( CTL.Height(), CTL.Width() );
    DBR.ResizeTo( CBR.Height(), CBR.Width() );
    //------------------------------------------------------------------------//
    if( uplo == LOWER )
        Gemm( orientationOfA, NORMAL, alpha, AR, BL, T(1), CBL );
    else
        Gemm( orientationOfA, NORMAL, alpha, AL, BR, T(1), CTR );

    Gemm( orientationOfA, NORMAL, alpha, AL, BL, T(0), DTL );
    AxpyTriangle( uplo, T(1), DTL, CTL );

    Gemm( orientationOfA, NORMAL, alpha, AR, BR, T(0), DBR );
    AxpyTriangle( uplo, T(1), DBR, CBR );
    //------------------------------------------------------------------------//
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #16
0
inline void
CholeskyUVar3( Matrix<F>& A )
{
#ifndef RELEASE
    PushCallStack("internal::CholeskyUVar3");
    if( A.Height() != A.Width() )
        throw std::logic_error
        ("Can only compute Cholesky factor of square matrices");
#endif
    // Matrix views
    Matrix<F> 
        ATL, ATR,  A00, A01, A02,
        ABL, ABR,  A10, A11, A12,
                   A20, A21, A22;

    // Start the algorithm
    PartitionDownDiagonal
    ( A, ATL, ATR,
         ABL, ABR, 0 ); 
    while( ABR.Height() > 0 )
    {
        RepartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, /**/ A01, A02,
         /*************/ /******************/
               /**/       A10, /**/ A11, A12,
          ABL, /**/ ABR,  A20, /**/ A21, A22 );

        //--------------------------------------------------------------------//
        CholeskyUVar3Unb( A11 );
        Trsm( LEFT, UPPER, ADJOINT, NON_UNIT, F(1), A11, A12 );
        Herk( UPPER, ADJOINT, F(-1), A12, F(1), A22 );
        //--------------------------------------------------------------------//

        SlidePartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, A01, /**/ A02,
               /**/       A10, A11, /**/ A12,
         /*************/ /******************/
          ABL, /**/ ABR,  A20, A21, /**/ A22 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #17
0
void MatrixMarket( const Matrix<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 array ";
        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();
    file << BuildString(m," ",n,"\n");
    
    // Write the entries
    // =================
    for( Int j=0; j<n; ++j )
    {
        for( Int i=0; i<m; ++i )
        {
            ostringstream os;
            os << A.GetRealPart(i,j);
            if( IsComplex<T>::value )
                os << " " << A.GetImagPart(i,j);
            os << "\n";
            file << os.str();
        }
    }
}
Example #18
0
inline void
MakeHilbert( Matrix<F>& A )
{
#ifndef RELEASE
    PushCallStack("MakeHilbert");
#endif
    const int m = A.Height();
    const int n = A.Width();
    if( m != n )
        throw std::logic_error("Cannot make a non-square matrix Hilbert");

    const F one = static_cast<F>(1);
    for( int j=0; j<n; ++j )
        for( int i=0; i<m; ++i )
            A.Set( i, j, one/(i+j+1) );
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #19
0
inline void
LU( Matrix<F>& A )
{
#ifndef RELEASE
    PushCallStack("LU");
#endif
    // Matrix views 
    Matrix<F>
        ATL, ATR,  A00, a01,     A02,  alpha21T,
        ABL, ABR,  a10, alpha11, a12,  a21B,
                   A20, a21,     A22;

    PushBlocksizeStack( 1 );
    PartitionDownDiagonal
    ( A, ATL, ATR,
         ABL, ABR, 0 );
    while( ATL.Height() < A.Height() && ATL.Width() < A.Width() )
    {
        RepartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, /**/ a01,     A02,
         /*************/ /**********************/
               /**/       a10, /**/ alpha11, a12,
          ABL, /**/ ABR,  A20, /**/ a21,     A22 );

        //--------------------------------------------------------------------//
        F alpha = alpha11.Get(0,0);
        if( alpha == static_cast<F>(0) )
            throw SingularMatrixException();
        Scal( static_cast<F>(1)/alpha, a21 );
        Geru( (F)-1, a21, a12, A22 );
        //--------------------------------------------------------------------//

        SlidePartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, a01,     /**/ A02,
               /**/       a10, alpha11, /**/ a12,
         /*************/ /**********************/
          ABL, /**/ ABR,  A20, a21,     /**/ A22 );
    }
    PopBlocksizeStack();
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #20
0
inline void
Print( const Matrix<T>& A, std::string title="", std::ostream& os=std::cout )
{
#ifndef RELEASE
    CallStackEntry entry("Print");
#endif
    if( title != "" )
        os << title << std::endl;

    const Int height = A.Height();
    const Int width = A.Width();
    for( Int i=0; i<height; ++i )
    {
        for( Int j=0; j<width; ++j )
            os << A.Get(i,j) << " ";
        os << std::endl;
    }
    os << std::endl;
}
Example #21
0
inline void
DiagonalScale
( LeftOrRight side, Orientation orientation,
  const Matrix<T>& d, Matrix<T>& X )
{
#ifndef RELEASE
    PushCallStack("DiagonalScale");
#endif
    const int m = X.Height();
    const int n = X.Width();
    const int ldim = X.LDim();
    if( side == LEFT )
    {
        for( int i=0; i<m; ++i )
        {
            const T delta = d.Get(i,0);
            T* XBuffer = X.Buffer(i,0);
            if( orientation == ADJOINT )
                for( int j=0; j<n; ++j )
                    XBuffer[j*ldim] *= Conj(delta);
            else
                for( int j=0; j<n; ++j )
                    XBuffer[j*ldim] *= delta;
        }
    }
    else
    {
        for( int j=0; j<n; ++j )
        {
            const T delta = d.Get(j,0);
            T* XBuffer = X.Buffer(0,j);
            if( orientation == ADJOINT )
                for( int i=0; i<m; ++i )
                    XBuffer[i] *= Conj(delta);
            else
                for( int i=0; i<m; ++i )
                    XBuffer[i] *= delta;
        }
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #22
0
inline void
Unb( Matrix<F>& A )
{
    EL_DEBUG_CSE
    const Int m = A.Height();
    const Int n = A.Width();
    for( Int j=0; j<Min(m,n); ++j )
    {
        const F alpha = A(j,j);
        if( alpha == F(0) )
            throw SingularMatrixException();

        blas::Scal( m-(j+1), F(1)/alpha, A.Buffer(j+1,j), 1 );
        blas::Geru
        ( m-(j+1), n-(j+1),
          F(-1), A.LockedBuffer(j+1,j), 1, A.LockedBuffer(j,j+1), A.LDim(),
                 A.Buffer(j+1,j+1), A.LDim() );
    }
}
Example #23
0
Real ComplementRatio
( const Matrix<Real>& s,
  const Matrix<Real>& z )
{
    DEBUG_CSE
    const Int k = s.Height();
    const Real* sBuf = s.LockedBuffer();
    const Real* zBuf = z.LockedBuffer();

    Real maxProd = 0;
    for( Int i=0; i<k; ++i )
        maxProd = Max( sBuf[i]*zBuf[i], maxProd );

    Real minProd = maxProd;
    for( Int i=0; i<k; ++i )
        minProd = Min( sBuf[i]*zBuf[i], minProd );

    return maxProd/minProd;
}
Example #24
0
inline void
Hemm
( LeftOrRight side, UpperOrLower uplo,
  T alpha, const Matrix<T>& A, const Matrix<T>& B, T beta, Matrix<T>& C )
{
#ifndef RELEASE
    PushCallStack("Hemm");
#endif
    const char sideChar = LeftOrRightToChar( side );
    const char uploChar = UpperOrLowerToChar( uplo );
    blas::Hemm
    ( sideChar, uploChar, C.Height(), C.Width(),
      alpha, A.LockedBuffer(), A.LDim(),
             B.LockedBuffer(), B.LDim(),
      beta,  C.Buffer(),       C.LDim() );
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #25
0
void SparseToCoordinates
( const Matrix<Field>& N,
  const Matrix<Field>& y,
        Matrix<Field>& v )
{
    EL_DEBUG_CSE
    const Int n = N.Height();

    v = y;

    // A custom rounded analogue of an upper-triangular solve
    for( Int j=n-1; j>=0; --j )
    {
        Field tau = 0;
        for( Int k=j+1; k<n; ++k ) 
            tau += N(j,k)*v(k);
        v(j) -= Round(tau);
    }
}
Example #26
0
inline void
MakeLegendre( Matrix<F>& A )
{
#ifndef RELEASE
    CallStackEntry entry("MakeLegendre");
#endif
    if( A.Height() != A.Width() )
        LogicError("Cannot make a non-square matrix Legendre");
    MakeZeros( A );

    const Int n = A.Width();
    for( Int j=0; j<n-1; ++j )
    {
        const F gamma = F(1) / Pow( F(2)*(j+1), F(2) );
        const F beta = F(1) / (2*Sqrt(F(1)-gamma));
        A.Set( j+1, j, beta );
        A.Set( j, j+1, beta );
    }
}
TEST_F(MatrixTest, MatrixScalarOperatorsTest) {
	ASSERT_EQ(empty, empty + 1.);
	ASSERT_EQ(empty, empty - 1.);
	ASSERT_EQ(empty, empty * 1.);
	ASSERT_EQ(empty, empty / 1.);
	ASSERT_ANY_THROW(empty / 0.);

	ASSERT_ANY_THROW(some / 0.);
	ASSERT_TRUE(cmp_matr_double(
			some + 10., make_mat({
			{  5 ,  5, 10, 21 , 25 },
			{  6 ,  8, 25,  -3, 23 },
			{  0 ,  8, 24,  -2, 11 },
			{  9 , 22, 22,  7 , 3  },
	})));
	ASSERT_TRUE(cmp_matr_double(
			some - 10., make_mat({
			{ -15,-15,-10,   1,  5 },
			{ -14,-12,  5, -23,  3 },
			{ -20,-12,  4, -22, -9 },
			{ -11,  2,  2, -13,-17 },
	})));
	ASSERT_TRUE(cmp_matr_double(
			some * 0.,
			Matrix(some.Width(), some.Height(), 0)
	));
	ASSERT_TRUE(cmp_matr_double(
			some * 1.,
			some
	));
	ASSERT_TRUE(cmp_matr_double(
			some / 1.,
			some
	));
	ASSERT_TRUE(cmp_matr_double(
			some / 0.5, make_mat({
			{ -10,-10, 0 , 22 , 30 },
			{ -8 , -4, 30, -26, 26 },
			{ -20, -4, 28, -24, 2  },
			{ -2 , 24, 24, -6 , -14},
	})));
}
Example #28
0
void TrrkTTKernel
( UpperOrLower uplo,
  Orientation orientationOfA,
  Orientation orientationOfB,
  T alpha, const Matrix<T>& A, const Matrix<T>& B,
                 Matrix<T>& C )
{
    DEBUG_CSE
    DEBUG_ONLY(CheckInputTT( orientationOfA, orientationOfB, A, B, C ))

    const Int half = C.Height()/2;
    const auto indTL = IR(0,half);
    const auto indBR = IR(half,END);

    auto AL = A(ALL,indTL);
    auto AR = A(ALL,indBR);
    auto BT = B(indTL,ALL);
    auto BB = B(indBR,ALL);
    auto CTL = C(indTL,indTL);
    auto CBR = C(indBR,indBR);

    if( uplo == LOWER )
    {
        auto CBL = C(indBR,indTL);
        Gemm( orientationOfA, orientationOfB, alpha, AR, BT, T(1), CBL );
    }
    else
    {
        auto CTR = C(indTL,indBR);
        Gemm( orientationOfA, orientationOfB, alpha, AL, BB, T(1), CTR );
    }

    // TODO(poulson): Avoid the temporary copy
    Matrix<T> DTL;
    Gemm( orientationOfA, orientationOfB, alpha, AL, BT, DTL );
    AxpyTrapezoid( uplo, T(1), DTL, CTL );

    // TODO(poulson): Avoid the temporary copy
    Matrix<T> DBR;
    Gemm( orientationOfA, orientationOfB, alpha, AR, BB, DBR );
    AxpyTrapezoid( uplo, T(1), DBR, CBR );
}
Example #29
0
void EvaluateSecularLast
( const Real& rho,
  const Matrix<Real>& z,
        LastState<Real>& state,
  bool penalizeDerivative=true )
{
    DEBUG_CSE
    const Real one(1);
    const Int n = z.Height();
    const Int origin = n-1;
    const Real rhoInv = one / rho;
    Real temp;

    state.psiMinus = 0;
    state.psiMinusDeriv = 0;
    state.relErrorBound = 0;
    for( Int j=0; j<origin; ++j )
    {
        // Compute the j'th term divided by z(j)
        temp = z(j) / state.dMinusShift(j);
        state.psiMinus += z(j)*temp;
        state.psiMinusDeriv += temp*temp;
        state.relErrorBound += state.psiMinus; // This should be negative
    }
    state.relErrorBound = Abs(state.relErrorBound); // This should be negation

    // Compute the origin term divided by z(origin)
    temp = z(origin) / state.dMinusShift(origin);
    state.psiOrigin = z(origin)*temp;
    state.psiOriginDeriv = temp*temp;
    state.secularDeriv = state.psiMinusDeriv + state.psiOriginDeriv;
    state.relErrorBound -= state.psiOrigin;

    // Compute the secular function with the origin term removed
    // (and its derivative)
    const Real psi = state.psiMinus + state.psiOrigin;
    state.secular = rhoInv + psi;

    state.relErrorBound += rhoInv - 8*psi;
    if( penalizeDerivative )
        state.relErrorBound += Abs(state.rootRelEst)*state.secularDeriv;
}
Example #30
0
inline void
MakeGKS( Matrix<F>& A )
{
#ifndef RELEASE
    CallStackEntry entry("MakeGKS");
#endif
    const Int m = A.Height();
    const Int n = A.Width();
    if( m != n )
        LogicError("Cannot make a non-square matrix GKS");

    MakeZeros( A );
    for( Int j=0; j<n; ++j )
    {
        const F jDiag = F(1)/Sqrt(F(j));
        for( Int i=0; i<j; ++i )
            A.Set( i, j, -jDiag );
        A.Set( j, j, jDiag );
    }
}