Skip to content

Conversation

@jpn--
Copy link
Member

@jpn-- jpn-- commented Oct 29, 2025

This pull request introduces comprehensive improvements for handling sparse matrix blending in the codebase, focusing on both robustness and usability. It enhances the sparse_blender functionality to automatically create dense backing arrays when needed, improves error handling for missing sparse data, and adds documentation and tests to verify correct blending behavior. The changes are grouped as follows:

Sparse Matrix Blending Enhancements:

  • The sparse_blender method in sharrow/sparse.py now automatically creates a zero-filled dense backing array if the named variable does not exist, ensuring that sparse blending works even when only sparse data is available.
  • The method signature and docstring for sparse_blender have been expanded to support and clearly document new parameters (backing_i_dim, backing_j_dim), blending logic, and usage examples.

Error Handling and Logic Improvements:

  • In sharrow/aster.py, error handling is improved for cases where a sparse variable is missing a dense backstop: the code now sets the result to zero and lets the blender logic handle the fallback, instead of raising a KeyError.
  • The logic for returning nodes in the AST is updated to ensure correct behavior when a backstop is missing for sparse variables.

Blending Logic Refinements:

  • The AST code for calling get_blended_2 is refactored to only include the blend_limit argument if max_blend_distance is not infinite, improving clarity and correctness of blending calls.

Testing and Validation:

  • A new comprehensive test suite (sharrow/tests/test_sparse.py) is added to verify sparse blending, transformations, accessor methods, shared memory compatibility, blender attributes, reverse lookups, and dense dimension lookups, ensuring robust coverage for all blending scenarios.

General Codebase Improvements:

  • Logging is introduced in sharrow/sparse.py to warn when a zero backing array is created, aiding debugging and transparency.

These changes greatly improve the reliability, documentation, and test coverage of sparse blending functionality in the codebase.

@jpn-- jpn-- merged commit ab25d30 into ActivitySim:main Oct 31, 2025
14 checks passed
@jpn-- jpn-- deleted the patch-missing-backstop branch October 31, 2025 00:12
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.

1 participant