Exemple #1
0
    F_2 = pylarc.create_fft_matrix_matrixID(2)
    pylarc.print_naive_by_matID(F_2)

    print("\nF_3 matrix is:")
    F_3 = pylarc.create_fft_matrix_matrixID(3)
    pylarc.print_naive_by_matID(F_3)

    #################################
    # create FFT matrices in python #
    #################################
    print("\nCreate a vector\n")
    A_arr = list(map(str, [1, 0, 0, 0, 0, 1, 0, 0]))
    rowLevel = 3
    colLevel = 0
    dimWhole = 1 << colLevel
    A_mID = pylarc.row_major_list_to_store_matrixID(A_arr, rowLevel, colLevel,
                                                    dimWhole)
    pylarc.print_naive_by_matID(A_mID)

    print("Now multiply FFT matrix by the vector to get the result\n")
    B_mID = pylarc.matrix_mult_matrixID(F_3, A_mID)
    pylarc.print_naive_by_matID(B_mID)

    #################################
    # precision test                #
    #################################

    k = 3
    print("\nCalculating the principal 2^%d-th root of unity:" % k)
    root_matID = pylarc.principal_pow2_root_unity(k)

    print("\nPrinting 2^%d-th root of unity:" % k)
Exemple #2
0
            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))
Exemple #3
0
    x = 3.77 * (2**5)
    more = [x, x * 2**10, x * 2**15, x * 2**20]
elif typeChar == 'c':  # reformat to C style strings
    # note that python represents complex #s as a+b*1j
    # and we've set up our C code to expect them as a+I*b
    # also note that we can have no spaces between characters!
    x = "3.77+I*2.34"
    more = [x, "27.1+I*0", "0+I*27.1", "3.77+I*-2.34"]
elif typeChar == 'q':  # need a better way to do this
    x = "32/3"
    more = [x, "57/5", "22/7", "16/33"]
else:  # in case we define another type
    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)]
Exemple #4
0
    verbose = 1
    pylarc.initialize_larc(mat_store_exp, op_store_exp, max_level,
                           rnd_sig_bits, trunc_to_zero_bits, verbose)

    pylarc.create_report_thread(1800)

    # Define string for using in formating filenames
    scalarTypeStr = pylarc.cvar.scalarTypeStr

    # MAKE a matrix to test Globbing
    # two by two tests
    level = 1
    dim_whole = 2**level

    arr_a = list(map(str, [.4, 0, 0, .3]))
    a_mID = pylarc.row_major_list_to_store_matrixID(arr_a, level, level,
                                                    dim_whole)
    arr_b = list(map(str, [.8, 0, 0, .6]))
    b_mID = pylarc.row_major_list_to_store_matrixID(arr_b, level, level,
                                                    dim_whole)
    arr_c = list(map(str, [-.4, 0, 0, -.3]))
    c_mID = pylarc.row_major_list_to_store_matrixID(arr_c, level, level,
                                                    dim_whole)
    print("The matrixIDs of a, b, and c are %d %d %d\n" %
          (a_mID, b_mID, c_mID))

    d_mID = pylarc.matrix_add_matrixID(a_mID, a_mID)

    print("matrix a:")
    pylarc.print_naive_by_matID(a_mID)

    print("\nMatrix id of a + a: %d, should be that of b: %d \n" %
Exemple #5
0

    
    # turn the matrix into an array by reading off each row in turn (row major format)
    alist = a.reshape(-1).tolist()[0]
    alist_strs = pylarc.map_to_str(alist, scalarTypeStr)
    # arr = pylarc.buildArray(alist)
    # print 'arr:', pylarc.str_scalarTypeArray(arr, len(alist))
    print("alist_str:", alist_strs)

    # 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))
Exemple #6
0
        a = np.matrix([[1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j],
                       [8 + 7j, 6 + 5j, 3 + 4j, 1 + 2j],
                       [9 + 10j, 11 + 12j, 13 + 14j, 15 + 16j],
                       [16 + 15j, 14 + 13j, 12 + 11j, 10 + 9j]])
    elif scalarTypeStr in ("Real", "MPReal", "MPRational"):
        a = np.matrix([[1, 3, .5, 6], [8, 6, 3, .1], [-9, 11, 13, 1.5],
                       [16, 13, 12, 10]])
    else:
        raise Exception('Do not know how to build matrix for type %s.' %
                        scalarTypeStr)

    # test our new function matrix_is_zero_matrixID(z_matID))
    z = np.matrix([[0, 0], [0, 0]])
    zlist = z.reshape(-1).tolist()[0]
    zlist_strs = pylarc.map_to_str(zlist, scalarTypeStr)
    z_matID = pylarc.row_major_list_to_store_matrixID(zlist_strs, 1, 1, 2)
    pylarc.print_naive_by_matID(z_matID)
    print("\nThe fucntion matrix_is_zero_matrixID returns:")
    print(pylarc.matrix_is_zero_matrixID(z_matID))
    print("\n")

    # turn the matrix into an array by reading off each row in turn (row major format)
    alist = a.reshape(-1).tolist()[0]
    alist_strs = pylarc.map_to_str(alist, scalarTypeStr)
    # arr = pylarc.buildArray(alist)
    # print 'arr:', pylarc.str_scalarTypeArray(arr, len(alist))
    print("alist_str:", alist_strs)

    # parameters for entering the python array into the store
    level = 2
    dim_whole = 2**level
Exemple #7
0
#                       [8, 6, 3, .1],
#                       [-9, 11, 13, 1.5],
#                       [16, 13, 12, 10]])
    else:
        raise Exception('Do not know how to build matrix for type %s.' %
                        scalarTypeStr)

    print("COLUMN_COLUMN CASE")
    # turn the matrix into an array by reading off each row in turn (row major format)
    alist = a.reshape(-1).tolist()[0]
    aarr = pylarc.map_to_str(alist, scalarTypeStr)
    # print('array A:', pylarc.str_scalarTypeArray(aarr, len(alist)))
    print('array A:', aarr)

    # creating or finding the matrix associated with the array
    serial_a = pylarc.row_major_list_to_store_matrixID(aarr, 3, 0, 1)
    pylarc.print_naive_by_matID(serial_a)
    print("\n")

    # turn the matrix into an array by reading off each row in turn (row major format)
    blist = b.reshape(-1).tolist()[0]
    barr = pylarc.map_to_str(blist, scalarTypeStr)
    # print('array B:', pylarc.str_scalarTypeArray(barr, len(blist)))
    print('array B:', barr)

    # creating or finding the matrix associated with the array
    serial_b = pylarc.row_major_list_to_store_matrixID(barr, 2, 0, 1)
    pylarc.print_naive_by_matID(serial_b)
    print("\n")

    print("kronecker product A \otimes B:")