Exemplo n.º 1
0
def test_eval_spline_grid_simplest():
    npoint = 10
    boxsize = 2.0
    points = np.random.normal(0, boxsize, (npoint,3))
    #points = np.hstack([np.arange(0.0, 0.9001, 0.1).reshape(-1,1)]*3)
    g = IntGrid(points, np.random.normal(0, 1.0, npoint))
    cs = get_cosine_spline()
    cell = Cell(np.identity(3, float)*boxsize)

    output1 = np.zeros(npoint)
    g.eval_spline(cs, np.array([0.0, 0.0, 0.0]), output1, cell)
    output2 = np.zeros(npoint)
    g.eval_spline(cs, np.array([2.0, 0.0, 0.0]), output2, cell)
    assert abs(output1 - output2).max() < 1e-10
Exemplo n.º 2
0
def test_eval_spline_grid_simplest():
    npoint = 10
    boxsize = 2.0
    points = np.random.normal(0, boxsize, (npoint, 3))
    #points = np.hstack([np.arange(0.0, 0.9001, 0.1).reshape(-1,1)]*3)
    g = IntGrid(points, np.random.normal(0, 1.0, npoint))
    cs = get_cosine_spline()
    cell = Cell(np.identity(3, float) * boxsize)

    output1 = np.zeros(npoint)
    g.eval_spline(cs, np.array([0.0, 0.0, 0.0]), output1, cell)
    output2 = np.zeros(npoint)
    g.eval_spline(cs, np.array([2.0, 0.0, 0.0]), output2, cell)
    assert abs(output1 - output2).max() < 1e-10
Exemplo n.º 3
0
def test_eval_spline_grid_3d_random():
    npoint = 10
    for i in xrange(10):
        cell = get_random_cell(1.0, 3)
        rvecs = cell.rvecs
        points = np.dot(np.random.normal(-2, 3, (npoint,3)), rvecs)
        g = IntGrid(points, np.random.normal(0, 1.0, npoint))
        cs = get_cosine_spline()

        output1 = np.zeros(npoint)
        center1 = np.random.uniform(-10, 10, 3)
        g.eval_spline(cs, center1, output1, cell)
        output2 = np.zeros(npoint)
        center2 = center1 + np.dot(np.random.randint(-3, 3, 3), rvecs)
        g.eval_spline(cs, center2, output2, cell)

        assert abs(output1 - output2).max() < 1e-10
Exemplo n.º 4
0
def test_eval_spline_grid_3d_random():
    npoint = 10
    for i in xrange(10):
        cell = get_random_cell(1.0, 3)
        rvecs = cell.rvecs
        points = np.dot(np.random.normal(-2, 3, (npoint, 3)), rvecs)
        g = IntGrid(points, np.random.normal(0, 1.0, npoint))
        cs = get_cosine_spline()

        output1 = np.zeros(npoint)
        center1 = np.random.uniform(-10, 10, 3)
        g.eval_spline(cs, center1, output1, cell)
        output2 = np.zeros(npoint)
        center2 = center1 + np.dot(np.random.randint(-3, 3, 3), rvecs)
        g.eval_spline(cs, center2, output2, cell)

        assert abs(output1 - output2).max() < 1e-10
Exemplo n.º 5
0
def test_eval_spline_grid_0d_random():
    npoint = 10
    cs = get_cosine_spline()

    for i in xrange(10):
        cell = Cell(None)
        points = np.random.normal(-1, 1, (npoint,3))
        g = IntGrid(points, np.random.normal(0, 1.0, npoint))

        center = np.random.uniform(-1, 1, 3)

        output1 = np.zeros(npoint)
        g.eval_spline(cs, center, output1, cell)

        distances = np.sqrt(((center - g.points)**2).sum(axis=1))
        output2 = cs(distances)

        assert abs(output1 - output2).max() < 1e-10
Exemplo n.º 6
0
def test_eval_spline_grid_0d_random():
    npoint = 10
    cs = get_cosine_spline()

    for i in xrange(10):
        cell = Cell(None)
        points = np.random.normal(-1, 1, (npoint, 3))
        g = IntGrid(points, np.random.normal(0, 1.0, npoint))

        center = np.random.uniform(-1, 1, 3)

        output1 = np.zeros(npoint)
        g.eval_spline(cs, center, output1, cell)

        distances = np.sqrt(((center - g.points)**2).sum(axis=1))
        output2 = cs(distances)

        assert abs(output1 - output2).max() < 1e-10
Exemplo n.º 7
0
def test_eval_spline_grid_add_random():
    npoint = 10
    cs = get_cosine_spline()

    for i in xrange(10):
        cell = get_random_cell(1.0, np.random.randint(4))
        points = np.random.normal(-2, 3, (npoint,3))
        g = IntGrid(points, np.random.normal(0, 1.0, npoint))

        output1 = np.zeros(npoint)
        center1 = np.random.uniform(-2, 2, 3)
        g.eval_spline(cs, center1, output1, cell)

        output2 = np.zeros(npoint)
        center2 = np.random.uniform(-2, 2, 3)
        g.eval_spline(cs, center2, output2, cell)

        output3 = np.zeros(npoint)
        g.eval_spline(cs, center1, output3, cell)
        g.eval_spline(cs, center2, output3, cell)

        assert abs(output1 + output2 - output3).max() < 1e-10
Exemplo n.º 8
0
def test_eval_spline_grid_add_random():
    npoint = 10
    cs = get_cosine_spline()

    for i in xrange(10):
        cell = get_random_cell(1.0, np.random.randint(4))
        points = np.random.normal(-2, 3, (npoint, 3))
        g = IntGrid(points, np.random.normal(0, 1.0, npoint))

        output1 = np.zeros(npoint)
        center1 = np.random.uniform(-2, 2, 3)
        g.eval_spline(cs, center1, output1, cell)

        output2 = np.zeros(npoint)
        center2 = np.random.uniform(-2, 2, 3)
        g.eval_spline(cs, center2, output2, cell)

        output3 = np.zeros(npoint)
        g.eval_spline(cs, center1, output3, cell)
        g.eval_spline(cs, center2, output3, cell)

        assert abs(output1 + output2 - output3).max() < 1e-10