Skip to content

Commit 5143989

Browse files
dean0x7dwjakob
authored andcommitted
Fix compilation of Eigen casters with complex scalars
1 parent 5687b33 commit 5143989

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

include/pybind11/numpy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ template <typename T> struct npy_format_descriptor<T, enable_if_t<satisfies_any_
731731
template <typename T2 = T, enable_if_t<is_complex<T2>::value, int> = 0>
732732
static PYBIND11_DESCR name() {
733733
return _<std::is_same<typename T2::value_type, float>::value || std::is_same<typename T2::value_type, double>::value>(
734-
_("complex") + _<sizeof(T2::value_type)*16>(), _("longcomplex"));
734+
_("complex") + _<sizeof(typename T2::value_type)*16>(), _("longcomplex"));
735735
}
736736
};
737737

tests/test_eigen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ test_initializer eigen([](py::module &m) {
6666

6767
m.def("double_col", [](const Eigen::VectorXf &x) -> Eigen::VectorXf { return 2.0f * x; });
6868
m.def("double_row", [](const Eigen::RowVectorXf &x) -> Eigen::RowVectorXf { return 2.0f * x; });
69+
m.def("double_complex", [](const Eigen::VectorXcf &x) -> Eigen::VectorXcf { return 2.0f * x; });
6970
m.def("double_threec", [](py::EigenDRef<Eigen::Vector3f> x) { x *= 2; });
7071
m.def("double_threer", [](py::EigenDRef<Eigen::RowVector3f> x) { x *= 2; });
7172
m.def("double_mat_cm", [](Eigen::MatrixXf x) -> Eigen::MatrixXf { return 2.0f * x; });

tests/test_eigen.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,18 @@ def test_pass_readonly_array():
129129

130130
def test_nonunit_stride_from_python():
131131
from pybind11_tests import (
132-
double_row, double_col, double_mat_cm, double_mat_rm,
132+
double_row, double_col, double_complex, double_mat_cm, double_mat_rm,
133133
double_threec, double_threer)
134134

135135
counting_mat = np.arange(9.0, dtype=np.float32).reshape((3, 3))
136136
second_row = counting_mat[1, :]
137137
second_col = counting_mat[:, 1]
138138
np.testing.assert_array_equal(double_row(second_row), 2.0 * second_row)
139139
np.testing.assert_array_equal(double_col(second_row), 2.0 * second_row)
140+
np.testing.assert_array_equal(double_complex(second_row), 2.0 * second_row)
140141
np.testing.assert_array_equal(double_row(second_col), 2.0 * second_col)
141142
np.testing.assert_array_equal(double_col(second_col), 2.0 * second_col)
143+
np.testing.assert_array_equal(double_complex(second_col), 2.0 * second_col)
142144

143145
counting_3d = np.arange(27.0, dtype=np.float32).reshape((3, 3, 3))
144146
slices = [counting_3d[0, :, :], counting_3d[:, 0, :], counting_3d[:, :, 0]]
@@ -564,14 +566,17 @@ def test_special_matrix_objects():
564566

565567

566568
def test_dense_signature(doc):
567-
from pybind11_tests import double_col, double_row, double_mat_rm
569+
from pybind11_tests import double_col, double_row, double_complex, double_mat_rm
568570

569571
assert doc(double_col) == """
570572
double_col(arg0: numpy.ndarray[float32[m, 1]]) -> numpy.ndarray[float32[m, 1]]
571573
"""
572574
assert doc(double_row) == """
573575
double_row(arg0: numpy.ndarray[float32[1, n]]) -> numpy.ndarray[float32[1, n]]
574576
"""
577+
assert doc(double_complex) == """
578+
double_complex(arg0: numpy.ndarray[complex64[m, 1]]) -> numpy.ndarray[complex64[m, 1]]
579+
"""
575580
assert doc(double_mat_rm) == """
576581
double_mat_rm(arg0: numpy.ndarray[float32[m, n]]) -> numpy.ndarray[float32[m, n]]
577582
"""

0 commit comments

Comments
 (0)