1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
import os
import numpy as np
from dtcwt.opencl.lowlevel import colifilt
from dtcwt.numpy.lowlevel import colifilt as colifilt_gold
from dtcwt.coeffs import biort, qshift
from pytest import raises
from .util import assert_almost_equal, skip_if_no_cl
import tests.datasets as datasets
def setup_module():
global mandrill
mandrill = datasets.mandrill()
def test_mandrill_loaded():
assert mandrill.shape == (512, 512)
assert mandrill.min() >= 0
assert mandrill.max() <= 1
assert mandrill.dtype == np.float32
@skip_if_no_cl
def test_odd_filter():
with raises(ValueError):
colifilt(mandrill, (-1,2,-1), (-1,2,1))
@skip_if_no_cl
def test_different_size_h():
with raises(ValueError):
colifilt(mandrill, (-1,2,1), (-0.5,-1,2,-1,0.5))
@skip_if_no_cl
def test_zero_input():
Y = colifilt(np.zeros_like(mandrill), (-1,1), (1,-1))
assert np.all(Y[:0] == 0)
@skip_if_no_cl
def test_bad_input_size():
with raises(ValueError):
colifilt(mandrill[:511,:], (-1,1), (1,-1))
@skip_if_no_cl
def test_good_input_size():
Y = colifilt(mandrill[:,:511], (-1,1), (1,-1))
Z = colifilt_gold(mandrill[:,:511], (-1,1), (1,-1))
assert_almost_equal(Y,Z)
@skip_if_no_cl
def test_output_size():
Y = colifilt(mandrill, (-1,1), (1,-1))
assert Y.shape == (mandrill.shape[0]*2, mandrill.shape[1])
Z = colifilt_gold(mandrill, (-1,1), (1,-1))
assert_almost_equal(Y,Z)
@skip_if_no_cl
def test_non_orthogonal_input():
Y = colifilt(mandrill, (1,1), (1,1))
assert Y.shape == (mandrill.shape[0]*2, mandrill.shape[1])
Z = colifilt_gold(mandrill, (1,1), (1,1))
assert_almost_equal(Y,Z)
@skip_if_no_cl
def test_output_size_non_mult_4():
Y = colifilt(mandrill, (-1,0,0,1), (1,0,0,-1))
assert Y.shape == (mandrill.shape[0]*2, mandrill.shape[1])
Z = colifilt_gold(mandrill, (-1,0,0,1), (1,0,0,-1))
assert_almost_equal(Y,Z)
@skip_if_no_cl
def test_non_orthogonal_input_non_mult_4():
Y = colifilt(mandrill, (1,0,0,1), (1,0,0,1))
assert Y.shape == (mandrill.shape[0]*2, mandrill.shape[1])
Z = colifilt_gold(mandrill, (1,0,0,1), (1,0,0,1))
assert_almost_equal(Y,Z)
@skip_if_no_cl
def test_qshift():
h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')
y = colifilt(mandrill, h1b, h1b)
z = colifilt_gold(mandrill, h1b, h1a)
assert_almost_equal(y, z)
# This test fails. I'm not sure if that's expected or not because it is using
# colifilt in an odd way.
#
# @skip_if_no_cl
# def test_qshift_odd_len_input_1():
# h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')
# h1a = h1a[:-2]
# h1b = h1a[::-1]
# y = colifilt(mandrill, h1a, h1b)
# z = colifilt_gold(mandrill, h1a, h1b)
# assert_almost_equal(y, z)
@skip_if_no_cl
def test_qshift_odd_len_input_2():
h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')
y = colifilt(mandrill, h1a[1:-1], h1b[1:-1])
z = colifilt_gold(mandrill, h1a[1:-1], h1b[1:-1])
assert_almost_equal(y, z)
@skip_if_no_cl
def test_qshift_even_input():
h1b = np.array((-0.25, 0.5, 0.5, -0.25))
h1a = h1b[::-1]
y = colifilt(mandrill, h1b, h1a)
z = colifilt_gold(mandrill, h1b, h1a)
assert_almost_equal(y, z)
# vim:sw=4:sts=4:et
|