Skip to content

Add FactorResidualOffsetAndDim to Linearizer and DenseLinearizer - #479

Open
thiagopari wants to merge 1 commit into
symforce-org:mainfrom
thiagopari:factor-residual-offsets
Open

thiagopari wants to merge 1 commit into
symforce-org:mainfrom
thiagopari:factor-residual-offsets

Conversation

@thiagopari

Copy link
Copy Markdown

Summary

Adds FactorResidualOffsetAndDim(factor_index) to Linearizer and DenseLinearizer, as suggested in #320. It returns the offset and dimension of factors[factor_index]'s residual within the combined residual (equivalently, its rows of the combined jacobian), so callers can use linearization.residual.segment(offset, dim) instead of replicating the bookkeeping in BuildInitialLinearization().

Implementation

  • Each linearizer records factor_residual_offsets_ during the first linearization: one int32_t per factor plus the total residual dimension at the end, so the lookup is O(1).
  • Asserts IsInitialized() and that the index is in range, the same contract as StateIndex().
  • The relinearization path is unchanged.

Testing

  • symforce_linearizer_test.cc: interleaves sparse and dense factors with different residual sizes. For every factor it checks the offset and dim, and that residual.segment(offset, dim) equals that factor's own residual. It does this on the first linearization and again on a relinearization, and checks that the blocks add up to residual.size().
  • symforce_dense_linearizer_test.cc: the same checks for DenseLinearizer.
  • Both test binaries pass locally, and clang-format is clean.

I didn't add Python bindings; happy to add them if you'd like.

Fixes #320

Records, during the first linearization, where each factor's residual
lands in the combined residual (and the rows of the combined jacobian),
so callers can pull out per-factor residuals or jacobian blocks without
recomputing the layout themselves.

Fixes symforce-org#320

This branch has not been deployed

No deployments
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.

Residual to Factor map

1 participant