Ejemplo n.º 1
0
    # 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)]
vals_string = pylarc.map_to_str(vals, "Integer")
zeroID_3_3 = pylarc.row_major_list_to_store_matrixID(vals_string, 3, 3, 8)
Ejemplo n.º 2
0
        else:
            print("  not printing files of nonzero matrices\n")

    print(
        "Finished creating LARC matrix and op stores and loading basic matrices.\n"
    )
    print(
        "Seppuku check to see if program is to large to occur once every 10 minutes.\n"
    )

    ################################
    # inverse permutation matrices #
    ################################
    print("\nPI_0 matrix is:")
    PI_0 = pylarc.create_perm_inv_matrixID(0)
    pylarc.print_naive_by_matID(PI_0)

    print("\nPI_1 matrix is:")
    PI_1 = pylarc.create_perm_inv_matrixID(1)
    pylarc.print_naive_by_matID(PI_1)

    print("\nPI_2 matrix is:")
    PI_2 = pylarc.create_perm_inv_matrixID(2)
    pylarc.print_naive_by_matID(PI_2)

    print("\nPI_3 matrix is:")
    PI_3 = pylarc.create_perm_inv_matrixID(3)
    pylarc.print_naive_by_matID(PI_3)

    # print("\nPI_4 matrix is:")
    # PI_4 = pylarc.create_perm_inv_matrixID(4)
Ejemplo n.º 3
0
    trunc_to_zero_bits = -1  # default value
    pylarc.create_report_thread(1800)
    verbose = 1
    pylarc.initialize_larc(mat_store_exp, op_store_exp, max_level,
                           rnd_sig_bits, trunc_to_zero_bits, verbose)

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

    #  PLAYING WITH PREWRITTEN NONSQUARE MATRIX
    filename = "../dat/in/sample.1.2.%s.json" % scalarTypeStr
    print("About to test read %s\n" % filename)
    samp_matrixID = pylarc.read_larcMatrix_file_return_matID(
        os.path.join(os.path.dirname(__file__), filename))
    print("We read in the LARCMatrix file\n")
    pylarc.print_naive_by_matID(samp_matrixID)

    print("does scalarM1_val print?")
    scalarM1_val = '-1'
    scalarM1_matrixID = pylarc.get_valID_from_valString(scalarM1_val)
    pylarc.print_naive_by_matID(scalarM1_matrixID)

    print("testing scalar_mult:")
    samp2_matrixID = pylarc.scalar_mult_matrixID(scalarM1_matrixID,
                                                 samp_matrixID)
    pylarc.print_naive_by_matID(samp2_matrixID)

    print("testing addition:")
    samp3_matrixID = pylarc.matrix_add_matrixID(samp_matrixID, samp2_matrixID)
    pylarc.print_naive_by_matID(samp3_matrixID)
Ejemplo n.º 4
0
    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" %
          (d_mID, b_mID))
    if (d_mID == b_mID):
        print("a + a PASSED: \n")
        pylarc.print_naive_by_matID(d_mID)
    else:
        print("FAILED: [.4,0,0,.3] + [.4,0,0,.3] = [.8,0,0,.6]\n")

    arr_prod1 = list(map(str, [.16, 0, 0, .09]))
    prod1_mID = pylarc.row_major_list_to_store_matrixID(
        arr_prod1, level, level, dim_whole)
    arr_e = list(map(str, [1, -1, -1, 1]))
    e_mID = pylarc.row_major_list_to_store_matrixID(arr_e, level, level,
                                                    dim_whole)
Ejemplo n.º 5
0
 print(
     "\nRunning code to produce a list of matrixIDs for all the %d-th roots of unity."
     % n)
 n_array = [0] * (n)
 if (verbose > 1):
     print("The length of the array is %d" % len(n_array))
 for k in range(n):
     n_array[k] = pylarc.k_th_power_of_n_th_root_of_unity_matID(
         k, n, call_verbose)
 print("\nHere is the array of the %dth roots of unity:" % n)
 print(n_array)
 if (verbose > 1):
     print("\nThe stored values of these roots are:")
     print("")
     for k in range(n):
         pylarc.print_naive_by_matID(n_array[k])
         print("")
 print("\nNow we can look to see if multiplication is closed, by looking")
 print("at the matrixIDs of products of pairs of these roots.")
 success = 1
 for k in range(n):
     for j in range(k + 1):
         my_matrixID = pylarc.matrix_mult_matrixID(n_array[j], n_array[k])
         flag = 0  # initialize as though there was a closure failure
         for i in range(n):
             if (my_matrixID == n_array[i]):
                 flag = 1  # we found the matrixID of product in the preloaded roots
         if (flag == 0):
             success = 0
             print(
                 "\nMatrix multiplication of the %d-th roots of unity is not closed"
Ejemplo n.º 6
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))
    print("We read in the LARCMatrix nand file\n")
Ejemplo n.º 7
0
                       [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
Ejemplo n.º 8
0
#                       [-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:")
    serial_c = pylarc.kronecker_product_matrixID(serial_a, serial_b)
Ejemplo n.º 9
0
    scalarTypeStr = pylarc.cvar.scalarTypeStr

    # Calculate number of matrices created, then print part of matrix store
    num_matrices_made = pylarc.num_matrices_created()
    print("\n%d matrices have been created" %num_matrices_made)
    end = num_matrices_made - 1
    filename = "../dat/out/preload.%s.store" %scalarTypeStr
    pylarc.matrix_store_info_to_file(0,end,os.path.join(os.path.dirname(__file__),filename),"After preload with parameters: 26, 24, 10.")

    #  PLAYING WITH PREWRITTEN NONSQUARE MATRIX
    filename = "../dat/in/sample.1.2.%s.json" %scalarTypeStr
    print("About to test read %s\n" %filename)
    samp_mID = pylarc.read_larcMatrix_file_return_matID(os.path.join(os.path.dirname(__file__),filename))

    print("We read in the LARCMatrix file\n")
    pylarc.print_naive_by_matID(samp_mID)
    print("\n")

    # build array in C from Python list of scalars
    print("Using row_major_list_to_store on data entered from python\n")

    # create a matrix in python
    if scalarTypeStr in ("Integer", "MPInteger"): 
        a = np.matrix([[1, 3, 5, 6],
                       [8, 6, 3, 1],
                       [-9, 11, 13, 15],
                       [16, 13, 12, 10]])
    elif scalarTypeStr in ("Complex", "MPComplex", "MPRatComplex"): 
        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],