def writeCoeffs(coeffs): U = transpose(coeffs[0]) V = transpose(coeffs[1]) W = transpose(coeffs[2]) print("U:") printmat(U) print("V:") printmat(V) print("W:") printmat(W) print("")
def writeEquation(coeffs, dims_mix): for eq_index in range(len(coeffs[0][0])): m_mat_name = "M" + str(eq_index) my_eq_str = "" for coeff_index in range(len(coeffs)): #print "coeff_index:" + str(coeff_index) name_list = getName( coeff_index) # 0: a, gamma; 1: b, delta; 2: c, alpha coeff_list = transpose(coeffs[coeff_index]) my_eq_coeff_list = coeff_list[eq_index] if (coeff_index == 0): #A my_eq_str = my_eq_str + m_mat_name + "=( " elif (coeff_index == 1): #B my_eq_str = my_eq_str + " )( " elif (coeff_index == 2): #C my_eq_str += " );\n " else: print("Coeff_index not supported!\n") nz_index = 0 for item_index in range(len(my_eq_coeff_list)): if (is_nonzero(my_eq_coeff_list[item_index])): mat_name = getActualBlockName(coeff_index, item_index, dims_mix) if (coeff_index == 0 or coeff_index == 1): # A or B mat_prefix = "" if (is_negone(my_eq_coeff_list[item_index])): mat_prefix = "-" elif (is_one(my_eq_coeff_list[item_index])): if (nz_index == 0): mat_prefix = "" else: mat_prefix = "+" else: mat_prefix = "+(" + str( my_eq_coeff_list[item_index]) + ")" #print "%d:%s" % ( item_index, my_eq_coeff_list[ item_index ] ) #print "entry should be either 1 or -1!" my_eq_str += mat_prefix + mat_name elif (coeff_index == 2): mat_suffix = "" if (is_negone(my_eq_coeff_list[item_index])): mat_suffix = "-=" elif (is_one(my_eq_coeff_list[item_index])): mat_suffix = "+=" else: mat_suffix = "+=(" + str( my_eq_coeff_list[item_index]) + ") " #print "%d:%s" % ( item_index, my_eq_coeff_list[ item_index ] ) #print "entry should be either 1 or -1!" my_eq_str += mat_name + mat_suffix + m_mat_name + ";" else: print("Coeff_index not support!\n") #write_line( myfile, 0, str( coeff_index ) + " " + str( item_index ) ) #write_line( myfile, 0, "{0}_list[{1}] = {2}; {3}_list[{1}] = {4};".format( name_list[0], str(nz_index), getBlockName( coeff_index, item_index, dims, level ), name_list[1], my_eq_coeff_list[ item_index ] ) ) nz_index += 1 print(my_eq_str)
def generateCoeffs(coeffs_mix): coeffs = coeffs_mix[0] UM = transpose(coeffs[0]) VM = transpose(coeffs[1]) WM = transpose(coeffs[2]) for ii in range(len(coeffs_mix) - 1): coeffs = coeffs_mix[ii + 1] U = transpose(coeffs[0]) V = transpose(coeffs[1]) W = transpose(coeffs[2]) UM = phantomMatMul(UM, U) VM = phantomMatMul(VM, V) WM = phantomMatMul(WM, W) res_coeffs = [transpose(UM), transpose(VM), transpose(WM)] return res_coeffs