Ejemplo n.º 1
0
def _sincinterp(M, iava, dims=None, dir=0, dtype='float64'):
    """Sinc interpolation.
    """
    ncp = get_array_module(iava)

    _checkunique(iava)

    # create sinc interpolation matrix
    nreg = M if dims is None else dims[dir]
    ireg = ncp.arange(nreg)
    sinc = ncp.tile(iava[:, np.newaxis], (1, nreg)) - \
           ncp.tile(ireg, (len(iava), 1))
    sinc = ncp.sinc(sinc)

    # identify additional dimensions and create MatrixMult operator
    otherdims = None
    if dims is not None:
        otherdims = ncp.array(dims)
        otherdims = ncp.roll(otherdims, -dir)
        otherdims = otherdims[1:]
    Op = MatrixMult(sinc, dims=otherdims, dtype=dtype)

    # create Transpose operator that brings dir to first dimension
    if dir > 0:
        axes = np.arange(len(dims), dtype=np.int)
        axes = np.roll(axes, -dir)
        dimsd =  list(dims)
        dimsd[dir] = len(iava)
        Top = Transpose(dims, axes=axes, dtype=dtype)
        T1op = Transpose(dimsd, axes=axes, dtype=dtype)
        Op = T1op.H * Op * Top
    return Op
Ejemplo n.º 2
0
def test_Transpose_3dsignal(par):
    """Dot-test and adjoint for Transpose operator for 3d signals
    """
    dims = (par['ny'], par['nx'], par['nt'])
    x = np.arange(par['ny']*par['nx']*par['nt']).reshape(dims) + \
        par['imag'] * np.arange(par['ny']*par['nx']*par['nt']).reshape(dims)

    Top = Transpose(dims=dims, axes=(2, 1, 0))
    assert dottest(Top, np.prod(dims), np.prod(dims),
                   complexflag = 0 if par['imag'] == 0 else 3)

    y = Top * x.ravel()
    xadj = Top.H * y

    y = y.reshape(Top.dimsd)
    xadj = xadj.reshape(Top.dims)

    assert_equal(x, xadj)
Ejemplo n.º 3
0
def test_Transpose_2dsignal(par):
    """Dot-test and adjoint for Transpose operator for 2d signals"""
    dims = (par["ny"], par["nx"])
    x = np.arange(par["ny"] * par["nx"]).reshape(dims) + par["imag"] * np.arange(
        par["ny"] * par["nx"]
    ).reshape(dims)

    Top = Transpose(dims=dims, axes=(1, 0), dtype=par["dtype"])
    assert dottest(
        Top, np.prod(dims), np.prod(dims), complexflag=0 if par["imag"] == 0 else 3
    )
    y = Top * x.ravel()
    xadj = Top.H * y

    y = y.reshape(Top.dimsd)
    xadj = xadj.reshape(Top.dims)

    assert_equal(x, xadj)
    assert_equal(y, x.T)