Commit Graph

1376 Commits

Author SHA1 Message Date
Jason Rhinelander
b68d8fc2c5 *Really* fix enumeration indices 2016-08-04 16:39:30 -04:00
Wenzel Jakob
67bfeb19c1 Merge pull request #316 from jagerman/eigen-base-types
Eigen support for special matrix objects
2016-08-04 22:37:26 +02:00
Jason Rhinelander
38d5b4565c Fixed enumeration indices 2016-08-04 16:36:16 -04:00
Jason Rhinelander
9ffb3dda5f Eigen support for special matrix objects
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.
2016-08-04 15:24:41 -04:00
Wenzel Jakob
19637536ac Merge pull request #315 from jagerman/eigen-stride-fix
Fix eigen copying of non-standard stride values
2016-08-04 19:47:17 +02:00
Wenzel Jakob
2fb81afb59 Merge pull request #313 from jagerman/scoped-enums
Fix scoped enums and add scoped enum example
2016-08-04 19:46:56 +02:00
Jason Rhinelander
8657f3083a Fix eigen copying of non-standard stride values
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.
2016-08-04 13:21:39 -04:00
Jason Rhinelander
d41a273031 Only support ==/!= int on unscoped enums
This makes the Python interface mirror the C++ interface:
pybind11-exported scoped enums aren't directly comparable to the
underlying integer values.
2016-08-04 00:21:37 -04:00
Jason Rhinelander
613541947a Fix scoped enums and add scoped enum example
PR #309 broke scoped enums, which failed to compile because the added:

    value == value2

comparison isn't valid for a scoped enum (they aren't implicitly
convertible to the underlying type).  This commit fixes it by
explicitly converting the enum value to its underlying type before
doing the comparison.

It also adds a scoped enum example to the constants-and-functions
example that triggers the problem fixed in this commit.
2016-08-04 00:01:39 -04:00
Wenzel Jakob
39ff2d0140 Merge pull request #312 from jagerman/eigen-ref-args
Add support for Eigen::Ref<...> function arguments
2016-08-03 23:12:20 +02:00
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
Wenzel Jakob
7f9603fe24 Merge pull request #311 from lsst-dm/master
Fix zero valued enum comparison error
2016-08-03 17:42:28 +02:00
Pim Schellart
3d079fbd54 Fix zero valued enum comparison error 2016-08-03 10:36:22 -04:00
Wenzel Jakob
6c19f6e598 Merge pull request #309 from lsst-dm/master
Enable comparisons between enums and their underlying types
2016-08-02 18:27:32 +02:00
Pim Schellart
e5b42ef1fe Enable comparisons between enums and their underlying types 2016-08-02 11:33:48 -04:00
Wenzel Jakob
2160860c0a minor cmake change as per #306 2016-08-02 02:19:35 +02:00
Wenzel Jakob
3da5edec1f Merge pull request #306 from trygvis/pybind-305-1
Mark pybind11 include dir as PRIVATE to avoid a CMake error message.
2016-08-02 02:18:08 +02:00
Wenzel Jakob
b6f79f28b9 Merge pull request #302 from dean0x7d/ci
Improve CI test coverage: eigen, numpy and C++14
2016-08-02 01:30:26 +02:00
Dean Moldovan
880a7e4d0a Use system version of Python 2.7 on OS X on Travis 2016-08-02 01:19:19 +02:00
Wenzel Jakob
3764e28475 added note about args/kwargs limitation 2016-08-01 23:34:48 +02:00
Wenzel Jakob
f5d00105ce Merge pull request #304 from trygvis/pybind-303
Changes accessor::operator=() to throw error_already_set() instead of using pybind11_fail().
2016-08-01 23:10:00 +02:00
Trygve Laugstøl
9119f13072 Improving support for installing pybind11.
Mark the pybind11 headers as private to the target.

Fixes #305
2016-08-01 09:17:29 +02:00
Trygve Laugstøl
3572bc3e82 Changes accessor::operator=() to throw error_already_set() instead of using pybind11_fail().
PyObject_SetItem and PyObject_SetAttr both throws an exception on
failure so this will show the underlying exception instead of masking
it.

Fixes #303.
2016-08-01 08:45:16 +02:00
Dean Moldovan
3ac1275248 Improve CI test coverage: eigen, numpy and C++14 2016-07-30 17:18:33 +02:00
Wenzel Jakob
f38f359f96 documentation fix (fixes #290) 2016-07-19 17:48:42 +02:00
Wenzel Jakob
a771e362df check for NOMINMAX issue on windows (fixes #291) 2016-07-19 17:47:59 +02:00
Wenzel Jakob
a975ab2501 minor namespace change in example 2016-07-19 17:35:09 +02:00
Wenzel Jakob
4a87933be9 descr<> fix for int-to-string conversion 2016-07-19 11:59:37 +02:00
Wenzel Jakob
61352e504d Merge pull request #289 from jagerman/example-renaming
Rename examples files, as per #288
2016-07-18 23:52:59 +02:00
Jason Rhinelander
3e2e44f53f Updated advanced.rst example references 2016-07-18 17:03:37 -04:00
Jason Rhinelander
b3f3d79f4c Rename examples files, as per #288
This renames example files from `exampleN` to `example-description`.

Specifically, the following renaming is applied:

example1 -> example-methods-and-attributes
example2 -> example-python-types
example3 -> example-operator-overloading
example4 -> example-constants-and-functions
example5 -> example-callbacks (*)
example6 -> example-sequence-and-iterators
example7 -> example-buffers
example8 -> example-custom-ref-counting
example9 -> example-modules
example10 -> example-numpy-vectorize
example11 -> example-arg-keywords-and-defaults
example12 -> example-virtual-functions
example13 -> example-keep-alive
example14 -> example-opaque-types
example15 -> example-pickling
example16 -> example-inheritance
example17 -> example-stl-binders
example18 -> example-eval
example19 -> example-custom-exceptions

* the inheritance parts of example5 are moved into example-inheritance
(previously example16), and the remainder is left as example-callbacks.

This commit also renames the internal variables ("Example1",
"Example2", "Example4", etc.) into non-numeric names ("ExampleMandA",
"ExamplePythonTypes", "ExampleWithEnum", etc.) to correspond to the
file renaming.

The order of tests is preserved, but this can easily be changed if
there is some more natural ordering by updating the list in
examples/CMakeLists.txt.
2016-07-18 16:43:18 -04:00
Wenzel Jakob
fb6aed2157 return value policy clarifications 2016-07-18 20:29:53 +02:00
Wenzel Jakob
1f66a58427 pybind11.h: minor cleanups (no functionality change) 2016-07-18 10:47:10 +02:00
Wenzel Jakob
6969e7c1ba exception handler tweaks (fixes #284) 2016-07-18 10:46:41 +02:00
Wenzel Jakob
d46b6eee5a Merge pull request #285 from jagerman/fix-uninitialized-str
Fix #283: don't print first arg of constructor
2016-07-18 10:09:24 +02:00
Jason Rhinelander
4e45e1805b Fix #283: don't print first arg of constructor
This changes the exception error message of a bad-arguments error to
suppress the constructor argument when the failure is a constructor.

This changes both the "Invoked with: " output to omit the object
instances, and rewrites the constructor signature to make it look
like a constructor (changing the first argument to the object name, and
removing the ' -> NoneType' return type.
2016-07-17 17:47:05 -04:00
Wenzel Jakob
fbdd30e5c5 Merge pull request #278 from jagerman/eigen-test-scipy-dep
Add missing scipy run-time dep to eigen test
2016-07-12 21:00:54 +02: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
Wenzel Jakob
a720a6046e updated changelog with v1.8.1, updated release instructions 2016-07-12 18:03:17 +02:00
Wenzel Jakob
4d727e10ab minor README.md fix 2016-07-12 16:58:55 +02:00
Wenzel Jakob
59b240a848 bump Intel compiler version requirement 2016-07-12 16:56:47 +02:00
Wenzel Jakob
c47d498c35 fix rare GC issue during type creation (fixes #277) 2016-07-11 23:41:15 +02:00
Wenzel Jakob
58ec1caa9b updated README and changelog 2016-07-11 23:39:39 +02:00
Wenzel Jakob
3c6ada3a48 Merge pull request #273 from lsst-dm/master
Add support for user defined exception translators
2016-07-11 23:38:21 +02:00
Pim Schellart
5a7d17ff16 Add support for user defined exception translators 2016-07-11 17:33:04 -04:00
Wenzel Jakob
4e27f7bb13 python 2.7 fix for example 5 2016-07-10 11:01:35 +02:00
Wenzel Jakob
e6b2f75949 updated changelog 2016-07-10 10:54:46 +02:00
Wenzel Jakob
954b7932fe avoid C++ -> Python -> C++ overheads when passing around function objects 2016-07-10 10:44:44 +02:00
Wenzel Jakob
52269e91aa Merge pull request #274 from jagerman/report-skipped-tests
Skip eigen test when eigen header available but NumPy not
2016-07-09 20:38:25 +02: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