import sys sys.path.append(os.path.join(os.path.dirname(__file__),"../")) import pylarc import argparse from timeit import default_timer as timer if __name__ == '__main__': # Returns the count of a specified scalar in a json matrix file parser = argparse.ArgumentParser(description="Count the number of entries in a LARCmatrix json file with a given scalar value.") parser.add_argument("matrix_path", help="the path to the json file containing the LARC matrix") parser.add_argument("-x", "--scalar", default="0", help="the scalar value to count (default 0)") parser.add_argument("-v", "--verbose", action="store_true", help="set to verbose printing") larc_starter = pylarc.LarcSettings() larc_starter.addArgsToParser(parser) args = parser.parse_args() larc_starter.parseArgs(args) # Exit gracefully if matrix is too big (i.e, has either dimension > 1024) [mat_row_level, mat_col_level] = pylarc.get_levels_from_larcMatrix_file(args.matrix_path) if (mat_row_level > 10) or (mat_col_level > 10): print("Sorry, matrix is too big to process. Levels = [{0}, {1}]".format(mat_row_level, mat_col_level)) sys.exit(1) larc_starter.getLevelFromFiles(args.matrix_path) larc_starter.initLarc() # if args.verbose: # larc_starter.getLevelFromFiles(args.matrix_path)
parser.add_argument( "matrix_path", help="the path to write the json file containing the LARC matrix") parser.add_argument("num_ones", help="the number of 1's in the matrix") 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)