# creating or finding the matrix associated with the array serial = pylarc.row_major_list_to_store_matrixID(arr, level, level, dim_whole) ######################### # add metadata to store # ######################### info_name = "DATE" info_type = pylarc.get_info_type_from_string_name(info_name) info_data = "20170707" print("Loading %s of %s to info_store" % (info_name, info_data)) fail = pylarc.info_set(info_type, serial, info_data) if fail: print("Unable to write data to info store") else: print("Wrote data to info_store") info_name = "COMPUTER" info_type = pylarc.get_info_type_from_string_name(info_name) info_data = "a226" print("Loading %s of %s to info_store" % (info_name, info_data)) fail = pylarc.info_set(info_type, serial, info_data) if fail: print("Unable to write data to info store") else: print("Wrote data to info_store") # write out LARCMatrix file local_name = "../dat/out/infoTest1.json" out_name = os.path.join(os.path.dirname(__file__), local_name) print("Writing LARCMatrix file with info attached to %s" % out_name) pylarc.write_larcMatrix_file_by_matID(serial, out_name)
for i in range(dim_whole) ] elif scalarTypeStr in ("Real", "MPReal", "MPRational"): randVals = [random.random() for i in range(dim_whole)] else: raise Exception('Do not know how to build matrix for type %s.' % scalarTypeStr) # create circulant matrix from the dim_whole random numbers a = [] b = randVals for i in range(dim_whole): a.append(list(b)) b.insert(0, b.pop(-1)) #print("a: ", a) amat = np.matrix(a) alist = amat.reshape(-1).tolist()[0] #print(alist) arr = pylarc.map_to_str(alist, scalarTypeStr) #print('arr:', pylarc.str_scalarTypeArray(arr, len(alist))) # creating or finding the matrix associated with the array serial = pylarc.row_major_list_to_store_matrixID(arr, level, level, dim_whole) filename_json = "../dat/out/circulant.lev%d.%s.json" % (level, scalarTypeStr) # pylarc.print_naive_by_matID(serial) # print("\n") pylarc.write_larcMatrix_file_by_matID( serial, os.path.join(os.path.dirname(__file__), filename_json))
################################### ## Look at info store contents ################################### pylarc.list_info_names() # info_name = "DATE" # info_type = pylarc.get_info_type_from_string_name(info_name) # info_data = pylarc.info_get(info_type, inFile_ID) # print("info_data = *%s* for info_name = %s\n" %(info_data,info_name)) # info_name = "COMPUTER" # info_type = pylarc.get_info_type_from_string_name(info_name) # info_data = pylarc.info_get(info_type, inFile_ID) # print("info_data = *%s* for info_name = %s\n" %(info_data,info_name)) max_info_type = pylarc.get_info_type_from_string_name("INVALID_INFO") for info_type in range(max_info_type): info_name = pylarc.return_info_name(info_type) info_data = pylarc.info_get(info_type, inFile_ID) if (info_data != ""): print("info_data = *%s* for info_name = %s\n" % (info_data, info_name)) ################################### ## Write copy of test file ################################### local_name = "../dat/out/infoTest2.json" out_name = os.path.join(os.path.dirname(__file__), local_name) pylarc.write_larcMatrix_file_by_matID(inFile_ID, out_name) print("Printing the file %s\n" % out_name)
x = 2**25 more = [x, 2**100, 2**50, 2**75] myFirstMatID = pylarc.row_major_list_to_store_matrixID(list(map(str, more)), 1, 1, 2) print("my first matrix is") pylarc.print_naive_by_matID(myFirstMatID) print("\nentry squared and then multiplied by 10 is") squareID = pylarc.matrix_entrySquared_matrixID(myFirstMatID, "10") pylarc.print_naive_by_matID(squareID) myfile = "../tests/dat/out/temp_" + typeChar + "_matrix.json" print(myfile) pylarc.write_larcMatrix_file_by_matID(squareID, myfile) # lets look at the result of building an identity and zero matrix # from scratch using the row major reader and print vals = [0 for i in range(64)] vals_string = pylarc.map_to_str(vals, "Integer") zeroID_3_3 = pylarc.row_major_list_to_store_matrixID(vals_string, 3, 3, 8) print("The 8 by 8 Zero matrix is") pylarc.print_naive_by_matID(zeroID_3_3) vals = [1 * (0 == (i % 9)) for i in range(64)] vals_string = pylarc.map_to_str(vals, "Integer") identityID_3 = pylarc.row_major_list_to_store_matrixID(vals_string, 3, 3, 8) print("The 8 by 8 identity matrix is") pylarc.print_naive_by_matID(identityID_3)
parser.add_argument("-r", "--row_level", type=int, default=4, help="row level for the matrix (default 4)") parser.add_argument("-c", "--col_level", type=int, default=4, help="column level for the matrix (default 4)") larc_initer = pylarc.LarcSettings() larc_initer.addArgsToParser(parser) args = parser.parse_args() larc_initer.parseArgs(args) larc_initer.max_mat_level = max(args.row_level, args.col_level) # initialize larc # with pylarc.stdout_redirected(): larc_initer.initLarc() # generate matrix matID = pylarc.random_bool_matrixID_from_count(args.row_level, args.col_level, args.num_ones) # write matrix to file pylarc.write_larcMatrix_file_by_matID(matID, args.matrix_path)
# parameters for entering the python array into the store level = 2 dim_whole = 2**level # creating or finding the matrix associated with the array serial = pylarc.row_major_list_to_store_matrixID(alist_strs, level, level, dim_whole) pylarc.print_naive_by_matID(serial) print("\n") # Make a parent matrix from four copies of the serial matrix print("Creating matrix from get_matID_from_four_subMatIDs on panel input and writing LARCMatrix file\n") panel = [serial]*4 # alternatively panel=[serial,serial,serial,serial] serial_parent = pylarc.get_matID_from_four_subMatIDs(serial,serial,serial,serial,3,3) pylarc.print_naive_by_matID(serial_parent) filename = "../dat/out/testfile.%s.json" %scalarTypeStr pylarc.write_larcMatrix_file_by_matID(serial_parent,os.path.join(os.path.dirname(__file__), filename)) # PLAYING WITH PREWRITTEN REVERSIBLE NAND LARCMatrix FILE print("About to test read LARCMatrix file\n") filename = "../dat/in/nand.%s.json" %scalarTypeStr nand_matrixID = pylarc.read_larcMatrix_file_return_matID(os.path.join(os.path.dirname(__file__),filename)) print("We read in the LARCMatrix nand file\n") pylarc.print_naive_by_matID(nand_matrixID) print("\n") # TESTING READING AND WRITING OF MATRICES print("Testing reading row major matrix format and writing files in LARCMatrix and naive format.\n") filename_rmm = "../dat/in/sample.1.1.%s.rmm" %scalarTypeStr filename_naive = "../dat/out/sample.1.1.%s.naive" %scalarTypeStr filename_json = "../dat/out/sample.1.1.%s.json" %scalarTypeStr
pylarc.print_naive_by_matID(serial) print("\n") # Make a parent matrix from four copies of the serial matrix print( "Creating matrix from get_matID_from_four_subMatIDs on panel input and writing LARCMatrix file\n" ) zero2 = pylarc.get_zero_matrixID(2, 2) # panel = [serial,zero2,zero2,serial] top_matID = pylarc.get_matID_from_four_subMatIDs(serial, zero2, zero2, serial, 3, 3) pylarc.print_naive_by_matID(top_matID) filename = "../dat/out/blocktest.%s.json" % scalarTypeStr pylarc.write_larcMatrix_file_by_matID( top_matID, os.path.join(os.path.dirname(__file__), filename)) verbose = 1 # 0 run quiet, 1 warn if not block diagonal, 2 be chatty # run our test code for finding the matrix IDs of block diagonals blockLevel = 4 print("\nTEST with blocklevel %d" % blockLevel) block_array = pylarc.list_block_diagonal_matrixIDs(top_matID, blockLevel, verbose) print(block_array) # run our test code for finding the matrix IDs of block diagonals blockLevel = 3 print("\nTEST with blocklevel %d" % blockLevel) block_array = pylarc.list_block_diagonal_matrixIDs(top_matID, blockLevel, verbose)