def base_counts(coeff_set): """ Count the number of additions, reads, and writes for this coefficient set (A, B, or C). For A and B, these are the adds used to form the 'S' and 'T' matrices. If an S or T matrix is just a length-1 addition chain, then no additions are counted. """ cols = subexpr_elim.transpose(coeff_set) num_adds = sum([gen.num_nonzero(col) - 1 for col in cols]) num_reads = sum([gen.num_nonzero(col) for col in cols]) num_writes = sum([1 for col in cols if gen.num_nonzero(col) > 1]) return (num_adds, num_reads, num_writes)
def main(): try: coeff_file = sys.argv[1] dims = tuple([int(d) for d in sys.argv[2].split(',')]) except: raise Exception('USAGE: python stability_vector.py coeff_file m,k,n') full_stab_mat = 0 if len(sys.argv) > 3: full_stab_mat = sys.argv[3] coeffs = read_coeffs(coeff_file) # Using the notation from our paper a_vec = np.array( [sum(np.abs([float(x) for x in row])) for row in transpose(coeffs[0])]) b_vec = np.array( [sum(np.abs([float(x) for x in row])) for row in transpose(coeffs[1])]) e_vec = [ np.dot(np.abs([float(x) for x in row]), a_vec * b_vec) for row in coeffs[2] ] alpha_vec = np.array([num_nonzero(row) for row in transpose(coeffs[0])]) beta_vec = np.array([num_nonzero(row) for row in transpose(coeffs[1])]) ab_vec = alpha_vec + beta_vec gamma_vec = [num_nonzero(row) for row in coeffs[2]] W_ind = np.array([[float(val) for val in row] for row in coeffs[2]]) W_ind[np.nonzero(W_ind)] = 1 q_vec = [gamma_vec[k] + np.max(ab_vec * W_ind[k,:]) \ for k in range(W_ind.shape[0])] # Number of additions nnz = sum([val for val in ab_vec]) + sum([val for val in gamma_vec]) # print as q_vec emax rank = len(coeffs[0][0]) mkn = dims[0] * dims[1] * dims[2] print mkn, rank, nnz, int(np.max(q_vec)), int(np.max(e_vec)) if full_stab_mat: # Print in the same style as D'Alberto presents in his 2014 paper. print 'e vector:' for i in range(dims[0]): out_format = '\t' + ' '.join(['%4d' for _ in range(dims[2])]) vals = e_vec[(i * dims[2]):(i * dims[2] + dims[2])] print out_format % tuple(vals) print 'q vector:' for i in range(dims[0]): out_format = '\t' + ' '.join(['%4d' for _ in range(dims[2])]) vals = q_vec[(i * dims[2]):(i * dims[2] + dims[2])] print out_format % tuple(vals)
def elim_counts(elim_info): """ Count the number of additions, reads, and writes for the elimination variables of a single coefficient set (for S matrices, T matrix, or M matrices). """ if any(map(lambda x: len(x) == 0, elim_info)): return (0, 0, 0) num_adds = sum([gen.num_nonzero(row) - 1 for row in elim_info]) num_reads = sum([gen.num_nonzero(row) for row in elim_info]) num_writes = len(elim_info) return (num_adds, num_reads, num_writes)
def main(): try: coeff_file = sys.argv[1] dims = tuple([int(d) for d in sys.argv[2].split(',')]) except: raise Exception('USAGE: python stability_vector.py coeff_file m,k,n') full_stab_mat = 0 if len(sys.argv) > 3: full_stab_mat = sys.argv[3] coeffs = read_coeffs(coeff_file) # Using the notation from our paper a_vec = np.array([sum(np.abs([float(x) for x in row])) for row in transpose(coeffs[0])]) b_vec = np.array([sum(np.abs([float(x) for x in row])) for row in transpose(coeffs[1])]) e_vec = [np.dot(np.abs([float(x) for x in row]), a_vec * b_vec) for row in coeffs[2]] alpha_vec = np.array([num_nonzero(row) for row in transpose(coeffs[0])]) beta_vec = np.array([num_nonzero(row) for row in transpose(coeffs[1])]) ab_vec = alpha_vec + beta_vec gamma_vec = [num_nonzero(row) for row in coeffs[2]] W_ind = np.array([[float(val) for val in row] for row in coeffs[2]]) W_ind[np.nonzero(W_ind)] = 1 q_vec = [gamma_vec[k] + np.max(ab_vec * W_ind[k,:]) \ for k in range(W_ind.shape[0])] # Number of additions nnz = sum([val for val in ab_vec]) + sum([val for val in gamma_vec]) # print as q_vec emax rank = len(coeffs[0][0]) mkn = dims[0] * dims[1] * dims[2] print mkn, rank, nnz, int(np.max(q_vec)), int(np.max(e_vec)) if full_stab_mat: # Print in the same style as D'Alberto presents in his 2014 paper. print 'e vector:' for i in range(dims[0]): out_format = '\t' + ' '.join(['%4d' for _ in range(dims[2])]) vals = e_vec[(i * dims[2]):(i * dims[2] + dims[2])] print out_format % tuple(vals) print 'q vector:' for i in range(dims[0]): out_format = '\t' + ' '.join(['%4d' for _ in range(dims[2])]) vals = q_vec[(i * dims[2]):(i * dims[2] + dims[2])] print out_format % tuple(vals)