feat: use LUT for numpy AEF dequantization#10
Open
Geethen wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The plain numpy path in
dequantize_aefrecomputes the same int8-to-float32 formula for every pixel value. AEF stores only 256 possible raw values, so large materialized windows spend avoidable time repeating(v / 127.5) ** 2 * sign(v)and then applying a separate nodata mask.Fix
This adds a 256-entry lookup table for the plain ndarray path and maps raw values through it with
lut[raw + 128]. The-128 -> NaNnodata mapping is folded into the table. The xarray/DataArray path stays elementwise so dask-backed arrays remain lazy and blockwise.In local checks on a 2048 x 2048 x 64 materialized AEF window, this changed numpy dequantization from about 2702 ms to 1582 ms, while preserving identical output.
Tests
Adds
tests/test_utils.pycoverage asserting the LUT path matches the reference formula for all 256 int8 values, for both int8 and int16 inputs.Ran locally: