MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_nocopy_wrapper

Function test_nocopy_wrapper

tests/test_eigen_matrix.py:614–668  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

612
613
614def test_nocopy_wrapper():
615 # get_elem requires a column-contiguous matrix reference, but should be
616 # callable with other types of matrix (via copying):
617 int_matrix_colmajor = np.array(
618 [[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype="l", order="F"
619 )
620 dbl_matrix_colmajor = np.array(
621 int_matrix_colmajor, dtype="double", order="F", copy=True
622 )
623 int_matrix_rowmajor = np.array(int_matrix_colmajor, order="C", copy=True)
624 dbl_matrix_rowmajor = np.array(
625 int_matrix_rowmajor, dtype="double", order="C", copy=True
626 )
627
628 # All should be callable via get_elem:
629 assert m.get_elem(int_matrix_colmajor) == 8
630 assert m.get_elem(dbl_matrix_colmajor) == 8
631 assert m.get_elem(int_matrix_rowmajor) == 8
632 assert m.get_elem(dbl_matrix_rowmajor) == 8
633
634 # All but the second should fail with m.get_elem_nocopy:
635 with pytest.raises(TypeError) as excinfo:
636 m.get_elem_nocopy(int_matrix_colmajor)
637 assert "get_elem_nocopy(): incompatible function arguments." in str(excinfo.value)
638 assert ', "flags.f_contiguous"' in str(excinfo.value)
639 assert m.get_elem_nocopy(dbl_matrix_colmajor) == 8
640 with pytest.raises(TypeError) as excinfo:
641 m.get_elem_nocopy(int_matrix_rowmajor)
642 assert "get_elem_nocopy(): incompatible function arguments." in str(excinfo.value)
643 assert ', "flags.f_contiguous"' in str(excinfo.value)
644 with pytest.raises(TypeError) as excinfo:
645 m.get_elem_nocopy(dbl_matrix_rowmajor)
646 assert "get_elem_nocopy(): incompatible function arguments." in str(excinfo.value)
647 assert ', "flags.f_contiguous"' in str(excinfo.value)
648
649 # For the row-major test, we take a long matrix in row-major, so only the third is allowed:
650 with pytest.raises(TypeError) as excinfo:
651 m.get_elem_rm_nocopy(int_matrix_colmajor)
652 assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
653 excinfo.value
654 )
655 assert ', "flags.c_contiguous"' in str(excinfo.value)
656 with pytest.raises(TypeError) as excinfo:
657 m.get_elem_rm_nocopy(dbl_matrix_colmajor)
658 assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
659 excinfo.value
660 )
661 assert ', "flags.c_contiguous"' in str(excinfo.value)
662 assert m.get_elem_rm_nocopy(int_matrix_rowmajor) == 8
663 with pytest.raises(TypeError) as excinfo:
664 m.get_elem_rm_nocopy(dbl_matrix_rowmajor)
665 assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
666 excinfo.value
667 )
668 assert ', "flags.c_contiguous"' in str(excinfo.value)
669
670
671def test_eigen_ref_life_support():

Callers

nothing calls this directly

Calls 2

strClass · 0.85
arrayMethod · 0.80

Tested by

no test coverage detected