Exemple #1
0
def test_hide_zero_padding_flat():
    r"""Test _hide_zero_padding with flat array."""
    array0 = np.array([0, 1, 5, 8, 0, 1])
    # check array with no padding
    np.testing.assert_almost_equal(_hide_zero_padding(array0), array0, decimal=6)
    array1 = np.array([0, 1, 5, 8, 0, 1, 0])
    np.testing.assert_almost_equal(_hide_zero_padding(array1), array0, decimal=6)
    array2 = np.array([0, 1, 5, 8, 0, 1, 0, 0, 0, 0])
    np.testing.assert_almost_equal(_hide_zero_padding(array2), array0, decimal=6)
Exemple #2
0
def test_hide_zero_padding_rectangular():
    r"""Test _hide_zero_padding by array with redundant row of zeros."""
    array0 = np.array([[1, 6, 0, 7, 8], [5, 7, 0, 22, 7]])
    # check array with no padding
    np.testing.assert_almost_equal(_hide_zero_padding(array0),
                                   array0,
                                   decimal=6)
    # check row-padded arrays
    array1 = np.array([[1, 6, 0, 7, 8], [5, 7, 0, 22, 7], [0, 0, 0, 0, 0]])
    np.testing.assert_almost_equal(_hide_zero_padding(array1),
                                   array0,
                                   decimal=6)
    array2 = np.array([[1, 6, 0, 7, 8], [5, 7, 0, 22, 7], [0, 0, 0, 0, 0],
                       [0, 0, 0, 0, 0]])
    np.testing.assert_almost_equal(_hide_zero_padding(array2),
                                   array0,
                                   decimal=6)
    # check column-padded arrays
    array3 = np.array([[1, 6, 0, 7, 8, 0], [5, 7, 0, 22, 7, 0]])
    np.testing.assert_almost_equal(_hide_zero_padding(array3),
                                   array0,
                                   decimal=6)
    array4 = np.array([[1, 6, 0, 7, 8, 0, 0, 0], [5, 7, 0, 22, 7, 0, 0, 0]])
    np.testing.assert_almost_equal(_hide_zero_padding(array4),
                                   array0,
                                   decimal=6)
    # check row- and column-padded arrays
    array5 = np.array([[1, 6, 0, 7, 8, 0, 0, 0], [5, 7, 0, 22, 7, 0, 0, 0],
                       [0, 0, 0, 0, 0, 0, 0, 0]])
    np.testing.assert_almost_equal(_hide_zero_padding(array5),
                                   array0,
                                   decimal=6)
Exemple #3
0
def test_hide_zero_padding_square():
    r"""Test _hide_zero_padding with squared array."""
    array0 = np.array([[0, 0.5, 1.0], [0, 3.1, 4.6], [0, 7.2, 9.2]])
    # check array with no padding
    np.testing.assert_almost_equal(_hide_zero_padding(array0), array0, decimal=6)
    # check row-padded arrays
    array1 = np.array(
        [[0, 0.5, 1.0], [0, 3.1, 4.6], [0, 7.2, 9.2], [0., 0., 0.]])
    np.testing.assert_almost_equal(_hide_zero_padding(array1), array0, decimal=6)
    # check column-padded arrays
    array2 = np.array([[0, 0.5, 1.0, 0], [0, 3.1, 4.6, 0], [0, 7.2, 9.2, 0]])
    np.testing.assert_almost_equal(_hide_zero_padding(array2), array0, decimal=6)
    array3 = np.array(
        [[0, 0.5, 1.0, 0, 0], [0, 3.1, 4.6, 0, 0], [0, 7.2, 9.2, 0, 0]])
    np.testing.assert_almost_equal(_hide_zero_padding(array3), array0, decimal=6)
    # check row- and column-padded arrays
    array4 = np.array([[0, 0.5, 1.0, 0, 0],
                       [0, 3.1, 4.6, 0, 0],
                       [0, 7.2, 9.2, 0, 0],
                       [0, 0.0, 0.0, 0, 0],
                       [0, 0.0, 0.0, 0, 0]])
    np.testing.assert_almost_equal(_hide_zero_padding(array4), array0, decimal=6)
    # check with close to zero values.
    array4 = np.array([[0, 0.5, 1.0, 1e-6, 1e-8],
                       [0, 3.1, 4.6, 1e-6, 1e-8],
                       [0, 7.2, 9.2, 1e-5, 1e-9],
                       [0, 0.0, 0.0, 0.0, 1e-8],
                       [0, 0.0, 0.0, 0.0, 0]])
    actual = np.array([[0, 0.5, 1.0, 1e-6],
                       [0., 3.1, 4.6, 1e-6],
                       [0., 7.2, 9.2, 1e-5]])
    np.testing.assert_almost_equal(_hide_zero_padding(array4), actual, decimal=6)