Пример #1
0
def GaussianElimination_unb(A):
    """
	GaussianElimination_unb(matrix)	

	Computes the Gauss Transform of the input matrix.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT.
    """
    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        laff.invscal( alpha11, a21 )        #  a21 := a21 / alpha11
        laff.ger( -1.0, a21, a12t, A22 )    #  A22 := A22 - a21 * a12t

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

    flame.merge_2x2(ATL, ATR, \
                    ABL, ABR, A)
Пример #2
0
def GaussianElimination_unb(A):
    """
	GaussianElimination_unb(matrix)	

	Computes the Gauss Transform of the input matrix.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT.
    """
    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        laff.invscal(alpha11, a21)  #  a21 := a21 / alpha11
        laff.ger(-1.0, a21, a12t, A22)  #  A22 := A22 - a21 * a12t

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

    flame.merge_2x2(ATL, ATR, \
                    ABL, ABR, A)
Пример #3
0
def Set_to_lower_triangular_matrix_unb_var1(A):
    """
	Set_to_lower_triangular_matrix_unb_var1(matrix)	
	
	Sets the above diagonal elements of A to zero.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT,
	and sets results column-wise.
    """

    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        laff.zerov(a01)

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

    flame.merge_2x2(ATL, ATR, \
                    ABL, ABR, A)
Пример #4
0
def Symmetrize_from_lower_triangle_unb_var1(A):
    """
	Symmetrize_from_lower_triangle_unb_var1(matrix)	
	
	Makes square matrix A symmetric by copying the
	lower triangular part in its upper triangular part.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT.
    """
    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        laff.copy(a01, a10t)

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

    flame.merge_2x2(ATL, ATR, \
                    ABL, ABR, A)
Пример #5
0
def Set_to_identity_unb_var1(A):
    """
	Set_to_identity_unb_var1(matrix)	
	
	Sets the input matrix to the Identity matrix.
	Traverses input matrix from TOP-LEFT to BOTTOM-RIGHT
	and sets results column-wise.
    """

    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        laff.zerov(a01)
        laff.onev(alpha11)
        laff.zerov(a21)

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

    flame.merge_2x2(ATL, ATR, \
                    ABL, ABR, A)
def Symmetrize_from_lower_triangle_unb_var1(A):
    """
	Symmetrize_from_lower_triangle_unb_var1(matrix)	
	
	Makes square matrix A symmetric by copying the
	lower triangular part in its upper triangular part.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT.
    """
    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        laff.copy(a01,a10t)

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

    flame.merge_2x2(ATL, ATR, \
                    ABL, ABR, A)
Пример #7
0
def Set_to_identity_unb_var1(A):
    """
	Set_to_identity_unb_var1(matrix)	
	
	Sets the input matrix to the Identity matrix.
	Traverses input matrix from TOP-LEFT to BOTTOM-RIGHT
	and sets results column-wise.
    """
    
    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        laff.zerov(a01)
        laff.onev(alpha11)
        laff.zerov(a21)

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

    flame.merge_2x2(ATL, ATR, \
                    ABL, ABR, A)
Пример #8
0
def Set_to_diagonal_matrix_unb_var2(d, A):
    """
	Set_to_diagonal_matrix_unb_var2(vector, matrix)	
	
	Sets the diagonal elements of A to the components of vector d.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT,
	traverses vector d from TOP to BOTTOM 
	and sets results row-wise.
    """
    
    dT, \
    dB  = flame.part_2x1(d, \
                         0, 'TOP')

    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    while dT.shape[0] < d.shape[0]:

        d0,     \
        delta1, \
        d2      = flame.repart_2x1_to_3x1(dT, \
                                          dB, \
                                          1, 'BOTTOM')

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        laff.zerov(a10t)
        laff.copy(delta1, alpha11)
        laff.zerov(a12t)

        dT, \
        dB  = flame.cont_with_3x1_to_2x1(d0,     \
                                         delta1, \
                                         d2,     \
                                         'TOP')

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

    flame.merge_2x1(dT, \
                    dB, d)

    flame.merge_2x2(ATL, ATR, \
                    ABL, ABR, A)
Пример #9
0
def Trmv_un_unb_var2(U, x):
    """
	Trmv_un_unb_var2(matrix, vector)	

	Computes y = U * x using AXPY operations.
	U is the upper triangular matrix.

	Traverses matrix U from TOP-LEFT to BOTTOM-RIGHT,
	vector x from TOP to BOTTOM.
    """
    UTL, UTR, \
    UBL, UBR  = flame.part_2x2(U, \
                               0, 0, 'TL')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'TOP')

    while UTL.shape[0] < U.shape[0]:

        U00,  u01,       U02,  \
        u10t, upsilon11, u12t, \
        U20,  u21,       U22   = flame.repart_2x2_to_3x3(UTL, UTR, \
                                                         UBL, UBR, \
                                                         1, 1, 'BR')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'BOTTOM')

        laff.axpy( chi1, u01, x0 )
        laff.scal( upsilon11, chi1 )

        UTL, UTR, \
        UBL, UBR  = flame.cont_with_3x3_to_2x2(U00,  u01,       U02,  \
                                               u10t, upsilon11, u12t, \
                                               U20,  u21,       U22,  \
                                               'TL')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'TOP')

    flame.merge_2x1(xT, \
                    xB, x)
Пример #10
0
def Trmv_ln_unb_var2(L, x):
    """
	Trmv_ln_unb_var2(matrix, vector)	

	Computes y = L * x using AXPY operations.
	L is the lower triangular matrix.

	Traverses matrix L from BOTTOM-RIGHT to TOP-LEFT,
	vector x from BOTTOM to TOP.
    """
    LTL, LTR, \
    LBL, LBR  = flame.part_2x2(L, \
                               0, 0, 'BR')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'BOTTOM')

    while LBR.shape[0] < L.shape[0]:

        L00,  l01,      L02,  \
        l10t, lambda11, l12t, \
        L20,  l21,      L22   = flame.repart_2x2_to_3x3(LTL, LTR, \
                                                        LBL, LBR, \
                                                        1, 1, 'TL')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'TOP')

        laff.axpy( chi1, l21, x2 )
        laff.scal( lambda11, chi1 )
        
        LTL, LTR, \
        LBL, LBR  = flame.cont_with_3x3_to_2x2(L00,  l01,      L02,  \
                                               l10t, lambda11, l12t, \
                                               L20,  l21,      L22,  \
                                               'BR')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'BOTTOM')

    flame.merge_2x1(xT, \
                    xB, x)
Пример #11
0
def Trmv_un_unb_var1(U, x):
    """
	Trmv_un_unb_var1(matrix, vector)	

	Computes y = U * x using DOT products.
	U is the upper triangular matrix.

	Traverses matrix U from TOP-LEFT to BOTTOM-RIGHT,
	vector x from TOP to BOTTOM.
    """
    UTL, UTR, \
    UBL, UBR  = flame.part_2x2(U, \
                               0, 0, 'TL')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'TOP')

    while UTL.shape[0] < U.shape[0]:

        U00,  u01,       U02,  \
        u10t, upsilon11, u12t, \
        U20,  u21,       U22   = flame.repart_2x2_to_3x3(UTL, UTR, \
                                                         UBL, UBR, \
                                                         1, 1, 'BR')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'BOTTOM')

        laff.scal(upsilon11, chi1)
        laff.dots(u12t, x2, chi1)

        UTL, UTR, \
        UBL, UBR  = flame.cont_with_3x3_to_2x2(U00,  u01,       U02,  \
                                               u10t, upsilon11, u12t, \
                                               U20,  u21,       U22,  \
                                               'TL')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'TOP')

    flame.merge_2x1(xT, \
                    xB, x)
Пример #12
0
def ForwardSubstitution_unb(A, b):
    """
	ForwardSubstitution_unb(matrix, vector)	

	Computes coefficients using Forward Substituion.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT,
	vector b from TOP to BOTTOM.
    """
    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    bT, \
    bB  = flame.part_2x1(b, \
                         0, 'TOP')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        b0,    \
        beta1, \
        b2     = flame.repart_2x1_to_3x1(bT, \
                                         bB, \
                                         1, 'BOTTOM')


        laff.axpy( -beta1, a21, b2 )


        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

        bT, \
        bB  = flame.cont_with_3x1_to_2x1(b0,    \
                                         beta1, \
                                         b2,    \
                                         'TOP')

    flame.merge_2x1(bT, \
                    bB, b)
Пример #13
0
def Trmv_lt_unb_var1(L, x):
    """
	Trmv_lt_unb_var1(matrix, vector)	

	Computes x = L' * x using DOT products.

	Traverses matrix L from TOP-LEFT to BOTTOM-RIGHT,
	vector x from TOP to BOTTOM.
    """
    LTL, LTR, \
    LBL, LBR  = flame.part_2x2(L, \
                               0, 0, 'TL')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'TOP')

    while LTL.shape[0] < L.shape[0]:

        L00,  l01,      L02,  \
        l10t, lambda11, l12t, \
        L20,  l21,      L22   = flame.repart_2x2_to_3x3(LTL, LTR, \
                                                        LBL, LBR, \
                                                        1, 1, 'BR')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'BOTTOM')

        laff.scal(lambda11, chi1)
        laff.dots(l21, x2, chi1)

        LTL, LTR, \
        LBL, LBR  = flame.cont_with_3x3_to_2x2(L00,  l01,      L02,  \
                                               l10t, lambda11, l12t, \
                                               L20,  l21,      L22,  \
                                               'TL')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'TOP')

    flame.merge_2x1(xT, \
                    xB, x)
Пример #14
0
def Trmv_ut_unb_var1(U, x):
    """
	Trmv_ut_unb_var1(matrix, vector)	

	Computes x = U' * x using DOT products.

	Traverses matrix U from BOTTOM-RIGHT to TOP-LEFT,
	vector x from BOTTOM to TOP.
    """
    UTL, UTR, \
    UBL, UBR  = flame.part_2x2(U, \
                               0, 0, 'BR')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'BOTTOM')

    while UBR.shape[0] < U.shape[0]:

        U00,  u01,       U02,  \
        u10t, upsilon11, u12t, \
        U20,  u21,       U22   = flame.repart_2x2_to_3x3(UTL, UTR, \
                                                         UBL, UBR, \
                                                         1, 1, 'TL')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'TOP')

        laff.scal( upsilon11, chi1 )
        laff.dots( u01, x0, chi1 )
        
        UTL, UTR, \
        UBL, UBR  = flame.cont_with_3x3_to_2x2(U00,  u01,       U02,  \
                                               u10t, upsilon11, u12t, \
                                               U20,  u21,       U22,  \
                                               'BR')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'BOTTOM')

    flame.merge_2x1(xT, \
                    xB, x)
Пример #15
0
def Trmv_ut_unb_var2(U, x):
    """
	Trmv_ut_unb_var2(matrix, vector)	

	Computes x = U' * x using AXPY operations.

	Traverses matrix U from BOTTOM-RIGHT to TOP-LEFT,
	vector x from BOTTOM to TOP.
    """
    UTL, UTR, \
    UBL, UBR  = flame.part_2x2(U, \
                               0, 0, 'BR')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'BOTTOM')

    while UBR.shape[0] < U.shape[0]:

        U00,  u01,       U02,  \
        u10t, upsilon11, u12t, \
        U20,  u21,       U22   = flame.repart_2x2_to_3x3(UTL, UTR, \
                                                         UBL, UBR, \
                                                         1, 1, 'TL')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'TOP')

        laff.axpy(chi1, u12t, x2)
        laff.scal(upsilon11, chi1)

        UTL, UTR, \
        UBL, UBR  = flame.cont_with_3x3_to_2x2(U00,  u01,       U02,  \
                                               u10t, upsilon11, u12t, \
                                               U20,  u21,       U22,  \
                                               'BR')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'BOTTOM')

    flame.merge_2x1(xT, \
                    xB, x)
Пример #16
0
def trsv_lnn(L, b):

    LTL, LTR, \
    LBL, LBR  = flame.part_2x2(L, \
                               0, 0, 'TL')

    bT, \
    bB  = flame.part_2x1(b, \
                         0, 'TOP')

    while LTL.shape[0] < L.shape[0]:

        L00,  l01,      L02,  \
        l10t, lambda11, l12t, \
        L20,  l21,      L22   = flame.repart_2x2_to_3x3(LTL, LTR, \
                                                        LBL, LBR, \
                                                        1, 1, 'BR')

        b0,    \
        beta1, \
        b2     = flame.repart_2x1_to_3x1(bT, \
                                         bB, \
                                         1, 'BOTTOM')

        #------------------------------------------------------------#

        scal(1. / lambda11, beta1)
        axpy(-beta1, l21, b2)

        #------------------------------------------------------------#

        LTL, LTR, \
        LBL, LBR  = flame.cont_with_3x3_to_2x2(L00,  l01,      L02,  \
                                               l10t, lambda11, l12t, \
                                               L20,  l21,      L22,  \
                                               'TL')

        bT, \
        bB  = flame.cont_with_3x1_to_2x1(b0,    \
                                         beta1, \
                                         b2,    \
                                         'TOP')

    flame.merge_2x1(bT, \
                    bB, b)
Пример #17
0
def trsv_unn(U, b):

    UTL, UTR, \
    UBL, UBR  = flame.part_2x2(U, \
                               0, 0, 'BR')

    bT, \
    bB  = flame.part_2x1(b, \
                         0, 'BOTTOM')

    while UBR.shape[0] < U.shape[0]:

        U00,  u01,       U02,  \
        u10t, upsilon11, u12t, \
        U20,  u21,       U22   = flame.repart_2x2_to_3x3(UTL, UTR, \
                                                         UBL, UBR, \
                                                         1, 1, 'TL')

        b0,    \
        beta1, \
        b2     = flame.repart_2x1_to_3x1(bT, \
                                         bB, \
                                         1, 'TOP')

        #------------------------------------------------------------#

        dots( -u12t, b2, beta1 )
        scal( 1/upsilon11, beta1 )

        #------------------------------------------------------------#

        UTL, UTR, \
        UBL, UBR  = flame.cont_with_3x3_to_2x2(U00,  u01,       U02,  \
                                               u10t, upsilon11, u12t, \
                                               U20,  u21,       U22,  \
                                               'BR')

        bT, \
        bB  = flame.cont_with_3x1_to_2x1(b0,    \
                                         beta1, \
                                         b2,    \
                                         'BOTTOM')

    flame.merge_2x1(bT, \
                    bB, b)
Пример #18
0
def trsv_utn(U, b):

    UTL, UTR, \
    UBL, UBR  = flame.part_2x2(U, \
                               0, 0, 'TL')

    bT, \
    bB  = flame.part_2x1(b, \
                         0, 'TOP')

    while UTL.shape[0] < U.shape[0]:

        U00,  u01,       U02,  \
        u10t, upsilon11, u12t, \
        U20,  u21,       U22   = flame.repart_2x2_to_3x3(UTL, UTR, \
                                                         UBL, UBR, \
                                                         1, 1, 'BR')

        b0,    \
        beta1, \
        b2     = flame.repart_2x1_to_3x1(bT, \
                                         bB, \
                                         1, 'BOTTOM')

        #------------------------------------------------------------#

        invscal(upsilon11, beta1)
        axpy(-beta1, u12t, b2)

        #------------------------------------------------------------#

        UTL, UTR, \
        UBL, UBR  = flame.cont_with_3x3_to_2x2(U00,  u01,       U02,  \
                                               u10t, upsilon11, u12t, \
                                               U20,  u21,       U22,  \
                                               'TL')

        bT, \
        bB  = flame.cont_with_3x1_to_2x1(b0,    \
                                         beta1, \
                                         b2,    \
                                         'TOP')

    flame.merge_2x1(bT, \
                    bB, b)
Пример #19
0
def trsv_lnn(L, b):

    LTL, LTR, \
    LBL, LBR  = flame.part_2x2(L, \
                               0, 0, 'TL')

    bT, \
    bB  = flame.part_2x1(b, \
                         0, 'TOP')

    while LTL.shape[0] < L.shape[0]:

        L00,  l01,      L02,  \
        l10t, lambda11, l12t, \
        L20,  l21,      L22   = flame.repart_2x2_to_3x3(LTL, LTR, \
                                                        LBL, LBR, \
                                                        1, 1, 'BR')

        b0,    \
        beta1, \
        b2     = flame.repart_2x1_to_3x1(bT, \
                                         bB, \
                                         1, 'BOTTOM')

        #------------------------------------------------------------#

        scal( 1./lambda11, beta1 )
        axpy( -beta1, l21, b2 )

        #------------------------------------------------------------#

        LTL, LTR, \
        LBL, LBR  = flame.cont_with_3x3_to_2x2(L00,  l01,      L02,  \
                                               l10t, lambda11, l12t, \
                                               L20,  l21,      L22,  \
                                               'TL')

        bT, \
        bB  = flame.cont_with_3x1_to_2x1(b0,    \
                                         beta1, \
                                         b2,    \
                                         'TOP')

    flame.merge_2x1(bT, \
                    bB, b)
Пример #20
0
def trsv_ltu(L, B):

    LTL, LTR, \
    LBL, LBR  = flame.part_2x2(L, \
                               0, 0, 'TL')

    BT, \
    BB  = flame.part_2x1(B, \
                         0, 'TOP')

    while LTL.shape[0] < L.shape[0]:

        L00,  l01,      L02,  \
        l10t, lambda11, l12t, \
        L20,  l21,      L22   = flame.repart_2x2_to_3x3(LTL, LTR, \
                                                        LBL, LBR, \
                                                        1, 1, 'BR')

        B0,  \
        b1t, \
        B2   = flame.repart_2x1_to_3x1(BT, \
                                       BB, \
                                       1, 'BOTTOM')

        #------------------------------------------------------------#

        dots( -l21, b2, beta1 )
        scal( 1/lambda11, beta1 )

        #------------------------------------------------------------#

        LTL, LTR, \
        LBL, LBR  = flame.cont_with_3x3_to_2x2(L00,  l01,      L02,  \
                                               l10t, lambda11, l12t, \
                                               L20,  l21,      L22,  \
                                               'TL')

        BT, \
        BB  = flame.cont_with_3x1_to_2x1(B0,  \
                                         b1t, \
                                         B2,  \
                                         'TOP')

    flame.merge_2x1(BT, \
                    BB, B)
Пример #21
0
def Utrsv_notranspose_nonunit(U, b):

    UTL, UTR, \
    UBL, UBR  = flame.part_2x2(U, \
                               0, 0, 'BR')

    bT, \
    bB  = flame.part_2x1(b, \
                         0, 'BOTTOM')

    while UBR.shape[0] < U.shape[0]:

        U00,  u01,       U02,  \
        u10t, upsilon11, u12t, \
        U20,  u21,       U22   = flame.repart_2x2_to_3x3(UTL, UTR, \
                                                         UBL, UBR, \
                                                         1, 1, 'TL')

        b0,    \
        beta1, \
        b2     = flame.repart_2x1_to_3x1(bT, \
                                         bB, \
                                         1, 'TOP')

        #------------------------------------------------------------#

        dots(-u12t, b2, beta1)
        scal(1 / upsilon11, beta1)

        #------------------------------------------------------------#

        UTL, UTR, \
        UBL, UBR  = flame.cont_with_3x3_to_2x2(U00,  u01,       U02,  \
                                               u10t, upsilon11, u12t, \
                                               U20,  u21,       U22,  \
                                               'BR')

        bT, \
        bB  = flame.cont_with_3x1_to_2x1(b0,    \
                                         beta1, \
                                         b2,    \
                                         'BOTTOM')

    flame.merge_2x1(bT, \
                    bB, b)
Пример #22
0
def Set_to_lower_triangular_matrix_unb_var1(A):
    """
	Set_to_lower_triangular_matrix_unb_var1(matrix)	
	
	Sets the above diagonal elements of A to zero.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT,
	and sets results column-wise.
    """

    ATL, ATR, ABL, ABR = flame.part_2x2(A, 0, 0, "TL")

    while ATL.shape[0] < A.shape[0]:

        A00, a01, A02, a10t, alpha11, a12t, A20, a21, A22 = flame.repart_2x2_to_3x3(ATL, ATR, ABL, ABR, 1, 1, "BR")

        laff.zerov(a01)

        ATL, ATR, ABL, ABR = flame.cont_with_3x3_to_2x2(A00, a01, A02, a10t, alpha11, a12t, A20, a21, A22, "TL")

    flame.merge_2x2(ATL, ATR, ABL, ABR, A)
Пример #23
0
def chol_unb(A):

    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        #------------------------------------------------------------#

        # alpha11[0,0] = np.sqrt( alpha11[0,0] )
        # laff.invscal( alpha11, a21 )
        # laff.ger( -1, a21, a21, A22 ) #Not tril

        # laff.dots( a10t, a10t, alpha11 )
        # alpha11[0,0] = np.sqrt( alpha11[0,0] )
        # a21 -= A20 * np.transpose(a10t) #Not laff calls
        # laff.invscal( alpha11, a21 )

        trsv('Lower triangular', 'Nonunit diagonal', 'No transpose', A00, a10t)
        dots(a10t, a10t, alpha11)
        alpha11[0, 0] = np.sqrt(alpha11[0, 0])

        #------------------------------------------------------------#

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

    flame.merge_2x2(ATL, ATR, \
                    ABL, ABR, A)
Пример #24
0
def chol_unb(A):

    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        #------------------------------------------------------------#

        # alpha11[0,0] = np.sqrt( alpha11[0,0] )
        # laff.invscal( alpha11, a21 )
        # laff.ger( -1, a21, a21, A22 ) #Not tril

        # laff.dots( a10t, a10t, alpha11 )
        # alpha11[0,0] = np.sqrt( alpha11[0,0] )
        # a21 -= A20 * np.transpose(a10t) #Not laff calls
        # laff.invscal( alpha11, a21 )

        laff.trsv( 'Lower triangular', 'Nonunit diagonal', 'No transpose', A00, a10t )
        laff.dots( a10t, a10t, alpha11 )
        alpha11[0,0] = np.sqrt( alpha11[0,0] )

        #------------------------------------------------------------#

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

    flame.merge_2x2(ATL, ATR, \
                    ABL, ABR, A)
Пример #25
0
def Symv_u_unb_var2(A, x, y):
    """
	Symv_u_unb_var2(matrix, vector, vector)	

	Computes y = A * x + y using AXPY operations.

	A is a symmetric matrix.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT,
	vector x from TOP to BOTTOM,
	vector y from TOP to BOTTOM.
    """
    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'TOP')

    yT, \
    yB  = flame.part_2x1(y, \
                         0, 'TOP')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'BOTTOM')

        y0,   \
        psi1, \
        y2    = flame.repart_2x1_to_3x1(yT, \
                                        yB, \
                                        1, 'BOTTOM')

        laff.axpy( chi1, a01, y0 )
        laff.axpy( chi1, alpha11, psi1 )
        laff.axpy( chi1, a12t, y2 )
        

        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'TOP')

        yT, \
        yB  = flame.cont_with_3x1_to_2x1(y0,   \
                                         psi1, \
                                         y2,   \
                                         'TOP')

    flame.merge_2x1(yT, \
                    yB, y)
Пример #26
0
def Tmvmult_lt_unb_var2(L, x, y):
    """
	Tmvmult_lt_unb_var2(matrix, vector, vector)	

	Computes y = L' * x + y using AXPY operations.
	L is the lower triangular matrix.

	Traverses matrix L from TOP-LEFT to BOTTOM-RIGHT,
	vector x from TOP to BOTTOM,
	vector y from TOP to BOTTOM.
    """
    LTL, LTR, \
    LBL, LBR  = flame.part_2x2(L, \
                               0, 0, 'TL')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'TOP')

    yT, \
    yB  = flame.part_2x1(y, \
                         0, 'TOP')

    while LTL.shape[0] < L.shape[0]:

        L00,  l01,      L02,  \
        l10t, lambda11, l12t, \
        L20,  l21,      L22   = flame.repart_2x2_to_3x3(LTL, LTR, \
                                                        LBL, LBR, \
                                                        1, 1, 'BR')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'BOTTOM')

        y0,   \
        psi1, \
        y2    = flame.repart_2x1_to_3x1(yT, \
                                        yB, \
                                        1, 'BOTTOM')

        laff.axpy( chi1, lambda11, psi1 )
        laff.axpy( chi1, l10t, y0 )

        LTL, LTR, \
        LBL, LBR  = flame.cont_with_3x3_to_2x2(L00,  l01,      L02,  \
                                               l10t, lambda11, l12t, \
                                               L20,  l21,      L22,  \
                                               'TL')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'TOP')

        yT, \
        yB  = flame.cont_with_3x1_to_2x1(y0,   \
                                         psi1, \
                                         y2,   \
                                         'TOP')

    flame.merge_2x1(yT, \
                    yB, y)
Пример #27
0
def Symv_u_unb_var2(A, x, y):
    """
	Symv_u_unb_var2(matrix, vector, vector)	

	Computes y = A * x + y using AXPY operations.

	A is a symmetric matrix.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT,
	vector x from TOP to BOTTOM,
	vector y from TOP to BOTTOM.
    """
    ATL, ATR, \
    ABL, ABR  = flame.part_2x2(A, \
                               0, 0, 'TL')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'TOP')

    yT, \
    yB  = flame.part_2x1(y, \
                         0, 'TOP')

    while ATL.shape[0] < A.shape[0]:

        A00,  a01,     A02,  \
        a10t, alpha11, a12t, \
        A20,  a21,     A22   = flame.repart_2x2_to_3x3(ATL, ATR, \
                                                       ABL, ABR, \
                                                       1, 1, 'BR')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'BOTTOM')

        y0,   \
        psi1, \
        y2    = flame.repart_2x1_to_3x1(yT, \
                                        yB, \
                                        1, 'BOTTOM')

        laff.axpy(chi1, a01, y0)
        laff.axpy(chi1, alpha11, psi1)
        laff.axpy(chi1, a12t, y2)


        ATL, ATR, \
        ABL, ABR  = flame.cont_with_3x3_to_2x2(A00,  a01,     A02,  \
                                               a10t, alpha11, a12t, \
                                               A20,  a21,     A22,  \
                                               'TL')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'TOP')

        yT, \
        yB  = flame.cont_with_3x1_to_2x1(y0,   \
                                         psi1, \
                                         y2,   \
                                         'TOP')

    flame.merge_2x1(yT, \
                    yB, y)
Пример #28
0
def Tmvmult_ut_unb_var2(U, x, y):
    """
	Tmvmult_ut_unb_var2(matrix, vector, vector)	

	Computes y = U' * x + y using AXPY operations.

	Traverses matrix A from TOP-LEFT to BOTTOM-RIGHT,
	vector x from TOP to BOTTOM,
	vector y from TOP to BOTTOM.
    """
    UTL, UTR, \
    UBL, UBR  = flame.part_2x2(U, \
                               0, 0, 'TL')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'TOP')

    yT, \
    yB  = flame.part_2x1(y, \
                         0, 'TOP')

    while UTL.shape[0] < U.shape[0]:

        U00,  u01,       U02,  \
        u10t, upsilon11, u12t, \
        U20,  u21,       U22   = flame.repart_2x2_to_3x3(UTL, UTR, \
                                                         UBL, UBR, \
                                                         1, 1, 'BR')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'BOTTOM')

        y0,   \
        psi1, \
        y2    = flame.repart_2x1_to_3x1(yT, \
                                        yB, \
                                        1, 'BOTTOM')

        laff.axpy( chi1, u12t, y2 )
        laff.axpy( chi1, upsilon11, psi1 )

        UTL, UTR, \
        UBL, UBR  = flame.cont_with_3x3_to_2x2(U00,  u01,       U02,  \
                                               u10t, upsilon11, u12t, \
                                               U20,  u21,       U22,  \
                                               'TL')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'TOP')

        yT, \
        yB  = flame.cont_with_3x1_to_2x1(y0,   \
                                         psi1, \
                                         y2,   \
                                         'TOP')

    flame.merge_2x1(yT, \
                    yB, y)
Пример #29
0
def Tmvmult_ut_unb_var1(U, x, y):
    """
	Tmvmult_ut_unb_var1(matrix, vector, vector)	

	Computes y = U' * x + y using DOT products.

	Traverses matrix U from TOP-LEFT to BOTTOM-RIGHT,
	vector x from TOP to BOTTOM,
	vector y from TOP to BOTTOM.
    """
    UTL, UTR, \
    UBL, UBR  = flame.part_2x2(U, \
                               0, 0, 'TL')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'TOP')

    yT, \
    yB  = flame.part_2x1(y, \
                         0, 'TOP')

    while UTL.shape[0] < U.shape[0]:

        U00,  u01,       U02,  \
        u10t, upsilon11, u12t, \
        U20,  u21,       U22   = flame.repart_2x2_to_3x3(UTL, UTR, \
                                                         UBL, UBR, \
                                                         1, 1, 'BR')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'BOTTOM')

        y0,   \
        psi1, \
        y2    = flame.repart_2x1_to_3x1(yT, \
                                        yB, \
                                        1, 'BOTTOM')

        laff.dots( upsilon11, chi1, psi1 )
        laff.dots( u01, x0, psi1 )

        UTL, UTR, \
        UBL, UBR  = flame.cont_with_3x3_to_2x2(U00,  u01,       U02,  \
                                               u10t, upsilon11, u12t, \
                                               U20,  u21,       U22,  \
                                               'TL')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'TOP')

        yT, \
        yB  = flame.cont_with_3x1_to_2x1(y0,   \
                                         psi1, \
                                         y2,   \
                                         'TOP')

    flame.merge_2x1(yT, \
                    yB, y)
Пример #30
0
def Tmvmult_un_unb_var2(U, x, y):
    """
	Tmvmult_un_unb_var2(matrix, vector, vector)	

	Computes y = U * x + y using AXPY operations.
	U is the upper triangular matrix.

	Traverses matrix U from TOP-LEFT to BOTTOM-RIGHT,
	vector x from TOP to BOTTOM,
	vector y from TOP to BOTTOM.
    """
    UTL, UTR, \
    UBL, UBR  = flame.part_2x2(U, \
                               0, 0, 'TL')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'TOP')

    yT, \
    yB  = flame.part_2x1(y, \
                         0, 'TOP')

    while UTL.shape[0] < U.shape[0]:

        U00,  u01,       U02,  \
        u10t, upsilon11, u12t, \
        U20,  u21,       U22   = flame.repart_2x2_to_3x3(UTL, UTR, \
                                                         UBL, UBR, \
                                                         1, 1, 'BR')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'BOTTOM')

        y0,   \
        psi1, \
        y2    = flame.repart_2x1_to_3x1(yT, \
                                        yB, \
                                        1, 'BOTTOM')

        laff.axpy(chi1, u01, y0)
        laff.axpy(chi1, upsilon11, psi1)

        UTL, UTR, \
        UBL, UBR  = flame.cont_with_3x3_to_2x2(U00,  u01,       U02,  \
                                               u10t, upsilon11, u12t, \
                                               U20,  u21,       U22,  \
                                               'TL')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'TOP')

        yT, \
        yB  = flame.cont_with_3x1_to_2x1(y0,   \
                                         psi1, \
                                         y2,   \
                                         'TOP')

    flame.merge_2x1(yT, \
                    yB, y)
Пример #31
0
def Tmvmult_ln_unb_var2(L, x, y):
    """
	Tmvmult_ln_unb_var2(matrix, vector, vector)	

	Computes y = L * x + y using AXPY operations.
	L is the lower triangular matrix.

	Traverses matrix L from TOP-LEFT to BOTTOM-RIGHT,
	vector x from TOP to BOTTOM,
	vector y from TOP to BOTTOM.
    """
    LTL, LTR, \
    LBL, LBR  = flame.part_2x2(L, \
                               0, 0, 'TL')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'TOP')

    yT, \
    yB  = flame.part_2x1(y, \
                         0, 'TOP')

    while LTL.shape[0] < L.shape[0]:

        L00,  l01,      L02,  \
        l10t, lambda11, l12t, \
        L20,  l21,      L22   = flame.repart_2x2_to_3x3(LTL, LTR, \
                                                        LBL, LBR, \
                                                        1, 1, 'BR')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'BOTTOM')

        y0,   \
        psi1, \
        y2    = flame.repart_2x1_to_3x1(yT, \
                                        yB, \
                                        1, 'BOTTOM')

        laff.axpy(chi1, lambda11, psi1)
        laff.axpy(chi1, l21, y2)

        LTL, LTR, \
        LBL, LBR  = flame.cont_with_3x3_to_2x2(L00,  l01,      L02,  \
                                               l10t, lambda11, l12t, \
                                               L20,  l21,      L22,  \
                                               'TL')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'TOP')

        yT, \
        yB  = flame.cont_with_3x1_to_2x1(y0,   \
                                         psi1, \
                                         y2,   \
                                         'TOP')

    flame.merge_2x1(yT, \
                    yB, y)
Пример #32
0
def Tmvmult_un_unb_var1(U, x, y):
    """
	Tmvmult_un_unb_var1(matrix, vector, vector)	

	Computes y = U * x + y using DOT products.
	U is the upper triangular matrix.

	Traverses matrix U from TOP-LEFT to BOTTOM-RIGHT,
	vector x from TOP to BOTTOM,
	vector y from TOP to BOTTOM.
    """
    UTL, UTR, \
    UBL, UBR  = flame.part_2x2(U, \
                               0, 0, 'TL')

    xT, \
    xB  = flame.part_2x1(x, \
                         0, 'TOP')

    yT, \
    yB  = flame.part_2x1(y, \
                         0, 'TOP')

    while UTL.shape[0] < U.shape[0]:

        U00,  u01,       U02,  \
        u10t, upsilon11, u12t, \
        U20,  u21,       U22   = flame.repart_2x2_to_3x3(UTL, UTR, \
                                                         UBL, UBR, \
                                                         1, 1, 'BR')

        x0,   \
        chi1, \
        x2    = flame.repart_2x1_to_3x1(xT, \
                                        xB, \
                                        1, 'BOTTOM')

        y0,   \
        psi1, \
        y2    = flame.repart_2x1_to_3x1(yT, \
                                        yB, \
                                        1, 'BOTTOM')

        laff.dots( upsilon11, chi1, psi1 )
        laff.dots( u12t, x2, psi1 )

        UTL, UTR, \
        UBL, UBR  = flame.cont_with_3x3_to_2x2(U00,  u01,       U02,  \
                                               u10t, upsilon11, u12t, \
                                               U20,  u21,       U22,  \
                                               'TL')

        xT, \
        xB  = flame.cont_with_3x1_to_2x1(x0,   \
                                         chi1, \
                                         x2,   \
                                         'TOP')

        yT, \
        yB  = flame.cont_with_3x1_to_2x1(y0,   \
                                         psi1, \
                                         y2,   \
                                         'TOP')

    flame.merge_2x1(yT, \
                    yB, y)