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

Python buffer objects can have negative strides. #782

Merged
merged 4 commits into from
May 7, 2017
Merged

Python buffer objects can have negative strides. #782

merged 4 commits into from
May 7, 2017

Commits on May 3, 2017

  1. Python buffer objects can have negative strides.

    Cris Luengo committed May 3, 2017
    Configuration menu
    Copy the full SHA
    98b43bb View commit details
    Browse the repository at this point in the history
  2. Making a copy when casting a numpy array with negative strides to Eigen.

    `EigenConformable::stride_compatible` returns false if the strides are
    negative. In this case, do not use `EigenConformable::stride`, as it
    is {0,0}. We cannot write negative strides in this element, as Eigen
    will throw an assertion if we do.
    
    The `type_caster` specialization for regular, dense Eigen matrices now
    does a second `array_t::ensure` to copy data in case of negative strides.
    I'm not sure that this is the best way to implement this.
    
    I have added "TODO" tags linking these changes to Eigen bug #747, which,
    when fixed, will allow Eigen to accept negative strides.
    Cris Luengo committed May 3, 2017
    Configuration menu
    Copy the full SHA
    253e5f3 View commit details
    Browse the repository at this point in the history
  3. Use numpy rather than Eigen for copying

    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.
    jagerman authored and Cris Luengo committed May 3, 2017
    Configuration menu
    Copy the full SHA
    ddec26a View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    3e14727 View commit details
    Browse the repository at this point in the history