def Set_to_zero_unb_var1(A): """ Set_to_zero_unb_var1(matrix) Sets the input matrix to zeros. Traverses input matrix from LEFT to RIGHT and sets results column-wise. """ AL, \ AR = flame.part_1x2(A, \ 0, 'LEFT') while AL.shape[1] < A.shape[1]: A0, \ a1, \ A2 = flame.repart_1x2_to_1x3(AL, \ AR, \ 1, 'RIGHT') laff.zerov(a1) AL, \ AR = flame.cont_with_1x3_to_1x2(A0, \ a1, \ A2, 'LEFT') flame.merge_1x2(AL, \ AR, A)
def trsm_lnu(L, B): BL, BR = flame.part_1x2(B, 0, "LEFT") while BL.shape[1] < B.shape[1]: B0, b1, B2 = flame.repart_1x2_to_1x3(BL, BR, 1, "RIGHT") # ------------------------------------------------------------# laff.trsv("Lower triangular", "No transpose", "Unit diagonal", L, b1) # ------------------------------------------------------------# BL, BR = flame.cont_with_1x3_to_1x2(B0, b1, B2, "LEFT") flame.merge_1x2(BL, BR, B)
def trsm_lutu(U, B): BL, BR = flame.part_1x2(B, \ 0, 'LEFT') while BL.shape[1] < B.shape[1]: B0, b1, B2 = flame.repart_1x2_to_1x3(BL, BR, \ 1, 'RIGHT') #------------------------------------------------------------# trsv('Upper triangular', 'Transpose', 'Unit diagonal', U, b1) #------------------------------------------------------------# BL, BR = flame.cont_with_1x3_to_1x2(B0, b1, B2, \ 'LEFT') flame.merge_1x2(BL, BR, B)
def trsm_llnu(L, B): BL, BR = flame.part_1x2(B, \ 0, 'LEFT') while BL.shape[1] < B.shape[1]: B0, b1, B2 = flame.repart_1x2_to_1x3(BL, BR, \ 1, 'RIGHT') #------------------------------------------------------------# trsv( 'Lower triangular', 'No transpose', 'Unit diagonal', L, b1 ) #------------------------------------------------------------# BL, BR = flame.cont_with_1x3_to_1x2(B0, b1, B2, \ 'LEFT') flame.merge_1x2(BL, BR, B)
def trsm_llnn(L, B): BL, BR = flame.part_1x2(B, \ 0, 'LEFT') while BL.shape[1] < B.shape[1]: B0, b1, B2 = flame.repart_1x2_to_1x3(BL, BR, \ 1, 'RIGHT') #------------------------------------------------------------# trsv( 'Lower triangular', 'No transpose', 'Nonunit diagonal', L, b1 ) #------------------------------------------------------------# BL, BR = flame.cont_with_1x3_to_1x2(B0, b1, B2, \ 'LEFT') flame.merge_1x2(BL, BR, 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 trsm_unn(U, B): BL, BR = flame.part_1x2(B, \ 0, 'LEFT') while BL.shape[1] < B.shape[1]: B0, b1, B2 = flame.repart_1x2_to_1x3(BL, BR, \ 1, 'RIGHT') #------------------------------------------------------------# laff.trsv('Upper triangular', 'No transpose', 'Nonunit diagonal', U, b1) #------------------------------------------------------------# 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 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 Scale_a_matrix_unb_var1(beta, A): """ Scale_a_matrix_unb_var1(scalar, matrix) Scales matrix A by a factor of beta. Traverses matrix A from LEFT to RIGHT. """ AL, AR = flame.part_1x2(A, \ 0, 'LEFT') while AL.shape[1] < A.shape[1]: A0, a1, A2 = flame.repart_1x2_to_1x3(AL, AR, \ 1, 'RIGHT') laff.scal(beta,a1) AL, AR = flame.cont_with_1x3_to_1x2(A0, a1, A2, \ 'LEFT') flame.merge_1x2(AL, AR, A)
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')