Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TST: Calculate RMS and diff image in C++#29102

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
QuLogic wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromQuLogic:cpp-rms

Conversation

QuLogic
Copy link
Member

PR summary

The current implementation is not slow, but uses a lot of memory per image.

Incompare_images, we have:

  • one actual and one expected image as uint8 (2×image)
  • both converted to int16 (though original is thrown away) (4×)

which adds up to 4× the image allocated in this function.

Then it callscalculate_rms, which has:

  • a difference between them as int16 (2×)
  • the difference cast to 64-bit float (8×)
  • the square of the difference as 64-bit float (though possibly the original difference was thrown away) (8×)

which at its peak has 16× the image allocated in parallel.

If the RMS is over the desired tolerance, thensave_diff_image is called, which:

  • loads the actual and expected imagesagain as uint8 (2× image)
  • converts both to 64-bit float (throwing away the original) (16×)
  • calculates the difference (8×)
  • calculates the absolute value (8×)
  • multiples that by 10 (in-place, so no allocation)
  • clips to 0-255 (8×)
  • casts to uint8 (1×)

which at peak uses 32× the image.

So at their peak,compare_imagescalculate_rms will have 20× the image allocated, and thencompare_imagessave_diff_image will have 36× the image allocated. This is generally not a problem, but on resource-constrained places like WASM, it can sometimes run out of memory just incalculate_rms.

This implementation in C++ always allocates the diff image, even when not needed, but doesn't have all the temporaries, so it's a maximum of 3× the image size (plus a few scalar temporaries).

PR checklist

The current implementation is not slow, but uses a lot of memory perimage.In `compare_images`, we have:- one actual and one expected image as uint8 (2×image)- both converted to int16 (though original is thrown away) (4×)which adds up to 4× the image allocated in this function.Then it calls `calculate_rms`, which has:- a difference between them as int16 (2×)- the difference cast to 64-bit float (8×)- the square of the difference as 64-bit float (though possibly the  original difference was thrown away) (8×)which at its peak has 16× the image allocated in parallel.If the RMS is over the desired tolerance, then `save_diff_image` iscalled, which:- loads the actual and expected images _again_ as uint8 (2× image)- converts both to 64-bit float (throwing away the original) (16×)- calculates the difference (8×)- calculates the absolute value (8×)- multiples that by 10 (in-place, so no allocation)- clips to 0-255 (8×)- casts to uint8 (1×)which at peak uses 32× the image.So at their peak, `compare_images`→`calculate_rms` will have 20× theimage allocated, and then `compare_images`→`save_diff_image` will have36× the image allocated. This is generally not a problem, but onresource-constrained places like WASM, it can sometimes run out ofmemory just in `calculate_rms`.This implementation in C++ always allocates the diff image, even whennot needed, but doesn't have all the temporaries, so it's a maximum of3× the image size (plus a few scalar temporaries).
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp