class TestNumpyXMatrix:
    @given(data(), shape_matrix())
    def test_input_as_tuples(self, data, shape):
        X = data.draw(numpy_X_matrices(shape))
        assert X.shape == shape

    @given(data())
    def test_input_as_strategy(self, data):
        data.draw(numpy_X_matrices(shape_matrix()))

    @given(data())
    def test_error_shape_0_smaller_shape_1(self, data):
        with pytest.raises(ValueError):
            data.draw(numpy_X_matrices([10, 20]))

    @given(data(), shape_matrix(), ordered_pair(32, 47))
    def test_min_max_values(self, data, shape, min_max_values):
        min_value, max_value = min_max_values
        X = data.draw(numpy_X_matrices(shape, min_value=min_value, max_value=max_value))
        assert X.min() >= min_value
        assert X.max() <= max_value

    @given(data(), shape_matrix())
    def test_no_nan(self, data, shape):
        X = data.draw(numpy_X_matrices(shape, allow_nan=False, allow_infinity=True))
        assert not np.isnan(X).any()

    @given(data(), shape_matrix())
    def test_no_infinity(self, data, shape):
        X = data.draw(numpy_X_matrices(shape, allow_nan=True, allow_infinity=False))
        assert not np.isinf(X).any()
示例#2
0
def numpy_X_matrices(
    draw,
    shape=shape_matrix(),
    min_value: float = None,
    max_value: float = None,
    allow_nan: bool = False,
    allow_infinity: bool = False,
):
    if not isinstance(shape, tuple) and not isinstance(shape, list):
        shape = draw(shape)
    if shape[0] <= shape[1]:
        raise ValueError(f"X.shape[0] must be <= X.shape[1]: {shape}")

    elements = floats(
        min_value=min_value,
        max_value=max_value,
        allow_nan=allow_nan,
        allow_infinity=allow_infinity,
    )

    X = draw(arrays(
        dtype=float,
        shape=shape,
        elements=elements,
    ))
    return X
 def test_input_as_strategy(self, data):
     data.draw(numpy_X_matrices(shape_matrix()))
示例#4
0
def test_shape_X(data, shape_0, shape_1):
    shape = data.draw(shape_matrix(*shape_0, *shape_1))
    assert shape_0[0] <= shape[0] <= shape_0[1]
    assert shape_1[0] <= shape[1] <= shape_1[1]