Skip to content

Test update test#13

Closed
jholveck wants to merge 16 commits into
mainfrom
test-update-test
Closed

Test update test#13
jholveck wants to merge 16 commits into
mainfrom
test-update-test

Conversation

@jholveck

Copy link
Copy Markdown
Owner

Changes proposed in this PR

Fixes #
(...)

  • Tests added/updated
  • Documentation updated
  • Changelog entry added
  • ./check.sh passed

Currently, this shares memory with the .raw bytearray in some cases.
We should consider whether we want to change that to always copy, or
just wait until we have the full shared buffer support.

This implementation always does the array manipulation on the CPU.
For PyTorch or TensorFlow, the user is likely to want to do the array
manipulation on the GPU for performance.  This is very easy to
implement.
Python 3.9 doesn't define TypeAlias, and it's not required in this
case, so we can just remove it.
The reverted change was from a temporary test, but I accidentally
included it in the commit.  It's not relevant to the issue at hand.
The docstrings weren't all in Sphinx format, and could use a little
clarification in places.

TensorFlow itself allows NumPy dtypes and DataType enums, so expand
to_tensorflow to accept those too.
The main point of this commit is to be explicit about the memory-sharing
semantics: mostly, that we don't guarantee memory sharing one way or
another.  More to the point, that if they modify the pixel data in one
of the exported objects, it may or may not affect the other exported
objects.

Memory sharing isn't expected to affect most users, since they
are unlikely to access the pixel data with two different exported
objects, but it's best to be explicit.

To have a good place to put the memory-sharing discussion, I added a new
section to the usage.rst file, listing the ways to access the pixel
data.  This is also where I documented the NumPy array interface
protocol, which previously didn't show up in our Sphinx docs.  (It might
have been in the docs for 10.1, which didn't use autodoc.)

I also put a discussion of the alpha channel in this new section: one
thing I keep forgetting is to delete the alpha channel when using
Matplotlib, and wondering why it's blank.

TODO: We probably should document `grab` in the usage.rst file for the
new section to make sense.

In the process, I've also added intersphinx links to libraries like PIL
and NumPy, so that our Sphinx docs will link to them.  While checking
that, I fixed a few other references (like referring to bytes with
:py:type:, when it's indexed under :py:class:).
Doc fixes.  Speed up converting to a NumPy array in RGB order.  That
sort of thing.
While I was writing this, I realized something else.  We may want to
change the to_torch and to_tensorflow methods to accept device and
stream arguments, and do the channel and layout shuffling on the GPU
instead of the CPU.  This wouldn't require us to natively support CUDA
or anything like that; we'd just be using PyTorch / TensorFlow's
existing CUDA support, which is easy.

This demo still (as before) shows the GPU-focused way to do the
channel and layout shuffling, presented as an alternative to using
to_torch.  A quick test shows about 107 ms / frame (to_torch)
vs. about 62 ms / frame (GPU-focused routine), and that's including
the CNN itself too.  So there's a very significant benefit there.
(That's not quite a fair comparison, since the GPU-focused routine is
exactly what this program needs, but not so it'd be a big difference.)
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4a1da77b-de43-487d-9c8e-901b86d67ea7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test-update-test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

While improving performance earlier in this PR, I had introduced a
case where to_torch would fail only for the RGB order.  It also seemed
likely that some cases might fail only if using particular
combinations of channel order and layout, so we just test them all.
@jholveck jholveck closed this Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant