Esempio n. 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)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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)
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)
Esempio n. 6
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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
0
def Tmvmult_ln_unb_var1(L, x, y):
    """
	Tmvmult_ln_unb_var1(matrix, vector, vector)	

	Computes y = L * x + y using DOT products.
	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.dots(l10t, x0, psi1)
        laff.dots(lambda11, chi1, psi1)

        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_2x2(LTL, LTR, \
                    LBL, LBR, L)

    flame.merge_2x1(xT, \
                    xB, x)

    flame.merge_2x1(yT, \
                    yB, y)