1. 12 Oct, 2017 1 commit
    • Jason Rhinelander's avatar
      Fix 2D Nx1/1xN inputs to eigen dense vector args · 6a81dbbb
      Jason Rhinelander authored
      This fixes a bug introduced in b68959e8
      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).
      6a81dbbb
  2. 05 Aug, 2017 1 commit
    • Jason Rhinelander's avatar
      Update all remaining tests to new test styles · 391c7544
      Jason Rhinelander authored
      This udpates all the remaining tests to the new test suite code and
      comment styles started in #898.  For the most part, the test coverage
      here is unchanged, with a few minor exceptions as noted below.
      
      - test_constants_and_functions: this adds more overload tests with
        overloads with different number of arguments for more comprehensive
        overload_cast testing.  The test style conversion broke the overload
        tests under MSVC 2015, prompting the additional tests while looking
        for a workaround.
      
      - test_eigen: this dropped the unused functions `get_cm_corners` and
        `get_cm_corners_const`--these same tests were duplicates of the same
        things provided (and used) via ReturnTester methods.
      
      - test_opaque_types: this test had a hidden dependence on ExampleMandA
        which is now fixed by using the global UserType which suffices for the
        relevant test.
      
      - test_methods_and_attributes: this required some additions to UserType
        to make it usable as a replacement for the test's previous SimpleType:
        UserType gained a value mutator, and the `value` property is not
        mutable (it was previously readonly).  Some overload tests were also
        added to better test overload_cast (as described above).
      
      - test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
        the templated versions with an empty parameter pack expand to the same
        thing.
      
      - test_stl: this was already mostly in the new style; this just tweaks
        things a bit, localizing a class, and adding some missing
        `// test_whatever` comments.
      
      - test_virtual_functions: like `test_stl`, this was mostly in the new
        test style already, but needed some `// test_whatever` comments.
        This commit also moves the inherited virtual example code to the end
        of the file, after the main set of tests (since it is less important
        than the other tests, and rather length); it also got renamed to
        `test_inherited_virtuals` (from `test_inheriting_repeat`) because it
        tests both inherited virtual approaches, not just the repeat approach.
      391c7544
  3. 29 Jun, 2017 1 commit
  4. 09 Apr, 2017 1 commit
    • Jason Rhinelander's avatar
      Fix Eigen argument doc strings · e9e17746
      Jason Rhinelander authored
      Many of the Eigen type casters' name() methods weren't wrapping the type
      description in a `type_descr` object, which thus wasn't adding the
      "{...}" annotation used to identify an argument which broke the help
      output by skipping eigen arguments.
      
      The test code I had added even had some (unnoticed) broken output (with
      the "arg0: " showing up in the return value).
      
      This commit also adds test code to ensure that named eigen arguments
      actually work properly, despite the invalid help output.  (The added
      tests pass without the rest of this commit).
      e9e17746
  5. 22 Mar, 2017 1 commit
  6. 17 Mar, 2017 1 commit
    • Jason Rhinelander's avatar
      Eigen: don't require conformability on length-1 dimensions · efa8726f
      Jason Rhinelander authored
      Fixes #738
      
      The current check for conformability fails when given a 2D, 1xN or Nx1
      input to a row-major or column-major, respectively, Eigen::Ref, leading
      to a copy-required state in the type_caster, but this later failed
      because the copy was also non-conformable because it had the same shape
      and strides (because a 1xN or Nx1 is both F and C contiguous).
      
      In such cases we can safely ignore the stride on the "1" dimension since
      it'll never be used: only the "N" dimension stride needs to match the
      Eigen::Ref stride, which both fixes the non-conformable copy problem,
      but also avoids a copy entirely as long as the "N" dimension has a
      compatible stride.
      efa8726f
  7. 28 Feb, 2017 1 commit
  8. 24 Feb, 2017 2 commits
    • Jason Rhinelander's avatar
      Eigen<->numpy referencing support · 17d0283e
      Jason Rhinelander authored
      This commit largely rewrites the Eigen dense matrix support to avoid
      copying in many cases: Eigen arguments can now reference numpy data, and
      numpy objects can now reference Eigen data (given compatible types).
      
      Eigen::Ref<...> arguments now also make use of the new `convert`
      argument use (added in PR #634) to avoid conversion, allowing
      `py::arg().noconvert()` to be used when binding a function to prohibit
      copying when invoking the function.  Respecting `convert` also means
      Eigen overloads that avoid copying will be preferred during overload
      resolution to ones that require copying.
      
      This commit also rewrites the Eigen documentation and test suite to
      explain and test the new capabilities.
      17d0283e
    • Jason Rhinelander's avatar
      Eigen: fix partially-fixed matrix conversion · d9d224f2
      Jason Rhinelander authored
      Currently when we do a conversion between a numpy array and an Eigen
      Vector, we allow the conversion only if the Eigen type is a
      compile-time vector (i.e. at least one dimension is fixed at 1 at
      compile time), or if the type is dynamic on *both* dimensions.
      
      This means we can run into cases where MatrixXd allow things that
      conforming, compile-time sizes does not: for example,
      `Matrix<double,4,Dynamic>` is currently not allowed, even when assigning
      from a 4-element vector, but it *is* allowed for a
      `Matrix<double,Dynamic,Dynamic>`.
      
      This commit also reverts the current behaviour of using the matrix's
      storage order to determine the structure when the Matrix is fully
      dynamic (i.e. in both dimensions).  Currently we assign to an eigen row
      if the storage order is row-major, and column otherwise: this seems
      wrong (the storage order has nothing to do with the shape!).  While
      numpy doesn't distinguish between a row/column vector, Eigen does, but
      it makes more sense to consistently choose one than to produce
      something with a different shape based on the intended storage layout.
      d9d224f2
  9. 12 Dec, 2016 1 commit
    • Jason Rhinelander's avatar
      Adds automatic casting on assignment of non-pyobject types (#551) · 3f1ff3f4
      Jason Rhinelander authored
      This adds automatic casting when assigning to python types like dict,
      list, and attributes.  Instead of:
      
          dict["key"] = py::cast(val);
          m.attr("foo") = py::cast(true);
          list.append(py::cast(42));
      
      you can now simply write:
      
          dict["key"] = val;
          m.attr("foo") = true;
          list.append(42);
      
      Casts needing extra parameters (e.g. for a non-default rvp) still
      require the py::cast() call. set::add() is also supported.
      
      All usage is channeled through a SFINAE implementation which either just returns or casts. 
      
      Combined non-converting handle and autocasting template methods via a
      helper method that either just returns (handle) or casts (C++ type).
      3f1ff3f4
  10. 06 Sep, 2016 1 commit
  11. 03 Sep, 2016 1 commit
    • Jason Rhinelander's avatar
      Make test initialization self-registering · 52f4be89
      Jason Rhinelander authored
      Adding or removing tests is a little bit cumbersome currently: the test
      needs to be added to CMakeLists.txt, the init function needs to be
      predeclared in pybind11_tests.cpp, then called in the plugin
      initialization.  While this isn't a big deal for tests that are being
      committed, it's more of a hassle when working on some new feature or
      test code for which I temporarily only care about building and linking
      the test being worked on rather than the entire test suite.
      
      This commit changes tests to self-register their initialization by
      having each test initialize a local object (which stores the
      initialization function in a static variable).  This makes changing the
      set of tests being build easy: one only needs to add or comment out
      test names in tests/CMakeLists.txt.
      
      A couple other minor changes that go along with this:
      
      - test_eigen.cpp is now included in the test list, then removed if eigen
        isn't available.  This lets you disable the eigen tests by commenting
        it out, just like all the other tests, but keeps the build working
        without eigen eigen isn't available.  (Also, if it's commented out, we
        don't even bother looking for and reporting the building with/without
        eigen status message).
      
      - pytest is now invoked with all the built test names (with .cpp changed
        to .py) so that it doesn't try to run tests that weren't built.
      52f4be89
  12. 19 Aug, 2016 1 commit
    • Dean Moldovan's avatar
      Port tests to pytest · a0c1ccf0
      Dean Moldovan authored
      Use simple asserts and pytest's powerful introspection to make testing
      simpler. This merges the old .py/.ref file pairs into simple .py files
      where the expected values are right next to the code being tested.
      
      This commit does not touch the C++ part of the code and replicates the
      Python tests exactly like the old .ref-file-based approach.
      a0c1ccf0
  13. 04 Aug, 2016 2 commits
    • Jason Rhinelander's avatar
      Eigen support for special matrix objects · 9ffb3dda
      Jason Rhinelander authored
      Functions returning specialized Eigen matrices like Eigen::DiagonalMatrix and
      Eigen::SelfAdjointView--which inherit from EigenBase but not
      DenseBase--isn't currently allowed; such classes are explicitly copyable
      into a Matrix (by definition), and so we can support functions that
      return them by copying the value into a Matrix then casting that
      resulting dense Matrix into a numpy.ndarray.  This commit does exactly
      that.
      9ffb3dda
    • Jason Rhinelander's avatar
      Fix eigen copying of non-standard stride values · 8657f308
      Jason Rhinelander authored
      Some Eigen objects, such as those returned by matrix.diagonal() and
      matrix.block() have non-standard stride values because they are
      basically just maps onto the underlying matrix without copying it (for
      example, the primary diagonal of a 3x3 matrix is a vector-like object
      with .src equal to the full matrix data, but with stride 4).  Returning
      such an object from a pybind11 method breaks, however, because pybind11
      assumes vectors have stride 1, and that matrices have strides equal to
      the number of rows/columns or 1 (depending on whether the matrix is
      stored column-major or row-major).
      
      This commit fixes the issue by making pybind11 use Eigen's stride
      methods when copying the data.
      8657f308
  14. 03 Aug, 2016 1 commit
    • Jason Rhinelander's avatar
      Add support for Eigen::Ref<...> function arguments · 5fd5074a
      Jason Rhinelander authored
      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.
      5fd5074a
  15. 05 Jul, 2016 2 commits
  16. 05 May, 2016 1 commit