示例#1
0
def benchmark_test(minsize, maxsize, step, repeat):
    plot_data = []
    y_sp       = []
    y_block  = []
    y_no = []
    for i in range(minsize, maxsize, step):
        test_sp = []
        test_no = []
        test_partial = []
        test_complete = []
        test_rook = []
        test_block = []

        for j in range(repeat):
            # pos_def = tests.generate_pos_dif(i, 1, 1000)
            A = np.random.randint(-1000, 1000, size=(i, i))   # change
            # Ab = np.random.randint(-1000, 1000, size=(i, 1))  # change

            time_start = time.clock()
            sp.lu(A)
            test_sp += [time.clock() - time_start]

            time_start = time.clock()
            lu.lu_in_place(A)
            test_no += [time.clock() - time_start]

            time_start = time.clock()
            lu.lu_partial_pivot(A)
            test_partial += [time.clock() - time_start]

            time_start = time.clock()
            lu.lu_complete_pivot(A)
            test_complete += [time.clock() - time_start]

            time_start = time.clock()
            lu.lu_rook_pivot(A)
            test_rook += [time.clock() - time_start]

            time_start = time.clock()
            lu_block.lu_partial_block(A, 32)
            test_block += [time.clock() - time_start]


            # time_start = time.clock()
            # lu.lu_partial_pivot(A)
            # test_no += [time.clock() - time_start]

            print i, j

        plot_data += [{
            'y': test_sp,
            'type':'box',
            'marker':{'color': 'black'},
            'name': str(i) + 'x' + str(i),
            'boxpoints': False
            }]

        plot_data += [{
            'y': test_no,
            'type':'box',
            'marker':{'color': 'grey'},
            'name': str(i) + 'x' + str(i),
            'boxpoints': False
            }]

        plot_data += [{
            'y': test_partial,
            'type':'box',
            'marker':{'color': 'blue'},
            'name': str(i) + 'x' + str(i),
            'boxpoints': False
            }]

        plot_data += [{
            'y': test_complete,
            'type':'box',
            'marker':{'color': 'red'},
            'name': str(i) + 'x' + str(i),
            'boxpoints': False
            }]

        plot_data += [{
            'y': test_rook,
            'type':'box',
            'marker':{'color': 'green'},
            'name': str(i) + 'x' + str(i),
            'boxpoints': False
            }]

        plot_data += [{
            'y': test_block,
            'type':'box',
            'marker':{'color': 'purple'},
            'name': str(i) + 'x' + str(i),
            'boxpoints': False
            }]
            # plot_data += [{
            #     'y': test_no,
            #     'type':'box',
            #     'marker':{'color': 'blue'},
            #     'name': str(i) + 'x' + str(i),
            #     'boxpoints': False
            #     }]
            #
            # y_sp += [np.sum(test_sp) / len(test_sp)]
            # y_block += [np.sum(test_block) / len(test_block)]
            # y_no += [np.sum(test_no) / len(test_no)]

    # print np.polyfit(range(len(y_sp)), y_sp, 1, full=True)
    # print np.polyfit(range(len(y_sp)), y_sp, 2, full=True)
    # print np.polyfit(range(len(y_block)), y_block, 1, full=True)
    # print np.polyfit(range(len(y_block)), y_block, 2, full=True)
    # print np.polyfit(range(len(y_no)), y_no, 1, full=True)
    # print np.polyfit(range(len(y_no)), y_no, 2, full=True)


    url = py.plot(plot_data, filename='Benchmark')
示例#2
0
 def test_lu_inplace(self):
     rand_int_matrix = np.random.randint(-1000, 1000, size=(1000, 1000))
     np.array_equal(lu.lu_in_place(rand_int_matrix)[0], lu.lu_inplace_with_dot(rand_int_matrix)[0])
     np.array_equal(lu.lu_in_place(rand_int_matrix)[1], lu.lu_inplace_with_dot(rand_int_matrix)[1])