예제 #1
0
def test_performance_F():

    from numpy import linspace, column_stack, repeat, tile
    import time

    N_x = 1000
    N_y = 7777
    x = linspace(1,N_x,N_x)
    y = linspace(1,N_y,N_y)

    cartesian([x[:10],y[:10]]) # warmup

    t1 = time.time()
    for i in range(100):
        prod = cartesian([x,y], order='F')
    t2 = time.time()
    # print(prod.shape)

    # compute the same produce using numpy:
    import numpy

    t3 = time.time()
    for i in range(100):
        prod_numpy = column_stack([
            tile(x,N_y),
            repeat(y,N_x)
        ])
    t4 = time.time()

    print("Timings for 'cartesian'(Fortran order)")
    print("Cartesian: {}".format(t2-t1))
    print("Numpy:     {}".format(t4-t3))
    assert(abs(prod-prod_numpy).max()==0)
예제 #2
0
def test_performance_F():

    from numpy import linspace, column_stack, repeat, tile
    import time

    N_x = 1000
    N_y = 7777
    x = linspace(1, N_x, N_x)
    y = linspace(1, N_y, N_y)

    cartesian([x[:10], y[:10]])  # warmup

    t1 = time.time()
    for i in range(100):
        prod = cartesian([x, y], order='F')
    t2 = time.time()
    # print(prod.shape)

    # compute the same produce using numpy:
    import numpy

    t3 = time.time()
    for i in range(100):
        prod_numpy = column_stack([tile(x, N_y), repeat(y, N_x)])
    t4 = time.time()

    print("Timings for 'cartesian'(Fortran order)")
    print("Cartesian: {}".format(t2 - t1))
    print("Numpy:     {}".format(t4 - t3))
    assert (abs(prod - prod_numpy).max() == 0)
예제 #3
0
def test_cartesian_C_order_int_float():

    from numpy import arange, linspace

    x_int = arange(10)
    x_float = linspace(0,9,10)
    prod_int = cartesian([x_int]*3)
    prod_float = cartesian([x_float]*3)
    assert(prod_int.dtype==x_int.dtype)
    assert(prod_float.dtype==x_float.dtype)
    assert( abs(prod_int-prod_float).max()==0)
예제 #4
0
def test_mlinsplace():

    from numpy import linspace
    from quantecon.cartesian import mlinspace

    grid1 = mlinspace([-1, -1], [2, 3], [30, 50])
    grid2 = cartesian([linspace(-1, 2, 30), linspace(-1, 3, 50)])
예제 #5
0
def test_mlinsplace():

    from numpy import linspace
    from quantecon.cartesian import mlinspace

    grid1 = mlinspace([-1,-1],[2,3],[30,50])
    grid2 = cartesian([linspace(-1,2,30), linspace(-1,3,50)])
예제 #6
0
def test_cartesian_F_order():

    from numpy import linspace
    x = linspace(0, 9, 10)

    prod = cartesian([x, x, x], order='F')

    correct = True
    for i in range(999):
        n = prod[i, 2] * 100 + prod[i, 1] * 10 + prod[i, 0]
        correct *= (i == n)

    assert (correct)
예제 #7
0
def test_cartesian_F_order():

    from numpy import linspace
    x = linspace(0,9,10)

    prod = cartesian([x,x,x], order='F')

    correct = True
    for i in range(999):
        n = prod[i,2]*100+prod[i,1]*10+prod[i,0]
        correct *= (i == n)

    assert(correct)