Skip to content

Commit

Permalink
add tests for umv/ndg reshape routines
Browse files Browse the repository at this point in the history
  • Loading branch information
espdev committed Jul 19, 2020
1 parent 7c5e5e2 commit 1bb29a5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/test_ndg.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_nd_2pt_array(shape: tuple):
(3, 4, 5, 6),
(3, 2, 2, 6, 2),
(3, 4, 5, 6, 7),
], ids=['1d_o2', '1d_o4', '2d_o2', '2d_o4', '3d_o2', '3d_o4', '4d_o2', '4d_o4', '5d_o2', '5d_o4'])
])
def test_nd_array(shape: tuple):
xdata = [np.arange(s) for s in shape]
ydata = np.arange(0, np.prod(shape)).reshape(shape)
Expand Down
71 changes: 71 additions & 0 deletions tests/test_reshape.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-

import pytest
import numpy as np

from csaps._reshape import ( # noqa
umv_coeffs_to_flatten,
umv_coeffs_to_canonical,
ndg_coeffs_to_flatten,
ndg_coeffs_to_canonical,
)


@pytest.mark.parametrize('shape_canonical, shape_flatten, pieces', [
((2, 1), (1, 2), 1),
((3, 6), (1, 18), 6),
((4, 3), (1, 12), 3),
((4, 30), (1, 120), 30),
((4, 5, 2), (2, 20), 5),
((4, 6, 3), (3, 24), 6),
((4, 120, 53), (53, 480), 120),
])
def test_umv_coeffs_reshape(shape_canonical: tuple, shape_flatten: tuple, pieces: int):
np.random.seed(1234)
arr_canonical_expected = np.random.randint(0, 99, size=shape_canonical)

arr_flatten = umv_coeffs_to_flatten(arr_canonical_expected)
assert arr_flatten.shape == shape_flatten

arr_canonical_actual = umv_coeffs_to_canonical(arr_flatten, pieces)
np.testing.assert_array_equal(arr_canonical_actual, arr_canonical_expected)


@pytest.mark.parametrize('shape_canonical, shape_flatten, pieces', [
# 1-d 2-ordered
((2, 3), (2, 3), (3,)),
((2, 4), (2, 4), (4,)),
((2, 5), (2, 5), (5,)),
# 1-d 3-ordered
((3, 3), (3, 3), (3,)),
((3, 4), (3, 4), (4,)),
((3, 5), (3, 5), (5,)),
# 1-d 4-ordered
((4, 3), (4, 3), (3,)),
((4, 4), (4, 4), (4,)),
((4, 5), (4, 5), (5,)),
# 2-d {2,4}-ordered
((2, 4, 3, 4), (6, 16), (3, 4)),
((4, 2, 3, 3), (12, 6), (3, 3)),
((4, 2, 4, 3), (16, 6), (4, 3)),
((2, 4, 4, 4), (8, 16), (4, 4)),
# 2-d {4,4}-ordered
((4, 4, 3, 3), (12, 12), (3, 3)),
# 3-d {4,4,4}-ordered
((4, 4, 4, 3, 3, 3), (12, 12, 12), (3, 3, 3)),
((4, 4, 4, 3, 5, 7), (12, 20, 28), (3, 5, 7)),
])
def test_ndg_coeffs_reshape(shape_canonical: tuple, shape_flatten: tuple, pieces: tuple):
np.random.seed(1234)
arr_canonical_expected = np.random.randint(0, 99, size=shape_canonical)

arr_flatten = ndg_coeffs_to_flatten(arr_canonical_expected)
assert arr_flatten.shape == shape_flatten

arr_canonical_actual = ndg_coeffs_to_canonical(arr_flatten, pieces)
np.testing.assert_array_equal(arr_canonical_actual, arr_canonical_expected)

0 comments on commit 1bb29a5

Please sign in to comment.