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: 6 additions & 7 deletions pywt/_swt.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,9 @@ def iswt2(coeffs, wavelet, norm=False, axes=(-2, -1)):
raise RuntimeError(
"Mismatch in shape of intermediate coefficient arrays")

# make sure output shares the common dtype
# (conversion of dtype for individual coeffs is handled within idwt2 )
common_dtype = np.result_type(*(
[dt, ] + [_check_dtype(c) for c in [cH, cV, cD]]))
# Include the approximation reconstructed from all coarser levels.
common_dtype = np.result_type(output.dtype, _check_dtype(cH),
_check_dtype(cV), _check_dtype(cD))
if output.dtype != common_dtype:
output = output.astype(common_dtype)

Expand Down Expand Up @@ -703,9 +702,9 @@ def iswtn(coeffs, wavelet, axes=None, norm=False):
if not trim_approx:
a = coeffs[j].pop('a'*ndim_transform) # will restore later
details = coeffs[j]
# make sure dtype matches the coarsest level approximation coefficients
common_dtype = np.result_type(*(
[dt, ] + [v.dtype for v in details.values()]))
# Include the approximation reconstructed from all coarser levels.
common_dtype = np.result_type(output.dtype,
*(v.dtype for v in details.values()))
if output.dtype != common_dtype:
output = output.astype(common_dtype)

Expand Down
14 changes: 14 additions & 0 deletions pywt/tests/test_swt.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,20 @@ def test_iswt2_mixed_dtypes():
assert_allclose(y, x, rtol=1e-3, atol=1e-3)


@pytest.mark.parametrize('axes', [(-2, -1), (0, 1)])
def test_iswt2_complex_coarse_detail(axes):
# The equivalent axis specifications exercise iswt2 and its iswtn path.
zeros = np.zeros((8, 8))
detail = zeros.copy()
detail[0, 0] = 1

def reconstruct(horizontal):
coeffs = [zeros, (horizontal, zeros, zeros), (zeros, zeros, zeros)]
return pywt.iswt2(coeffs, 'haar', axes=axes)

assert_allclose(reconstruct(1j * detail), 1j * reconstruct(detail))


def test_iswtn_mixed_dtypes():
# Mixed precision inputs give double precision output
rstate = np.random.RandomState(0)
Expand Down