diff --git a/include/nanobind/eigen/dense.h b/include/nanobind/eigen/dense.h index cb01d452..aa295a15 100644 --- a/include/nanobind/eigen/dense.h +++ b/include/nanobind/eigen/dense.h @@ -26,7 +26,7 @@ template using DMap = Eigen::Map; NAMESPACE_BEGIN(detail) template -constexpr int NumDimensions = int(T::MaxSizeAtCompileTime) == 1 ? 0 : bool(T::IsVectorAtCompileTime) ? 1 : 2; +constexpr int NumDimensions = bool(T::IsVectorAtCompileTime) ? 1 : 2; template using array_for_eigen_t = ndarray< diff --git a/src/nb_ndarray.cpp b/src/nb_ndarray.cpp index e435cc8d..1d7a7799 100644 --- a/src/nb_ndarray.cpp +++ b/src/nb_ndarray.cpp @@ -504,7 +504,6 @@ ndarray_handle *ndarray_create(void *value, size_t ndim, const size_t *shape_in, --i; } } - ndarray->dltensor.data = (void *) value_rounded; ndarray->dltensor.device.device_type = device_type; ndarray->dltensor.device.device_id = device_id; diff --git a/tests/test_eigen.cpp b/tests/test_eigen.cpp index a6698237..1c5eba21 100644 --- a/tests/test_eigen.cpp +++ b/tests/test_eigen.cpp @@ -117,6 +117,16 @@ NB_MODULE(test_eigen_ext, m) { return m; }); + /// issue #166 + using Matrix1d = Eigen::Matrix; + try { + m.def( + "default_arg", [](Matrix1d a, Matrix1d b) { return a + b; }, + "a"_a = Matrix1d::Zero(), "b"_a = Matrix1d::Zero()); + } catch (...) { + // Ignore (NumPy not installed, etc.) + } + struct Buffer { uint32_t x[30] { }; diff --git a/tests/test_eigen.py b/tests/test_eigen.py index 08b35cb4..b1e41a66 100644 --- a/tests/test_eigen.py +++ b/tests/test_eigen.py @@ -243,3 +243,8 @@ def test_sparse_failures(): # undo sabotage of the module sys.path = sys_path scipy.sparse.csr_matrix = csr_matrix + +@needs_numpy_and_eigen +def test_eigen_scalar_default(): + x = t.default_arg() + assert x==0