def trsm_ltu(L, B): BT, \ BB = flame.part_2x1(B, \ 0, 'TOP') while BT.shape[0] < B.shape[0]: B0, \ b1t, \ B2 = flame.repart_2x1_to_3x1(BT, \ BB, \ 1, 'BOTTOM') #------------------------------------------------------------# #TODO: Fix trsv.py to handle rows properly #Sorry for the hackiness in the fix here, I got pressed for time laff.trsv( 'Lower triangular', 'Transpose', 'Unit diagonal', L, transpose( b1t ) ) #------------------------------------------------------------# BT, \ BB = flame.cont_with_3x1_to_2x1(B0, \ b1t, \ B2, \ 'TOP') flame.merge_2x1(BT, \ BB, B)
def Set_to_zero_unb_var2(A): """ Set_to_zero_unb_var2(matrix) Sets the input matrix to zeros. Traverses input matrix from TOP to BOTTOM and sets results column-wise. """ AT, \ AB = flame.part_2x1(A, \ 0, 'TOP') while AT.shape[0] < A.shape[0]: A0, \ a1t, \ A2 = flame.repart_2x1_to_3x1(AT, \ AB, \ 1, 'BOTTOM') laff.zerov(a1t) AT, \ AB = flame.cont_with_3x1_to_2x1(A0, \ a1t, \ A2, \ 'TOP') flame.merge_2x1(AT, \ AB, A)
def trsm_utn(U, B): BT, \ BB = flame.part_2x1(B, \ 0, 'TOP') while BT.shape[0] < B.shape[0]: B0, \ b1t, \ B2 = flame.repart_2x1_to_3x1(BT, \ BB, \ 1, 'BOTTOM') #------------------------------------------------------------# #TODO: Fix trsv.py to handle rows properly #Sorry for the hackiness in the fix here, I got pressed for time laff.trsv('Upper triangular', 'Transpose', 'Nonunit diagonal', U, transpose(b1t)) #------------------------------------------------------------# BT, \ BB = flame.cont_with_3x1_to_2x1(B0, \ b1t, \ B2, \ 'TOP') flame.merge_2x1(BT, \ BB, B)
def Scale_a_matrix_unb_var2(beta, A): """ Scale_a_matrix_unb_var2(scalar, matrix) Scales matrix A by a factor of beta. Traverses matrix A from TOP to BOTTOM. """ AT, \ AB = flame.part_2x1(A, \ 0, 'TOP') while AT.shape[0] < A.shape[0]: A0, \ a1t, \ A2 = flame.repart_2x1_to_3x1(AT, \ AB, \ 1, 'BOTTOM') laff.scal(beta,a1t) AT, \ AB = flame.cont_with_3x1_to_2x1(A0, \ a1t, \ A2, \ 'TOP') flame.merge_2x1(AT, \ AB, A)
def Mvmult_n_unb_var1(A, x, y): """ Mvmult_n_unb_var1(matrix, vector, vector) Compuyes y = A * x + y using DOT products. Traverses matrix A from TOP to BOTTOM, vector y from TOP to BOTTOM. """ AT, \ AB = flame.part_2x1(A, \ 0, 'TOP') yT, \ yB = flame.part_2x1(y, \ 0, 'TOP') while AT.shape[0] < A.shape[0]: A0, \ a1t, \ A2 = flame.repart_2x1_to_3x1(AT, \ AB, \ 1, 'BOTTOM') y0, \ psi1, \ y2 = flame.repart_2x1_to_3x1(yT, \ yB, \ 1, 'BOTTOM') laff.dots(a1t, x, psi1) AT, \ AB = flame.cont_with_3x1_to_2x1(A0, \ a1t, \ A2, \ 'TOP') yT, \ yB = flame.cont_with_3x1_to_2x1(y0, \ psi1, \ y2, \ 'TOP') flame.merge_2x1(yT, \ yB, y)
def Mvmult_n_unb_var1(A, x, y): """ Mvmult_n_unb_var1(matrix, vector, vector) Compuyes y = A * x + y using DOT products. Traverses matrix A from TOP to BOTTOM, vector y from TOP to BOTTOM. """ AT, \ AB = flame.part_2x1(A, \ 0, 'TOP') yT, \ yB = flame.part_2x1(y, \ 0, 'TOP') while AT.shape[0] < A.shape[0]: A0, \ a1t, \ A2 = flame.repart_2x1_to_3x1(AT, \ AB, \ 1, 'BOTTOM') y0, \ psi1, \ y2 = flame.repart_2x1_to_3x1(yT, \ yB, \ 1, 'BOTTOM') laff.dots( a1t, x, psi1 ) AT, \ AB = flame.cont_with_3x1_to_2x1(A0, \ a1t, \ A2, \ 'TOP') yT, \ yB = flame.cont_with_3x1_to_2x1(y0, \ psi1, \ y2, \ 'TOP') flame.merge_2x1(yT, \ yB, y)
def Mvmult_t_unb_var2(A, x, y): """ Mvmult_t_unb_var2(matrix, vector, vector) Computes y = A' * x + y using AXPY operations. Traverses matrix A from TOP to BOTTOM, vector x from TOP to BOTTOM. """ AT, \ AB = flame.part_2x1(A, \ 0, 'TOP') xT, \ xB = flame.part_2x1(x, \ 0, 'TOP') while AT.shape[0] < A.shape[0]: A0, \ a1t, \ A2 = flame.repart_2x1_to_3x1(AT, \ AB, \ 1, 'BOTTOM') x0, \ chi1, \ x2 = flame.repart_2x1_to_3x1(xT, \ xB, \ 1, 'BOTTOM') laff.axpy( chi1, a1t, y ) AT, \ AB = flame.cont_with_3x1_to_2x1(A0, \ a1t, \ A2, \ 'TOP') xT, \ xB = flame.cont_with_3x1_to_2x1(x0, \ chi1, \ x2, \ 'TOP')
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)
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)
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)
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)
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)
def Dot_unb(x, y): xT, xB = flame.part_2x1(x, 0, 'TOP') yT, yB = flame.part_2x1(y, 0, 'TOP') alpha = 0 while xT.shape[0] < x.shape[0]: x0, chi1, x2 = flame.repart_2x1_to_3x1(xT, xB, 1, 'BOTTOM') y0, psi1, y2 = flame.repart_2x1_to_3x1(yT, yB, 1, 'BOTTOM') #------------------------------------------------------------# alpha = chi1 * psi1 + alpha #------------------------------------------------------------# xT, xB = flame.cont_with_3x1_to_2x1(x0, chi1, x2, 'TOP') yT, yB = flame.cont_with_3x1_to_2x1(y0, psi1, y2, 'TOP') return alpha
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)
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)
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)
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)
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)
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)
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)
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)
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)
def Transpose_unb_var1(A, B): """ Transpose_unb_var1(matrix, matrix) Transposes matrix A and stores result in matrix B. Traverses matrix A from LEFT to RIGHT, matrix B from TOP to BOTTOM, and copies columns of A to rows of B. """ AL, AR = flame.part_1x2(A, \ 0, 'LEFT') BT, \ BB = flame.part_2x1(B, \ 0, 'TOP') while AL.shape[1] < A.shape[1]: A0, a1, A2 = flame.repart_1x2_to_1x3(AL, AR, \ 1, 'RIGHT') B0, \ b1t, \ B2 = flame.repart_2x1_to_3x1(BT, \ BB, \ 1, 'BOTTOM') laff.copy( a1, b1t ) AL, AR = flame.cont_with_1x3_to_1x2(A0, a1, A2, \ 'LEFT') BT, \ BB = flame.cont_with_3x1_to_2x1(B0, \ b1t, \ B2, \ 'TOP') flame.merge_2x1(BT, \ BB, B)
def Transpose_unb_var2(A, B): """ Transpose_unb_var1(matrix, matrix) Transposes matrix A and stores result in matrix B. Traverses matrix A from TOP to BOTTOM, matrix B from LEFT to RIGHT, and copies rows of A to columns of B. """ AT, \ AB = flame.part_2x1(A, \ 0, 'TOP') BL, BR = flame.part_1x2(B, \ 0, 'LEFT') while AT.shape[0] < A.shape[0]: A0, \ a1t, \ A2 = flame.repart_2x1_to_3x1(AT, \ AB, \ 1, 'BOTTOM') B0, b1, B2 = flame.repart_1x2_to_1x3(BL, BR, \ 1, 'RIGHT') laff.copy( a1t, b1 ) AT, \ AB = flame.cont_with_3x1_to_2x1(A0, \ a1t, \ A2, \ 'TOP') BL, BR = flame.cont_with_1x3_to_1x2(B0, b1, B2, \ 'LEFT') flame.merge_1x2(BL, BR, B)
def Mvmult_t_unb_var1(A, x, y): """ Mvmult_t_unb_var1(matrix, vector, vector) Computes y = A' * x + y using DOT products. Traverses matrix A from LEFT to RIGHT, vector y from TOP to BOTTOM. """ AL, AR = flame.part_1x2(A, \ 0, 'LEFT') yT, \ yB = flame.part_2x1(y, \ 0, 'TOP') while AL.shape[1] < A.shape[1]: A0, a1, A2 = flame.repart_1x2_to_1x3(AL, AR, \ 1, 'RIGHT') y0, \ psi1, \ y2 = flame.repart_2x1_to_3x1(yT, \ yB, \ 1, 'BOTTOM') laff.dots( a1, x, psi1 ) AL, AR = flame.cont_with_1x3_to_1x2(A0, a1, A2, \ 'LEFT') yT, \ yB = flame.cont_with_3x1_to_2x1(y0, \ psi1, \ y2, \ 'TOP') flame.merge_2x1(yT, \ yB, y)
def Mvmult_n_unb_var2(A, x, y): """ Mvmult_n_unb_var2(matrix, vector, vector) Compuyes y = A * x + y using AXPY operations. Traverses matrix A from LEFT to RIGHT, vector x from TOP to BOTTOM. """ AL, AR = flame.part_1x2(A, \ 0, 'LEFT') xT, \ xB = flame.part_2x1(x, \ 0, 'TOP') while AL.shape[1] < A.shape[1]: A0, a1, A2 = flame.repart_1x2_to_1x3(AL, AR, \ 1, 'RIGHT') x0, \ chi1, \ x2 = flame.repart_2x1_to_3x1(xT, \ xB, \ 1, 'BOTTOM') laff.axpy(chi1, a1, y) AL, AR = flame.cont_with_1x3_to_1x2(A0, a1, A2, \ 'LEFT') xT, \ xB = flame.cont_with_3x1_to_2x1(x0, \ chi1, \ x2, \ 'TOP')
def Mvmult_n_unb_var2(A, x, y): """ Mvmult_n_unb_var2(matrix, vector, vector) Compuyes y = A * x + y using AXPY operations. Traverses matrix A from LEFT to RIGHT, vector x from TOP to BOTTOM. """ AL, AR = flame.part_1x2(A, \ 0, 'LEFT') xT, \ xB = flame.part_2x1(x, \ 0, 'TOP') while AL.shape[1] < A.shape[1]: A0, a1, A2 = flame.repart_1x2_to_1x3(AL, AR, \ 1, 'RIGHT') x0, \ chi1, \ x2 = flame.repart_2x1_to_3x1(xT, \ xB, \ 1, 'BOTTOM') laff.axpy( chi1, a1, y ) AL, AR = flame.cont_with_1x3_to_1x2(A0, a1, A2, \ 'LEFT') xT, \ xB = flame.cont_with_3x1_to_2x1(x0, \ chi1, \ x2, \ 'TOP')
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)
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)
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)
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)
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)
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)
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)
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)