Exemplo n.º 1
0
def test_shift4():
    a = np.array([[0.,0,0],[0,1,0],[0,0,0]])
    b = np.empty_like(a)
    shift(a, b, 1, axis=1)
    assert_all_eq(b, np.roll(a,1,axis=1))
    shift(b, b, -2, axis=1)
    assert_all_eq(b, np.roll(a,-1,axis=1))
Exemplo n.º 2
0
def test_shift4():
    a = np.array([[0., 0, 0], [0, 1, 0], [0, 0, 0]])
    b = np.empty_like(a)
    shift(a, b, 1, axis=1)
    assert_all_eq(b, np.roll(a, 1, axis=1))
    shift(b, b, -2, axis=1)
    assert_all_eq(b, np.roll(a, -1, axis=1))
Exemplo n.º 3
0
def test_shift2():
    a = np.array([[1., 1., 1., 1.], [2., 2., 2., 2.]])
    shift(a, a, [1, -1], axis=1)
    assert_all_eq(a, [[0, 1, 1, 1], [2, 2, 2, 0]])
Exemplo n.º 4
0
 def func(a, s):
     b = np.empty_like(a)
     shift(b, b, s, axis=-1)
     assert_all_eq(b, 0)
Exemplo n.º 5
0
def test_shift2():
    a = np.array([[1.,1.,1.,1.],[2.,2.,2.,2.]])
    shift(a, a, [1,-1], axis=1)
    assert_all_eq(a, [[0,1,1,1],[2,2,2,0]])
Exemplo n.º 6
0
 def func(a, s):
     b = np.empty_like(a)
     shift(b, b, s, axis=-1)
     assert_all_eq(b, 0)
Exemplo n.º 7
0
    if any_neq(a, 0): raise TestFailure()

for axis in range(4):
    a=np.random.random_integers(1, 10, size=(8,9,10,11)).astype(float)
    ref = -np.diff(a, axis=axis)
    s = ref.shape
    udiff(a, axis=axis)
    a[:s[0],:s[1],:s[2],:s[3]] -= ref
    if any_neq(a, 0): raise TestFailure()

# shift

for a in (np.ones(10),np.ones((12,10))):
    for s in (10,11,100,-10,-11,-100):
        b = a.copy()
        shift(b,s,axis=-1)
        if any_neq(b, 0): raise TestFailure()

a = np.array([[1.,1.,1.,1.],[2.,2.,2.,2.]])
shift(a, [1,-1], axis=1)
if any_neq(a, [[0,1,1,1],[2,2,2,0]]): raise TestFailure()

a = np.array([[0.,0,0],[0,1,0],[0,0,0]])
b = a.copy()
shift(b, 1, axis=0)
if any_neq(b, np.roll(a,1,axis=0)): raise TestFailure()
shift(b, -2, axis=0)
if any_neq(b, np.roll(a,-1,axis=0)): raise TestFailure()
b = a.copy()
shift(b, 1, axis=1)
if any_neq(b, np.roll(a,1,axis=1)): raise TestFailure()