Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow std::complex field with PYBIND11_NUMPY_DTYPE #831

Merged
merged 9 commits into from
May 10, 2017

Commits on May 4, 2017

  1. Allow std::complex field with PYBIND11_NUMPY_DTYPE

    This exposed a few underlying issues:
    
    1. is_pod_struct was too strict to allow this. I've relaxed it to
    require only trivially copyable and standard layout, rather than POD
    (which additionally requires a trivial constructor, which std::complex
    violates). Should the name be changed too? There might also need to be
    some documentation to warn the user not to do something stupid with a
    class that has invariants.
    
    2. format_descriptor<std::complex<T>>::format() returned numpy format
    strings instead of PEP3118 format strings, but register_dtype
    feeds format codes of its fields to _dtype_from_pep3118. I've changed it
    to return PEP3118 format codes. format_descriptor is a public type, so
    this may be considered an incompatible change.
    
    3. register_structured_dtype tried to be smart about whether to mark
    fields as unaligned (with ^). However, it's examining the C++ alignment,
    rather than what numpy (or possibly PEP3118) thinks the alignment should
    be. For complex values those are different. I've made it mark all fields
    as ^ unconditionally, which should always be safe even if they are
    aligned, because we explicitly mark the padding.
    bmerry committed May 4, 2017
    Configuration menu
    Copy the full SHA
    d383bd8 View commit details
    Browse the repository at this point in the history
  2. Workaround for GCC 4

    GCC 4 doesn't provide std::is_trivially_copyable.
    bmerry committed May 4, 2017
    Configuration menu
    Copy the full SHA
    51b51b6 View commit details
    Browse the repository at this point in the history
  3. Refinement to GCC 4 workaround

    Require either a trivial copy constructor or a trivial copy assignment,
    but not both. This is slightly more relaxed than being
    TriviallyCopyable, which requires that both are either trivial or
    deleted, and that at least one is not deleted. With this check, one of
    them could be user-provided.
    bmerry committed May 4, 2017
    Configuration menu
    Copy the full SHA
    fb8a4ed View commit details
    Browse the repository at this point in the history
  4. Workaround for numpy/numpy#9049

    This moves the ^ in the format string (to specify unaligned) to
    outside the `T{}` where it is sure to be parsed correctly. This is not
    strictly necessary yet, but it paves the way for pybind#832.
    bmerry committed May 4, 2017
    Configuration menu
    Copy the full SHA
    271f380 View commit details
    Browse the repository at this point in the history

Commits on May 6, 2017

  1. Workaround for MSVC2015 bug

    For some reason, returning the 'value' constexpr char array as a string
    would yield an empty string for format_descriptor<float>. I tried a few
    variants of the constructor and this is the first variation I found that
    worked.
    bmerry committed May 6, 2017
    Configuration menu
    Copy the full SHA
    c8f6488 View commit details
    Browse the repository at this point in the history

Commits on May 8, 2017

  1. Restructure format_descriptor overload for complex

    At the request of @jagerman, a separate specialization of
    format_descriptor is implemented for std::complex.
    
    This may run into MSVC 2015 bugs again - will put back the workaround if
    it fails.
    bmerry committed May 8, 2017
    Configuration menu
    Copy the full SHA
    bd5be69 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    0556c35 View commit details
    Browse the repository at this point in the history
  3. Add documentation about what structured types are acceptable

    This is to go with the weakened is_pod_struct static_assert.
    bmerry committed May 8, 2017
    Configuration menu
    Copy the full SHA
    f5818b4 View commit details
    Browse the repository at this point in the history

Commits on May 10, 2017

  1. Configuration menu
    Copy the full SHA
    979d979 View commit details
    Browse the repository at this point in the history