Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Commit62a96ff
committed
TST: Calculate RMS and diff image in C++
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).1 parent38a8e15 commit62a96ff
2 files changed
+79
-9
lines changedLines changed: 4 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
19 | 19 |
| |
20 | 20 |
| |
21 | 21 |
| |
22 |
| - | |
| 22 | + | |
23 | 23 |
| |
24 | 24 |
| |
25 | 25 |
| |
| |||
398 | 398 |
| |
399 | 399 |
| |
400 | 400 |
| |
401 |
| - | |
| 401 | + | |
402 | 402 |
| |
403 | 403 |
| |
404 | 404 |
| |
| |||
469 | 469 |
| |
470 | 470 |
| |
471 | 471 |
| |
472 |
| - | |
473 |
| - | |
474 |
| - | |
475 |
| - | |
476 |
| - | |
477 |
| - | |
| 472 | + | |
478 | 473 |
| |
479 | 474 |
| |
480 | 475 |
| |
481 | 476 |
| |
482 |
| - | |
| 477 | + | |
483 | 478 |
| |
484 | 479 |
| |
485 | 480 |
| |
|
Lines changed: 75 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 | 2 |
| |
3 | 3 |
| |
| 4 | + | |
| 5 | + | |
4 | 6 |
| |
5 | 7 |
| |
6 | 8 |
| |
| |||
200 | 202 |
| |
201 | 203 |
| |
202 | 204 |
| |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
203 | 275 |
| |
204 | 276 |
| |
205 | 277 |
| |
| |||
232 | 304 |
| |
233 | 305 |
| |
234 | 306 |
| |
| 307 | + | |
| 308 | + | |
| 309 | + | |
235 | 310 |
|
0 commit comments
Comments
(0)