Commit Graph

963 Commits

Author SHA1 Message Date
Wenzel Jakob
135fd14928 Merge pull request #449 from jagerman/no-implicit-conversions
Disable most implicit conversion constructors
2016-10-16 22:47:49 +02:00
Jason Rhinelander
12d76600f8 Disable most implicit conversion constructors
We have various classes that have non-explicit constructors that accept
a single argument, which is implicitly making them implicitly
convertible from the argument.  In a few cases, this is desirable (e.g.
implicit conversion of std::string to py::str, or conversion of double
to py::float_); in many others, however, it is unintended (e.g. implicit
conversion of size_t to some pre-declared py::array_t<T> type).

This disables most of the unwanted implicit conversions by marking them
`explicit`, and comments the ones that are deliberately left implicit.
2016-10-16 16:27:42 -04:00
Wenzel Jakob
946f897da0 Merge pull request #445 from lsst-dm/master
Accept any sequence type as std::vector (or std::list)
2016-10-15 23:50:06 +02:00
Pim Schellart
fcab621ee4 Merge pull request #4 from lsst-dm/tickets/DM-7115
Accept any sequence type as std::vector
2016-10-15 11:31:19 -04:00
Wenzel Jakob
8b51ed17c8 Merge pull request #444 from dean0x7d/inherit-dynamic-attr
Fix dynamic attribute inheritance in C++
2016-10-14 19:21:55 +02:00
Dean Moldovan
b8cb5ca7bd Fix dynamic attribute inheritance in C++
`PyType_Ready` would usually perform the inheritance for us, but it
can't adjust `tp_basicsize` appropriately.
2016-10-14 18:01:17 +02:00
Wenzel Jakob
5c13749aea Merge pull request #437 from dean0x7d/dynamic-attrs
Add dynamic attribute support
2016-10-14 08:57:12 +02:00
Dean Moldovan
9273af4f92 Document dynamic attributes 2016-10-14 01:16:40 +02:00
Wenzel Jakob
c01a1c1ade added array::ensure() function wrapping PyArray_FromAny
This convenience function ensures that a py::object is either a
py::array, or the implementation will try to convert it into one. Layout
requirements (such as c_style or f_style) can be also be provided.
2016-10-14 01:08:07 +02:00
Dean Moldovan
22726c9d22 Only allocate dict pointer when needed for dynamic attributes 2016-10-13 23:37:53 +02:00
Wenzel Jakob
00488a3e2c Merge pull request #440 from wjakob/master
Permit creation of NumPy arrays with a "base" object that owns the data
2016-10-13 10:50:35 +02:00
Wenzel Jakob
fac7c09458 NumPy "base" feature: integrated feedback by @aldanor 2016-10-13 10:49:53 +02:00
Wenzel Jakob
c49d6e508a py::print robustness improvements, added import exception class 2016-10-13 10:34:52 +02:00
Wenzel Jakob
369e9b3937 Permit creation of NumPy arrays with a "base" object that owns the data
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.
2016-10-13 01:03:40 +02:00
Wenzel Jakob
43f6aa6846 added numpy test (minor): check that 'strides' is respected even when creating new arrays
- This actually works with no changes, I just wasn't 100% convinced and
  decided to write a test to see if it's true.
2016-10-12 23:34:13 +02:00
Pim Schellart
d2afe7f001 Accept any sequence type as std::vector (or std::list) 2016-10-12 12:35:36 -04:00
Dean Moldovan
6fccf69360 Add dynamic attribute support 2016-10-11 22:13:02 +02:00
Wenzel Jakob
26df852392 removed forgotten message() stmt from CMakeLists.txt 2016-10-10 01:35:27 +02:00
Wenzel Jakob
6a1734af23 minor cmake cleanups 2016-10-09 20:14:23 +02:00
Wenzel Jakob
c3d8b8cf42 Merge pull request #435 from wjakob/master
extra python version sanity check at import time
2016-10-09 20:06:33 +02:00
Wenzel Jakob
4c00fd9ef6 extra python version sanity check at import time
Python 3.5 can often import pybind11 modules compiled compiled for
Python 3.4 (i.e. all symbols can be resolved), but this leads to crashes
later on due to changes in various Python-internal data structures. This
commit adds an extra sanity check to prevent a successful import when
the Python versions don't match.
2016-10-09 19:40:17 +02:00
Wenzel Jakob
f66610153f FindPythonLibsNew: wasn't actually setting PYTHONLIBS_FOUND contrary to specs 2016-10-09 14:12:24 +02:00
Wenzel Jakob
b55a5c5660 fixed typo in cmake file 2016-10-09 13:51:05 +02:00
Wenzel Jakob
e71ab8f455 unpacking_collector: allow nullptr-valued kwargs argument
This fixes an issue that can arise when forwarding (*args, **kwargs)
captured from a pybind11-bound function call to another Python function.
When the initial function call includes no keyword arguments, the
py::kwargs field is set to nullptr and causes a crash later on.
2016-10-08 15:30:02 +02:00
Wenzel Jakob
ba7678016c numpy.h: added array::squeeze() method 2016-10-07 11:19:57 +02:00
Wenzel Jakob
68a9989298 Merge pull request #429 from jagerman/accessor-bool-operator
Re-add accessor bool operator
2016-10-02 23:15:18 +02:00
Jason Rhinelander
7b8e3f9ec8 Re-add (but deprecated) bool operator for attr/items
PR #425 removed the bool operator from attribute accessors.  This is
likely in use by existing code as it was the only way before #425 added
the `hasattr` function to check for the existence of an attribute, via:

    if (obj.attr("foo")) { ... }

This commit adds it back in for attr and item accessors, but with a
deprecation warning to use `hasattr(obj, ...)` or `obj.contains(...)`
instead.
2016-10-02 16:39:51 -04:00
Wenzel Jakob
103d78d368 failed implicit conversions shouldn't lead to nullptr dereference 2016-09-30 13:43:19 +02:00
Wenzel Jakob
cd4d7d6bf8 very minor caster simplification 2016-09-30 12:20:19 +02:00
Wenzel Jakob
dac3858e7d Make header files viewable in IDEs (fixes #424) 2016-09-29 21:30:00 +02:00
Wenzel Jakob
5699986d12 Merge pull request #427 from dean0x7d/eigen-bases
Simplify base class detection for Eigen types
2016-09-29 21:20:26 +02:00
Dean Moldovan
71af3b07fb Simplify base class detection for Eigen types 2016-09-29 10:38:13 +02:00
Wenzel Jakob
886288787e contributor list update 2016-09-27 18:02:20 +02:00
Wenzel Jakob
632dee1e11 Merge pull request #356 from TrentHouliston/master
Add in casts for c++11s chrono classes to pythons datetime
2016-09-27 17:58:34 +02:00
Trent Houliston
10a6a90738 Redo documentation to make it easier to read 2016-09-28 01:01:59 +10:00
Trent Houliston
a3603e6df0 Simplify redundant code, conform to style suggestions, improve logic 2016-09-28 01:01:44 +10:00
Trent Houliston
253e41ccad Relax constraints on testing to ensure they work in all cases. 2016-09-28 00:59:21 +10:00
Wenzel Jakob
b0c4444687 format_descr constexpr tweak for MSVC by @jagerman (fixes #416) 2016-09-27 11:23:59 +02:00
Wenzel Jakob
0a014e9135 Merge pull request #425 from dean0x7d/accessors
Make the accessor interface more complete
2016-09-26 20:35:24 +02:00
Dean Moldovan
2bab5793f7 Later assignments to accessors should not overwrite the original field
`auto var = l[0]` has a strange quirk: `var` is actually an accessor and
not an object, so any later assignment of `var = ...` would modify l[0]
instead of `var`. This is surprising compared to the non-auto assignment
`py::object var = l[0]; var = ...`.

By overloading `operator=` on lvalue/rvalue, the expected behavior is
restored even for `auto` variables.
2016-09-23 02:00:01 +02:00
Dean Moldovan
ea763a57a8 Extend tuple and list accessor interface 2016-09-23 02:00:01 +02:00
Dean Moldovan
242b146a51 Extend attribute and item accessor interface using object_api 2016-09-23 02:00:01 +02:00
Dean Moldovan
865e43034b Make attr and item accessors throw on error instead of returning nullptr
This also adds the `hasattr` and `getattr` functions which are needed
with the new attribute behavior. The new functions behave exactly like
their Python counterparts.

Similarly `object` gets a `contains` method which calls `__contains__`,
i.e. it's the same as the `in` keyword in Python.
2016-09-23 01:40:22 +02:00
Dean Moldovan
37e22e436e Move common object functions into object_api mixin 2016-09-23 01:38:35 +02:00
Wenzel Jakob
2d9220f09d Merge pull request #423 from drufat/a
Use consistent indentation and typenames in numpy vectorize.
2016-09-22 23:57:49 +02:00
Dzhelil Rufat
c250ee5146 Use more consistent indentation and typenames names. 2016-09-22 14:51:41 -07:00
Wenzel Jakob
1ee4128cfe Merge pull request #420 from jagerman/doc-typos
Fix minor documentation spelling mistakes
2016-09-21 19:41:30 +02:00
Jason Rhinelander
20ef62656f Fix minor documentation spelling mistakes 2016-09-21 13:39:02 -04:00
Wenzel Jakob
d4285a6dda ..one more typo 2016-09-21 19:30:23 +02:00
Wenzel Jakob
514371ebec typo fixes (spotted by @TheGhostHuCodes) 2016-09-21 19:29:19 +02:00