FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use Python buffer protocol when converting Python objects to .NET arrays · Issue #1838 · pythonnet/pythonnet · GitHub

Repository navigation

Use Python buffer protocol when converting Python objects to .NET arrays #1838

Open

Description

Copying data from NumPy array to C# is a common task. Python.NET implements a simple sequence-to-array copying mechanism, which uses iterators. It is extremely inefficient for large arrays of primitive types.

Now we have a better way - using PyBuffer and buffer protocol. We could detect, that Python object implements the buffer protocol, use it to copy data when possible, and fallback to iteration otherwise.

Activity

  1. lostmsu commented on Jun 27, 2022

    MemberAuthor

    If somebody wants to take on it, this test shows simple use of PyBuffer: TestBufferRead

    And this is the method that needs to be changed: Converter.ToArray

  2. filmor commented on Jun 27, 2022

    Member

    This would not break API/ABI, so we can integrate it in a normal point release after 3.0, right?

  3. lostmsu commented on Jun 27, 2022

    MemberAuthor

    Yep.

  4. added this to the milestone on Jun 28, 2022
  5. bruceYangxianglin commented on Aug 14, 2022

    Copying data from C# array to Python list or Numpy array is also a common task. Is there a more efficient way?

  6. removed this from the milestone on Sep 30, 2022
  7. bjudkewitz commented on Mar 25, 2023

    Agreed, converting a python array to a C# array is a very common task, and it is currently extremely slow. It would be fantastic to make it faster. Is it currently possibly with Python (and Python.NET) only, without any C# programming?

  8. yahav6893 commented on Nov 19, 2023

    Hi! I’m looking for some guidance on how to speed up copying from Python to C#.
    Would anyone be able to point me in the right way to do that?
    Thanks ahead.

  9. chickenservice commented on Apr 15, 2024

    Hi, is someone currently working on this? If not I'd be happy to try. I've been using pythonnet at work successfully for years and would be glad to help. I'm familiar with the topic because I have already dealt with converting numpy arrays from/to C# arrays in an efficient manner. It'd be great to have this natively in pythonnet.

  10. filmor commented on Apr 15, 2024

    Member

    @chickenservice To my knowledge, no one is currently actively working on this, so give it a shot! An implementation would be greatly appreciated!

  11. chickenservice commented on Apr 15, 2024

    @filmor Perfect, is there anything besides the steps in CONTRIBUTING.md that I need to be aware of?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL