1. 09 May, 2017 1 commit
    • Jason Rhinelander's avatar
      Make PYBIND11_CPP_STANDARD work under MSVC · 77710ff0
      Jason Rhinelander authored
      Under MSVC we were ignoring PYBIND11_CPP_STANDARD and simply not
      passing any standard (which makes MSVC default to its C++14 mode).
      
      MSVC 2015u3 added the `/std:c++14` and `/std:c++latest` flags; the
      latter, under MSVC 2017, enables some C++17 features (such as
      `std::optional` and `std::variant`), so it is something we need to
      start supporting under MSVC.
      
      This makes the PYBIND11_CPP_STANDARD cmake variable work under MSVC,
      defaulting it to /std:c++14 (matching the default -std=c++14 for
      non-MSVC).
      
      It also adds a new appveyor test running under MSVC 2017 with
      /std:c++latest, which runs (and passes) the
      `std::optional`/`std::variant` tests.
      
      Also updated the documentation to clarify the c++ flags and add show
      MSVC flag examples.
      77710ff0
  2. 08 May, 2017 1 commit
  3. 07 May, 2017 3 commits
    • Cris Luengo's avatar
    • Jason Rhinelander's avatar
      Use numpy rather than Eigen for copying · b68959e8
      Jason Rhinelander authored
      We're current copy by creating an Eigen::Map into the input numpy
      array, then assigning that to the basic eigen type, effectively having
      Eigen do the copy.  That doesn't work for negative strides, though:
      Eigen doesn't allow them.
      
      This commit makes numpy do the copying instead by allocating the eigen
      type, then having numpy copy from the input array into a numpy reference
      into the eigen object's data.  This also saves a copy when type
      conversion is required: numpy can do the conversion on-the-fly as part
      of the copy.
      
      Finally this commit also makes non-reference parameters respect the
      convert flag, declining the load when called in a noconvert pass with a
      convertible, but non-array input or an array with the wrong dtype.
      b68959e8
    • Cris Luengo's avatar
      d400f60c
  4. 29 Apr, 2017 1 commit
  5. 07 Apr, 2017 1 commit
  6. 02 Apr, 2017 1 commit
    • Dean Moldovan's avatar
      Add a scope guard call policy · 1ac19036
      Dean Moldovan authored
      ```c++
      m.def("foo", foo, py::call_guard<T>());
      ```
      
      is equivalent to:
      
      ```c++
      m.def("foo", [](args...) {
          T scope_guard;
          return foo(args...); // forwarded arguments
      });
      ```
      1ac19036
  7. 28 Mar, 2017 1 commit
  8. 22 Mar, 2017 7 commits
    • Wenzel Jakob's avatar
      minor style fix · 0d92938f
      Wenzel Jakob authored
      0d92938f
    • Wenzel Jakob's avatar
      d405b1b3
    • Wenzel Jakob's avatar
      Changelog for v2.1.0 (#759) · 62e5fef0
      Wenzel Jakob authored
      62e5fef0
    • Wenzel Jakob's avatar
      Nicer API to pass py::capsule destructor (#752) · b16421ed
      Wenzel Jakob authored
      * nicer py::capsule destructor mechanism
      * added destructor-only version of capsule & tests
      * added documentation for module destructors (fixes #733)
      b16421ed
    • Wenzel Jakob's avatar
      ab26259c
    • 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
  9. 12 Mar, 2017 1 commit
    • Dean Moldovan's avatar
      Fix readthedocs build (#721) · b7017c3d
      Dean Moldovan authored
      RTD updated their build environment which broke the 1.8.14.dev build of
      doxygen that we were using. The update also breaks the conda-forge build
      of 1.8.13 (but that version has other issues).
      
      Luckily, the RTD update did bring their doxygen version up to 1.8.11
      which is enough to parse the C++11 code we need (ref qualifiers) and it
      also avoids the segfault found in 1.8.13.
      
      Since we're using the native doxygen, conda isn't required anymore and
      we can simplify the RTD configuration.
      
      [skip ci]
      b7017c3d
  10. 03 Mar, 2017 1 commit
  11. 24 Feb, 2017 1 commit
    • 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
  12. 23 Feb, 2017 2 commits
    • Dean Moldovan's avatar
      Enable static properties (py::metaclass) by default · dd01665e
      Dean Moldovan authored
      Now that only one shared metaclass is ever allocated, it's extremely
      cheap to enable it for all pybind11 types.
      
      * Deprecate the default py::metaclass() since it's not needed anymore.
      * Allow users to specify a custom metaclass via py::metaclass(handle).
      dd01665e
    • Dean Moldovan's avatar
      Minor docs build maintenance (#692) · a3f4a02c
      Dean Moldovan authored
      * Switch breathe to stable releases. It was previously pulling directly
        from master because a required bugfix was not in a stable release yet.
      
      * Force update sphinx and RTD theme. When using conda, readthedocs pins
        sphinx==1.3.5 and sphinx_rtd_theme==0.1.7, which is a bit older than
        the ones used in the RTD regular (non-conda) build. The newer theme
        has nicer sidebar navigation (4-level depth vs. only 2-level on the
        older version). Note that the python==3.5 requirement must stay
        because RTD still installs the older sphinx at one point which isn't
        available with Python 3.6.
      
      [skip ci]
      a3f4a02c
  13. 17 Feb, 2017 2 commits
  14. 14 Feb, 2017 2 commits
    • Dean Moldovan's avatar
      Fix readthedocs build · cec052b5
      Dean Moldovan authored
      Fixes #667
      
      The sphinx version is pinned by readthedocs, but sphinx 1.3.5 is not
      available with conda python 3.6. The workaround is to pin the python
      version to 3.5 (it doesn't really matter for the docs build).
      cec052b5
    • Jason Rhinelander's avatar
      Unicode fixes and docs (#624) · 11a337f1
      Jason Rhinelander authored
      * Propagate unicode conversion failure
      
      If returning a std::string with invalid utf-8 data, we currently fail
      with an uninformative TypeError instead of propagating the
      UnicodeDecodeError that Python sets on failure.
      
      * Add support for u16/u32strings and literals
      
      This adds support for wchar{16,32}_t character literals and the
      associated std::u{16,32}string types.  It also folds the
      character/string conversion into a single type_caster template, since
      the type casters for string and wstring were mostly the same anyway.
      
      * Added too-long and too-big character conversion errors
      
      With this commit, when casting to a single character, as opposed to a
      C-style string, we make sure the input wasn't a multi-character string
      or a single character with codepoint too large for the character type.
      
      This also changes the character cast op to CharT instead of CharT& (we
      need to be able to return a temporary decoded char value, but also
      because there's little gained by bothering with an lvalue return here).
      
      Finally it changes the char caster to 'has-a-string-caster' instead of
      'is-a-string-caster' because, with the cast_op change above, there's
      nothing at all gained from inheritance.  This also lets us remove the
      `success` from the string caster (which was only there for the char
      caster) into the char caster itself.  (I also renamed it to 'none' and
      inverted its value to better reflect its purpose).  The None -> nullptr
      loading also now takes place only under a `convert = true` load pass.
      Although it's unlikely that a function taking a char also has overloads
      that can take a None, it seems marginally more correct to treat it as a
      conversion.
      
      This commit simplifies the size assumptions about character sizes with
      static_asserts to back them up.
      11a337f1
  15. 04 Feb, 2017 2 commits
    • Jason Rhinelander's avatar
      Prefer non-converting argument overloads · e550589b
      Jason Rhinelander authored
      This changes the function dispatching code for overloaded functions into
      a two-pass procedure where we first try all overloads with
      `convert=false` for all arguments.  If no function calls succeeds in the
      first pass, we then try a second pass where we allow arguments to have
      `convert=true` (unless, of course, the argument was explicitly specified
      with `py::arg().noconvert()`).
      
      For non-overloaded methods, the two-pass procedure is skipped (we just
      make the overload-allowed call).  The second pass is also skipped if it
      would result in the same thing (i.e. where all arguments are
      `.noconvert()` arguments).
      e550589b
    • Jason Rhinelander's avatar
      Add support for non-converting arguments · abc29cad
      Jason Rhinelander authored
      This adds support for controlling the `convert` flag of arguments
      through the py::arg annotation.  This then allows arguments to be
      flagged as non-converting, which the type_caster is able to use to
      request different behaviour.
      
      Currently, AFAICS `convert` is only used for type converters of regular
      pybind11-registered types; all of the other core type_casters ignore it.
      We can, however, repurpose it to control internal conversion of
      converters like Eigen and `array`: most usefully to give callers a way
      to disable the conversion that would otherwise occur when a
      `Eigen::Ref<const Eigen::Matrix>` argument is passed a numpy array that
      requires conversion (either because it has an incompatible stride or the
      wrong dtype).
      
      Specifying a noconvert looks like one of these:
      
          m.def("f1", &f, "a"_a.noconvert() = "default"); // Named, default, noconvert
          m.def("f2", &f, "a"_a.noconvert()); // Named, no default, no converting
          m.def("f3", &f, py::arg().noconvert()); // Unnamed, no default, no converting
      
      (The last part--being able to declare a py::arg without a name--is new:
      previous py::arg() only accepted named keyword arguments).
      
      Such an non-convert argument is then passed `convert = false` by the
      type caster when loading the argument.  Whether this has an effect is up
      to the type caster itself, but as mentioned above, this would be
      extremely helpful for the Eigen support to give a nicer way to specify
      a "no-copy" mode than the custom wrapper in the current PR, and
      moreover isn't an Eigen-specific hack.
      abc29cad
  16. 02 Feb, 2017 1 commit
  17. 31 Jan, 2017 6 commits
    • Jason Rhinelander's avatar
      Minor fixes (#613) · 12494525
      Jason Rhinelander authored
      * Minor doc syntax fix
      
      The numpy documentation had a bad :file: reference (was using double
      backticks instead of single backticks).
      
      * Changed long-outdated "example" -> "tests" wording
      
      The ConstructorStats internal docs still had "from example import", and
      the main testing cpp file still used "example" in the module
      description.
      12494525
    • Jason Rhinelander's avatar
      Add support for positional args with args/kwargs · 2686da83
      Jason Rhinelander authored
      This commit rewrites the function dispatcher code to support mixing
      regular arguments with py::args/py::kwargs arguments.  It also
      simplifies the argument loader noticeably as it no longer has to worry
      about args/kwargs: all of that is now sorted out in the dispatcher,
      which now simply appends a tuple/dict if the function takes
      py::args/py::kwargs, then passes all the arguments in a vector.
      
      When the argument loader hit a py::args or py::kwargs, it doesn't do
      anything special: it just calls the appropriate type_caster just like it
      does for any other argument (thus removing the previous special cases
      for args/kwargs).
      
      Switching to passing arguments in a single std::vector instead of a pair
      of tuples also makes things simpler, both in the dispatch and the
      argument_loader: since this argument list is strictly pybind-internal
      (i.e. it never goes to Python) we have no particular reason to use a
      Python tuple here.
      
      Some (intentional) restrictions:
      - you may not bind a function that has args/kwargs somewhere other than
        the end (this somewhat matches Python, and keeps the dispatch code a
        little cleaner by being able to not worry about where to inject the
        args/kwargs in the argument list).
      - If you specify an argument both positionally and via a keyword
        argument, you get a TypeError alerting you to this (as you do in
        Python).
      2686da83
    • Dustin Spicuzza's avatar
    • Dean Moldovan's avatar
      Improve custom holder support (#607) · ec009a7c
      Dean Moldovan authored
      * Abstract away some holder functionality (resolve #585)
      
      Custom holder types which don't have `.get()` can select the correct
      function to call by specializing `holder_traits`.
      
      * Add support for move-only holders (fix #605)
      ec009a7c
    • Jason Rhinelander's avatar
      Numpy: better compilation errors, long double support (#619) · f7f5bc8e
      Jason Rhinelander authored
      * Clarify PYBIND11_NUMPY_DTYPE documentation
      
      The current documentation and example reads as though
      PYBIND11_NUMPY_DTYPE is a declarative macro along the same lines as
      PYBIND11_DECLARE_HOLDER_TYPE, but it isn't.  The changes the
      documentation and docs example to make it clear that you need to "call"
      the macro.
      
      * Add satisfies_{all,any,none}_of<T, Preds>
      
      `satisfies_all_of<T, Pred1, Pred2, Pred3>` is a nice legibility-enhanced
      shortcut for `is_all<Pred1<T>, Pred2<T>, Pred3<T>>`.
      
      * Give better error message for non-POD dtype attempts
      
      If you try to use a non-POD data type, you get difficult-to-interpret
      compilation errors (about ::name() not being a member of an internal
      pybind11 struct, among others), for which isn't at all obvious what the
      problem is.
      
      This adds a static_assert for such cases.
      
      It also changes the base case from an empty struct to the is_pod_struct
      case by no longer using `enable_if<is_pod_struct>` but instead using a
      static_assert: thus specializations avoid the base class, POD types
      work, and non-POD types (and unimplemented POD types like std::array)
      get a more informative static_assert failure.
      
      * Prefix macros with PYBIND11_
      
      numpy.h uses unprefixed macros, which seems undesirable.  This prefixes
      them with PYBIND11_ to match all the other macros in numpy.h (and
      elsewhere).
      
      * Add long double support
      
      This adds long double and std::complex<long double> support for numpy
      arrays.
      
      This allows some simplification of the code used to generate format
      descriptors; the new code uses fewer macros, instead putting the code as
      different templated options; the template conditions end up simpler with
      this because we are now supporting all basic C++ arithmetic types (and
      so can use is_arithmetic instead of is_integral + multiple
      different specializations).
      
      In addition to testing that it is indeed working in the test script, it
      also adds various offset and size calculations there, which
      fixes the test failures under x86 compilations.
      f7f5bc8e
    • Dean Moldovan's avatar
      Automate generation of reference docs with doxygen and breathe (#598) · 57a9bbc6
      Dean Moldovan authored
      * Make 'any' the default markup role for Sphinx docs
      
      * Automate generation of reference docs with doxygen and breathe
      
      * Improve reference docs coverage
      57a9bbc6
  18. 13 Jan, 2017 2 commits
    • jbarlow83's avatar
      Docs: minor clarifications (#590) · 7830e850
      jbarlow83 authored
      * Some clarifications to section on virtual fns
      
      Primarily, I made it clear that PYBIND11_OVERLOAD_PURE_NAME is not "useful" but required in renaming situations. Also clarified that one should not bind to the trampoline helper class which I found tempting since it seems more explicit.
      
      * Remove :emphasize-lines: from cpp block, seems to suppress formatting
      
      * docs: emphasize default policy, clarify keep_alive
      
      Emphasize the default return value policy since this statement is hidden in a wall of text. 
      
      Add a hint that call policies are probably required for container objects.
      7830e850
    • myd7349's avatar
      Docs: Fix several errors of examples from the doc (#592) · 9b815ad2
      myd7349 authored
      * [Doc] Fix several errors of examples from the doc
      
      * Add missing operator def.
      
      * Added missing `()`
      
      * Add missing `namespace`.
      9b815ad2
  19. 06 Jan, 2017 1 commit
  20. 04 Jan, 2017 1 commit
  21. 01 Jan, 2017 2 commits