Exemple #1
0
def test_collocation_interpolation_identity():
    # Check if interpolation followed by collocation on the same grid
    # is the identity
    rect = odl.IntervalProd([0, 0], [1, 1])
    part = odl.uniform_partition_fromintv(rect, [4, 2])
    space = odl.FunctionSpace(rect)
    dspace = odl.rn(part.size)

    coll_op_c = PointCollocation(space, part, dspace, order='C')
    coll_op_f = PointCollocation(space, part, dspace, order='F')
    interp_ops_c = [
        NearestInterpolation(space, part, dspace, variant='left', order='C'),
        NearestInterpolation(space, part, dspace, variant='right', order='C'),
        LinearInterpolation(space, part, dspace, order='C'),
        PerAxisInterpolation(space, part, dspace, order='C',
                             schemes=['linear', 'nearest'])]
    interp_ops_f = [
        NearestInterpolation(space, part, dspace, variant='left', order='F'),
        NearestInterpolation(space, part, dspace, variant='right', order='F'),
        LinearInterpolation(space, part, dspace, order='F'),
        PerAxisInterpolation(space, part, dspace, order='F',
                             schemes=['linear', 'nearest'])]

    values = np.arange(1, 9, dtype='float64')

    for interp_op_c in interp_ops_c:
        ident_values = coll_op_c(interp_op_c(values))
        assert all_almost_equal(ident_values, values)

    for interp_op_f in interp_ops_f:
        ident_values = coll_op_f(interp_op_f(values))
        assert all_almost_equal(ident_values, values)
Exemple #2
0
def test_collocation_interpolation_identity():
    """Check if collocation is left-inverse to interpolation."""
    # Interpolation followed by collocation on the same grid should be
    # the identity
    rect = odl.IntervalProd([0, 0], [1, 1])
    part = odl.uniform_partition_fromintv(rect, [4, 2])
    space = odl.FunctionSpace(rect)
    tspace = odl.rn(part.shape)

    coll_op = PointCollocation(space, part, tspace)
    interp_ops = [
        NearestInterpolation(space, part, tspace, variant='left'),
        NearestInterpolation(space, part, tspace, variant='right'),
        LinearInterpolation(space, part, tspace),
        PerAxisInterpolation(space,
                             part,
                             tspace,
                             schemes=['linear', 'nearest'])
    ]

    values = np.arange(1, 9, dtype='float64').reshape(tspace.shape)

    for interp_op in interp_ops:
        ident_values = coll_op(interp_op(values))
        assert all_almost_equal(ident_values, values)
Exemple #3
0
def test_collocation_cuda():
    rect = odl.Rectangle([0, 0], [1, 1])
    part = odl.uniform_partition_fromintv(rect, [4, 2])
    space = odl.FunctionSpace(rect)
    dspace = odl.CudaRn(part.size)

    coll_op = PointCollocation(space, part, dspace)
    interp_op = LinearInterpolation(space, part, dspace)

    values = np.arange(1, 9, dtype='float64')
    ident_values = coll_op(interp_op(values))
    assert all_almost_equal(ident_values, values)