Fix 2D Nx1/1xN inputs to eigen dense vector args
This fixes a bug introduced in b68959e822a619d1ad140f52c7197a29f4e6a06a
when passing in a two-dimensional, but conformable, array as the value
for a compile-time Eigen vector (such as VectorXd or RowVectorXd). The
commit switched to using numpy to copy into the eigen data, but this
broke the described case because numpy refuses to broadcast a (N,1)
into a (N).
This commit fixes it by squeezing the input array whenever the output
array is 1-dimensional, which will let the problematic case through.
(This shouldn't squeeze inappropriately as dimension compatibility is
already checked for conformability before getting to the copy code).
diff --git a/tests/test_eigen.py b/tests/test_eigen.py
index 4ac8cbf..1f263db 100644
--- a/tests/test_eigen.py
+++ b/tests/test_eigen.py
@@ -672,6 +672,21 @@
assert np.all(m.iss738_f2(np.array([[1.], [2], [3]])) == np.array([[1.], [12], [23]]))
+def test_issue1105():
+ """Issue 1105: 1xN or Nx1 input arrays weren't accepted for eigen
+ compile-time row vectors or column vector"""
+ assert m.iss1105_row(np.ones((1, 7)))
+ assert m.iss1105_col(np.ones((7, 1)))
+
+ # These should still fail (incompatible dimensions):
+ with pytest.raises(TypeError) as excinfo:
+ m.iss1105_row(np.ones((7, 1)))
+ assert "incompatible function arguments" in str(excinfo)
+ with pytest.raises(TypeError) as excinfo:
+ m.iss1105_col(np.ones((1, 7)))
+ assert "incompatible function arguments" in str(excinfo)
+
+
def test_custom_operator_new():
"""Using Eigen types as member variables requires a class-specific
operator new with proper alignment"""