1. 06 May, 2018 1 commit
  2. 11 Jan, 2018 1 commit
    • Jason Rhinelander's avatar
      Fixes for numpy 1.14.0 compatibility · 88efb251
      Jason Rhinelander authored
      - UPDATEIFCOPY is deprecated, replaced with similar (but not identical)
        WRITEBACKIFCOPY; trying to access the flag causes a deprecation
        warning under numpy 1.14, so just check the new flag there.
      - Numpy `repr` formatting of floats changed in 1.14.0 to `[1., 2., 3.]`
        instead of the pre-1.14 `[ 1.,  2.,  3.]`.  Updated the tests to
        check for equality with the `repr(...)` value rather than the
        hard-coded (and now version-dependent) string representation.
      88efb251
  3. 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
  4. 07 May, 2017 2 commits
  5. 29 Apr, 2017 1 commit
  6. 13 Apr, 2017 1 commit
    • Jason Rhinelander's avatar
      array: set exception message on failure · 5749b502
      Jason Rhinelander authored
      When attempting to get a raw array pointer we return nullptr if given a
      nullptr, which triggers an error_already_set(), but we haven't set an
      exception message, which results in "Unknown internal error".
      
      Callers that want explicit allowing of a nullptr here already handle it
      (by clearing the exception after the call).
      5749b502
  7. 22 Mar, 2017 2 commits
    • Jason Rhinelander's avatar
      array-unchecked: add runtime dimension support and array-compatible methods · 773339f1
      Jason Rhinelander authored
      The extends the previous unchecked support with the ability to
      determine the dimensions at runtime.  This incurs a small performance
      hit when used (versus the compile-time fixed alternative), but is still considerably
      faster than the full checks on every call that happen with
      `.at()`/`.mutable_at()`.
      773339f1
    • Jason Rhinelander's avatar
      array: add unchecked access via proxy object · 423a49b8
      Jason Rhinelander authored
      This adds bounds-unchecked access to arrays through a `a.unchecked<Type,
      Dimensions>()` method.  (For `array_t<T>`, the `Type` template parameter
      is omitted).  The mutable version (which requires the array have the
      `writeable` flag) is available as `a.mutable_unchecked<...>()`.
      
      Specifying the Dimensions as a template parameter allows storage of an
      std::array; having the strides and sizes stored that way (as opposed to
      storing a copy of the array's strides/shape pointers) allows the
      compiler to make significant optimizations of the shape() method that it
      can't make with a pointer; testing with nested loops of the form:
      
          for (size_t i0 = 0; i0 < r.shape(0); i0++)
              for (size_t i1 = 0; i1 < r.shape(1); i1++)
                  ...
                      r(i0, i1, ...) += 1;
      
      over a 10 million element array gives around a 25% speedup (versus using
      a pointer) for the 1D case, 33% for 2D, and runs more than twice as fast
      with a 5D array.
      423a49b8
  8. 13 Mar, 2017 1 commit
  9. 06 Mar, 2017 1 commit
  10. 26 Feb, 2017 1 commit
  11. 24 Feb, 2017 4 commits
    • Jason Rhinelander's avatar
      Move requires_numpy, etc. decorators to globals · 2a757844
      Jason Rhinelander authored
      test_eigen.py and test_numpy_*.py have the same
      @pytest.requires_eigen_and_numpy or @pytest.requires_numpy on every
      single test; this changes them to use pytest's global `pytestmark = ...`
      instead to disable the entire module when numpy and/or eigen aren't
      available.
      2a757844
    • Jason Rhinelander's avatar
      Change array's writeable exception to a ValueError · fd751703
      Jason Rhinelander authored
      Numpy raises ValueError when attempting to modify an array, while
      py::array is raising a RuntimeError.  This changes the exception to a
      std::domain_error, which gets mapped to the expected ValueError in
      python.
      fd751703
    • Jason Rhinelander's avatar
      array: fix base handling · f86dddf7
      Jason Rhinelander authored
      numpy arrays aren't currently properly setting base: by setting `->base`
      directly, the base doesn't follow what numpy expects and documents (that
      is, following chained array bases to the root array).
      
      This fixes the behaviour by using numpy's PyArray_SetBaseObject to set
      the base instead, and then updates the tests to reflect the fixed
      behaviour.
      f86dddf7
    • Jason Rhinelander's avatar
      Make string conversion stricter (#695) · ee2e5a50
      Jason Rhinelander authored
      * Make string conversion stricter
      
      The string conversion logic added in PR #624 for all std::basic_strings
      was derived from the old std::wstring logic, but that was underused and
      turns out to have had a bug in accepting almost anything convertible to
      unicode, while the previous std::string logic was much stricter.  This
      restores the previous std::string logic by only allowing actual unicode
      or string types.
      
      Fixes #685.
      
      * Added missing 'requires numpy' decorator
      
      (I forgot that the change to a global decorator here is in the
      not-yet-merged Eigen PR)
      ee2e5a50
  12. 16 Dec, 2016 1 commit
    • Wenzel Jakob's avatar
      WIP: PyPy support (#527) · 1d1f81b2
      Wenzel Jakob authored
      This commit includes modifications that are needed to get pybind11 to work with PyPy. The full test suite compiles and runs except for a last few functions that are commented out (due to problems in PyPy that were reported on the PyPy bugtracker).
      
      Two somewhat intrusive changes were needed to make it possible: two new tags ``py::buffer_protocol()`` and ``py::metaclass()`` must now be specified to the ``class_`` constructor if the class uses the buffer protocol and/or requires a metaclass (e.g. for static properties).
      
      Note that this is only for the PyPy version based on Python 2.7 for now. When the PyPy 3.x has caught up in terms of cpyext compliance, a PyPy 3.x patch will follow.
      1d1f81b2
  13. 20 Nov, 2016 1 commit
  14. 17 Nov, 2016 1 commit
    • Dean Moldovan's avatar
      Improve consistency of array and array_t with regard to other pytypes · 4de27102
      Dean Moldovan authored
      * `array_t(const object &)` now throws on error
      * `array_t::ensure()` is intended for casters —- old constructor is
        deprecated
      * `array` and `array_t` get default constructors (empty array)
      * `array` gets a converting constructor
      * `py::isinstance<array_T<T>>()` checks the type (but not flags)
      
      There is only one special thing which must remain: `array_t` gets
      its own `type_caster` specialization which uses `ensure` instead
      of a simple check.
      4de27102
  15. 27 Oct, 2016 1 commit
  16. 13 Oct, 2016 1 commit
  17. 12 Oct, 2016 2 commits
    • Wenzel Jakob's avatar
      Permit creation of NumPy arrays with a "base" object that owns the data · 369e9b39
      Wenzel Jakob authored
      This patch adds an extra base handle parameter to most ``py::array`` and
      ``py::array_t<>`` constructors. If specified along with a pointer to
      data, the base object will be registered within NumPy, which increases
      the base's reference count. This feature is useful to create shallow
      copies of C++ or Python arrays while ensuring that the owners of the
      underlying can't be garbage collected while referenced by NumPy.
      
      The commit also adds a simple test function involving a ``wrap()``
      function that creates shallow copies of various N-D arrays.
      369e9b39
    • Wenzel Jakob's avatar
      added numpy test (minor): check that 'strides' is respected even when creating new arrays · 43f6aa68
      Wenzel Jakob authored
      - This actually works with no changes, I just wasn't 100% convinced and
        decided to write a test to see if it's true.
      43f6aa68
  18. 10 Sep, 2016 2 commits