Skip to content

Improve SimdDescrInt API documentation in SimdLib.h - #360

Merged
ermig1979 merged 3 commits into
masterfrom
copilot/improve-function-descriptions-another-one
Jun 3, 2026
Merged

Improve SimdDescrInt API documentation in SimdLib.h#360
ermig1979 merged 3 commits into
masterfrom
copilot/improve-function-descriptions-another-one

Conversation

Copilot AI commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

The existing Doxygen comments for the SimdDescrInt family were superficial, omitting the encoding format, quantization algorithm, and the role of the precomputed header fields — all of which are non-obvious and critical for correct usage.

Changes

  • SimdDescrIntInit — Documents the exact binary layout of every encoded descriptor:

    • Bytes 0–3: inverse quantization scale (1/scale)
    • Bytes 4–7: minimum value (shift)
    • Bytes 8–11: precomputed dot-product sum helper
    • Bytes 12–15: precomputed L2 norm
    • Bytes 16–N: bit-packed quantized integers, depth bits per element, little-endian
  • SimdDescrIntEncodedSize — Adds the formula: 16 + ceil(size * depth / 8).

  • SimdDescrIntDecodedSize — Clarifies it returns the size passed to Init; lists which encode/decode calls require it as a buffer length.

  • SimdDescrIntEncode32f / SimdDescrIntEncode16f — Documents the full encoding pipeline: min/max scan → scale = (2^depth−1)/(max−min) → round quantize → bit-pack → header write. Notes that Encode16f converts FP16→FP32 internally before the same pipeline.

  • SimdDescrIntDecode32f / SimdDescrIntDecode16f — Documents reconstruction formula dst[i] = q[i] * invScale + min; notes precision is depth-dependent. Decode16f additionally converts each output to FP16.

  • SimdDescrIntCosineDistance — Adds formal definition (1 − dot(a,b)/(‖a‖·‖b‖)), explains that the integer dot product is computed directly on bit-packed data using header scale/shift, and that L2 norms are read from precomputed header fields (no decoding). Result is clamped to [0, 2].

  • SimdDescrIntCosineDistancesMxNa / MxNp — Clarifies M×N row-major output layout. Distinguishes the two variants: MxNa takes an array of pointers (non-contiguous memory); MxNp takes flat contiguous arrays with stride i * encodedSize.

  • SimdDescrIntVectorNorm — Clarifies it reads the precomputed L2 norm from the header (no recomputation).

Copilot AI changed the title Improve SimdDescrInt function descriptions in SimdLib.h Improve SimdDescrInt API documentation in SimdLib.h Jun 2, 2026
Copilot AI requested a review from ermig1979 June 2, 2026 16:20
@ermig1979
ermig1979 marked this pull request as ready for review June 2, 2026 16:21
Copilot AI review requested due to automatic review settings June 2, 2026 16:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Doxygen documentation in SimdLib.h, primarily expanding and clarifying the Integer Descriptor Engine (SimdDescrInt*) API, including encoded descriptor layout and cosine-distance semantics. It also includes a set of broader documentation clarifications for several image conversion, binarization, conditional, and copy APIs.

Changes:

  • Expanded SimdDescrInt* docs with encoded buffer layout, encode/decode pipeline details, and cosine-distance matrix conventions.
  • Clarified behavior/constraints for several image conversion (BGR→Lab/RGB/YUV) and binarization/conditional/copy APIs.
  • Minor doc-logic and parameter-description fixes (including pseudocode and boundary/stride explanations).

Comment thread src/Simd/SimdLib.h
Comment on lines 2541 to 2543
All images must have 8-bit gray format and must have the same width and height.
Image width and height must be greater than neighborhood.

Comment thread src/Simd/SimdLib.h
- Bytes 0.. 3: 32-bit float inverse quantization scale (1 / scale).
- Bytes 4.. 7: 32-bit float minimum value (shift) used during quantization.
- Bytes 8..11: 32-bit float precomputed sum helper for dot-product reconstruction.
- Bytes 12..15: 32-bit float precomputed L2 norm of the original float descriptor.
Comment thread src/Simd/SimdLib.h
starting at byte offset 16.
5. Writes a 16-byte header at the beginning of \a dst containing four 32-bit floats:
inverse scale (1/scale), minimum value (min), a precomputed sum helper used for
dot-product reconstruction, and the precomputed L2 norm of the original descriptor.
Comment thread src/Simd/SimdLib.h
Comment on lines +2969 to +2973
where \a a and \a b are treated as vectors in the original float space.
The function computes the integer dot product directly on the bit-packed data and then
reconstructs the true float dot product using the quantization scale and shift stored
in the 16-byte headers of the encoded descriptors. The L2 norms are read directly from
the precomputed values in the headers, avoiding full decoding.
Comment thread src/Simd/SimdLib.h
Comment on lines +3040 to +3043
The L2 norm of the original float descriptor is computed and stored in the 16-byte header
of the encoded descriptor during encoding (by ::SimdDescrIntEncode32f or ::SimdDescrIntEncode16f).
This function retrieves that precomputed value without performing any additional computation.
The norm equals the Euclidean length of the original float descriptor before quantization.
Comment thread src/Simd/SimdLib.h
\param [in] a - a pointer to integer descriptor.
\param [out] norm - a pointer to result 32-bit float norm.
\param [in] a - a pointer to the encoded integer descriptor.
\param [out] norm - a pointer to a 32-bit float that receives the precomputed L2 norm of the original float descriptor.
@ermig1979
ermig1979 merged commit ac50c31 into master Jun 3, 2026
25 checks passed
@ermig1979
ermig1979 deleted the copilot/improve-function-descriptions-another-one branch July 1, 2026 11:08
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.

3 participants