Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pywt/_extensions/c/wavelets_coeffs.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -1618,12 +1618,21 @@ static const TYPE CAT(db38_, TYPE)[76] = {
-1.716152451088744188732404281737964277713026087224248235541071e-18};


/* sym2 and sym3 coincide with db2 and db3; retain their precision. */
static const TYPE CAT(sym2_, TYPE)[4] = {
0.48296291314469025, 0.83651630373746899, 0.22414386804185735, -0.12940952255092145
4.829629131445341433748715998644486838169524195042022752011715e-01,
8.365163037378079055752937809168732034593703883484392934953414e-01,
2.241438680420133810259727622404003554678835181842717613871683e-01,
-1.294095225512603811744494188120241641745344506599652569070016e-01
};

static const TYPE CAT(sym3_, TYPE)[6] = {
0.33267055295095688, 0.80689150931333875, 0.45987750211933132, -0.13501102001039084, -0.085441273882241486, 0.035226291882100656
3.326705529500826159985115891390056300129233992450683597084705e-01,
8.068915093110925764944936040887134905192973949948236181650920e-01,
4.598775021184915700951519421476167208081101774314923066433867e-01,
-1.350110200102545886963899066993744805622198452237811919756862e-01,
-8.544127388202666169281916918177331153619763898808662976351748e-02,
3.522629188570953660274066471551002932775838791743161039893406e-02
};

static const TYPE CAT(sym4_, TYPE)[8] = {
Expand Down
29 changes: 28 additions & 1 deletion pywt/tests/test_wavelet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import pickle

import numpy as np
from numpy.testing import assert_, assert_allclose
import pytest
from numpy.testing import assert_, assert_allclose, assert_equal

import pywt

Expand Down Expand Up @@ -276,3 +277,29 @@ def test_wavelet_pickle(tmpdir):
wavelet2 = pickle.load(f)
assert isinstance(wavelet2, pywt.Wavelet)
assert wavelet2.name == wavelet.name


@pytest.mark.parametrize("order", [2, 3])
def test_low_order_symlet_coefficients(order):
# Daubechies and symlet filter taps coincide for these orders.
# https://people.tamu.edu/~brani/wavelet/wp/problem.pdf
symlet = pywt.Wavelet(f"sym{order}")
daubechies = pywt.Wavelet(f"db{order}")
assert_equal(symlet.filter_bank, daubechies.filter_bank)


@pytest.mark.parametrize("order", [2, 3])
@pytest.mark.parametrize("dtype", [np.float32, np.float64,
np.complex64, np.complex128])
@pytest.mark.parametrize("mode", pywt.Modes.modes)
def test_low_order_symlet_reconstruction(order, dtype, mode):
rng = np.random.default_rng(978)
data = rng.standard_normal(65)
if np.issubdtype(dtype, np.complexfloating):
data = data + 1j * rng.standard_normal(65)
data = data.astype(dtype)
wavelet = pywt.Wavelet(f"sym{order}")
coeffs = pywt.wavedec(data, wavelet, mode=mode, level=3)
reconstructed = pywt.waverec(coeffs, wavelet, mode=mode)[:len(data)]
error = np.linalg.norm(reconstructed - data) / np.linalg.norm(data)
assert error < 8 * np.finfo(data.real.dtype).eps