Beispiel #1
0
def test_coerce_shape_array_non_int():
    shape = (2, 3)
    array = np.random.random((3, 2))
    expected = np.append(array[:2, :], [[0], [0]], axis=1)
    actual = _coerce_shape(array, shape)
    assert (expected == actual).all()
    assert expected.dtype == np.float
Beispiel #2
0
def test_coerce_shape_3d_pad_nrows_and_trim_ncols():
    shape = (5, 2)
    array = np.arange(2 * 4 * 3).reshape(2, 4, 3)
    expected = np.array([[[0, 1, 2], [3, 4, 5]], [[12, 13, 14], [15, 16, 17]],
                         [[0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0]],
                         [[0, 0, 0], [0, 0, 0]]])
    actual = _coerce_shape(array, shape)
    assert (expected == actual).all()
Beispiel #3
0
def test_coerce_shape_3d_pad_ncols_and_trim_nrows():
    shape = (2, 5)
    array = np.arange(3 * 2 * 4).reshape(3, 2, 4)
    expected = np.array([[[0, 1, 2, 3], [4, 5, 6, 7], [0, 0, 0, 0],
                          [0, 0, 0, 0], [0, 0, 0, 0]],
                         [[8, 9, 10, 11], [12, 13, 14, 15], [0, 0, 0, 0],
                          [0, 0, 0, 0], [0, 0, 0, 0]]])
    actual = _coerce_shape(array, shape)
    assert (expected == actual).all()
Beispiel #4
0
def test_coerce_shape_raises_error_if_shape_not_len_2():
    shape = (2, 3, 3)
    array = np.arange(3**3).reshape(3, 3, 3)
    with pytest.raises(ValueError,
                       match='coerce_shape must be an iterable of len 2'):
        _coerce_shape(array, shape)
Beispiel #5
0
def test_coerce_shape_3d_no_change():
    shape = (3, 3)
    array = np.arange(3**3).reshape(3, 3, 3)
    actual = _coerce_shape(array, shape)
    assert (array == actual).all()
Beispiel #6
0
def test_coerce_shape_2d_pad_ncols_and_trim_nrows():
    shape = (2, 4)
    array = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
    expected = np.array([[1, 2, 0, 0], [3, 4, 0, 0]])
    actual = _coerce_shape(array, shape)
    assert (expected == actual).all()
Beispiel #7
0
def test_coerce_shape_2d_pad_nrows_and_trim_ncols():
    shape = (4, 2)
    array = np.array([[1, 2, 7], [3, 4, 6]])
    expected = np.array([[1, 2], [3, 4], [0, 0], [0, 0]])
    actual = _coerce_shape(array, shape)
    assert (expected == actual).all()
Beispiel #8
0
def test_coerce_shape_2d_pad_only():
    shape = (3, 4)
    array = np.array([[1, 2], [3, 4]])
    expected = np.array([[1, 2, 0, 0], [3, 4, 0, 0], [0, 0, 0, 0]])
    actual = _coerce_shape(array, shape)
    assert (expected == actual).all()
Beispiel #9
0
def test_coerce_shape_2d_trim_only(im):
    shape = (2, 2)
    array = np.array(im)
    expected = np.array([[1, 2], [3, 4]])
    actual = _coerce_shape(array, shape)
    assert (expected == actual).all()