import pytest

with pytest.suppress(ImportError):
    import numpy as np

    ref = np.array([[0, 3, 0, 0, 0, 11], [22, 0, 0, 0, 17, 11],
                    [7, 5, 0, 1, 0, 11], [0, 0, 0, 0, 0, 11],
                    [0, 0, 14, 0, 8, 11]])


def assert_equal_ref(mat):
    np.testing.assert_array_equal(mat, ref)


def assert_sparse_equal_ref(sparse_mat):
    assert_equal_ref(sparse_mat.todense())


@pytest.requires_eigen_and_numpy
def test_fixed():
    from pybind11_tests import fixed_r, fixed_c, fixed_passthrough_r, fixed_passthrough_c

    assert_equal_ref(fixed_c())
    assert_equal_ref(fixed_r())
    assert_equal_ref(fixed_passthrough_r(fixed_r()))
    assert_equal_ref(fixed_passthrough_c(fixed_c()))
    assert_equal_ref(fixed_passthrough_r(fixed_c()))
    assert_equal_ref(fixed_passthrough_c(fixed_r()))


@pytest.requires_eigen_and_numpy
示例#2
0
import pytest

pytestmark = pytest.requires_eigen_and_numpy

with pytest.suppress(ImportError):
    import numpy as np

    ref = np.array([[ 0.,  3,  0,  0,  0, 11],
                    [22,  0,  0,  0, 17, 11],
                    [ 7,  5,  0,  1,  0, 11],
                    [ 0,  0,  0,  0,  0, 11],
                    [ 0,  0, 14,  0,  8, 11]])


def assert_equal_ref(mat):
    np.testing.assert_array_equal(mat, ref)


def assert_sparse_equal_ref(sparse_mat):
    assert_equal_ref(sparse_mat.todense())


def test_fixed():
    from pybind11_tests import fixed_r, fixed_c, fixed_copy_r, fixed_copy_c

    assert_equal_ref(fixed_c())
    assert_equal_ref(fixed_r())
    assert_equal_ref(fixed_copy_r(fixed_r()))
    assert_equal_ref(fixed_copy_c(fixed_c()))
    assert_equal_ref(fixed_copy_r(fixed_c()))
    assert_equal_ref(fixed_copy_c(fixed_r()))