Commit Graph

8 Commits

Author SHA1 Message Date
Jason Rhinelander
5fd5074a0b Add support for Eigen::Ref<...> function arguments
Eigen::Ref is a common way to pass eigen dense types without needing a
template, e.g. the single definition `void
func(Eigen::Ref<Eigen::MatrixXd> x)` can be called with any double
matrix-like object.

The current pybind11 eigen support fails with internal errors if
attempting to bind a function with an Eigen::Ref<...> argument because
Eigen::Ref<...> satisfies the "is_eigen_dense" requirement, but can't
compile if actually used: Eigen::Ref<...> itself is not default
constructible, and so the argument std::tuple containing an
Eigen::Ref<...> isn't constructible, which results in compilation
failure.

This commit adds support for Eigen::Ref<...> by giving it its own
type_caster implementation which consists of an internal type_caster of
the referenced type, load/cast methods that dispatch to the internal
type_caster, and a unique_ptr to an Eigen::Ref<> instance that gets
set during load().

There is, of course, no performance advantage for pybind11-using code of
using Eigen::Ref<...>--we are allocating a matrix of the derived type
when loading it--but this has the advantage of allowing pybind11 to bind
transparently to C++ methods taking Eigen::Refs.
2016-08-03 16:50:22 -04:00
Jason Rhinelander
eae180cd0b Add missing scipy run-time dep to eigen test
scipy is imported in pybind11/eigen.h when it encounters a sparse
matrix, which gets tested in the eigen test.
2016-07-12 14:16:46 -04:00
Jason Rhinelander
7de9f6c72d Tests can skip by exiting with 99; fix eigen test failure
This allows (and changes the current examples) to exit with status 99 to
skip a test instead of outputting a special string ("NumPy missing").

This also fixes the eigen test, which currently fails when eigen
headers are available but NumPy is not, to skip instead of failing when
NumPy isn't available.
2016-07-09 14:33:10 -04:00
Ben North
150a0fa786 check(): Stricter check in tests
Previous version would give false 'OK' if, for example, we were supposed
to get [1, 2, 3] but instead got [2, 1, 3].
2016-07-05 21:46:50 +01:00
Ben North
676e29885b Test that check() catches wrong order of elements
Fails --- next commit will tighten test.
2016-07-05 21:46:50 +01:00
Ben North
7b8d9e0246 Test eigen converts slices of 3d arrays correctly 2016-07-05 21:13:24 +01:00
Ben North
4a22091d45 Add tests for doubling row- and col-vectors
Passing a non-contiguous one-dimensional numpy array gives incorrect
results, so three of these tests fail.  The only one passing is the
simple case where the numpy array is contiguous and we are building a
column-major vector.  Subsequent commit will fix the three failing
cases.
2016-07-05 21:13:20 +01:00
Wenzel Jakob
9e0a0568fe transparent conversion of dense and sparse Eigen types 2016-05-05 21:44:29 +02:00