From 51439896239570da704cb1328ce12174d3f0308c Mon Sep 17 00:00:00 2001 From: Dean Moldovan Date: Tue, 28 Feb 2017 18:07:51 +0100 Subject: [PATCH] Fix compilation of Eigen casters with complex scalars --- include/pybind11/numpy.h | 2 +- tests/test_eigen.cpp | 1 + tests/test_eigen.py | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index ea9914a4..29b139bf 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -731,7 +731,7 @@ public: template ::value, int> = 0> static PYBIND11_DESCR name() { return _::value || std::is_same::value>( - _("complex") + _(), _("longcomplex")); + _("complex") + _(), _("longcomplex")); } }; diff --git a/tests/test_eigen.cpp b/tests/test_eigen.cpp index 32905433..98711b08 100644 --- a/tests/test_eigen.cpp +++ b/tests/test_eigen.cpp @@ -66,6 +66,7 @@ test_initializer eigen([](py::module &m) { m.def("double_col", [](const Eigen::VectorXf &x) -> Eigen::VectorXf { return 2.0f * x; }); m.def("double_row", [](const Eigen::RowVectorXf &x) -> Eigen::RowVectorXf { return 2.0f * x; }); + m.def("double_complex", [](const Eigen::VectorXcf &x) -> Eigen::VectorXcf { return 2.0f * x; }); m.def("double_threec", [](py::EigenDRef x) { x *= 2; }); m.def("double_threer", [](py::EigenDRef x) { x *= 2; }); m.def("double_mat_cm", [](Eigen::MatrixXf x) -> Eigen::MatrixXf { return 2.0f * x; }); diff --git a/tests/test_eigen.py b/tests/test_eigen.py index 50c2a11a..c57ba277 100644 --- a/tests/test_eigen.py +++ b/tests/test_eigen.py @@ -129,7 +129,7 @@ def test_pass_readonly_array(): def test_nonunit_stride_from_python(): from pybind11_tests import ( - double_row, double_col, double_mat_cm, double_mat_rm, + double_row, double_col, double_complex, double_mat_cm, double_mat_rm, double_threec, double_threer) counting_mat = np.arange(9.0, dtype=np.float32).reshape((3, 3)) @@ -137,8 +137,10 @@ def test_nonunit_stride_from_python(): second_col = counting_mat[:, 1] np.testing.assert_array_equal(double_row(second_row), 2.0 * second_row) np.testing.assert_array_equal(double_col(second_row), 2.0 * second_row) + np.testing.assert_array_equal(double_complex(second_row), 2.0 * second_row) np.testing.assert_array_equal(double_row(second_col), 2.0 * second_col) np.testing.assert_array_equal(double_col(second_col), 2.0 * second_col) + np.testing.assert_array_equal(double_complex(second_col), 2.0 * second_col) counting_3d = np.arange(27.0, dtype=np.float32).reshape((3, 3, 3)) slices = [counting_3d[0, :, :], counting_3d[:, 0, :], counting_3d[:, :, 0]] @@ -564,7 +566,7 @@ def test_special_matrix_objects(): def test_dense_signature(doc): - from pybind11_tests import double_col, double_row, double_mat_rm + from pybind11_tests import double_col, double_row, double_complex, double_mat_rm assert doc(double_col) == """ double_col(arg0: numpy.ndarray[float32[m, 1]]) -> numpy.ndarray[float32[m, 1]] @@ -572,6 +574,9 @@ def test_dense_signature(doc): assert doc(double_row) == """ double_row(arg0: numpy.ndarray[float32[1, n]]) -> numpy.ndarray[float32[1, n]] """ + assert doc(double_complex) == """ + double_complex(arg0: numpy.ndarray[complex64[m, 1]]) -> numpy.ndarray[complex64[m, 1]] + """ assert doc(double_mat_rm) == """ double_mat_rm(arg0: numpy.ndarray[float32[m, n]]) -> numpy.ndarray[float32[m, n]] """