Skip to content

Fix ACA workspace allocation for strain and max_iter=0 edge case#53

Merged
maresb merged 4 commits intocutde-org:mainfrom
maresb:fix/aca-edge-cases
Mar 6, 2026
Merged

Fix ACA workspace allocation for strain and max_iter=0 edge case#53
maresb merged 4 commits intocutde-org:mainfrom
maresb:fix/aca-edge-cases

Conversation

@maresb
Copy link
Copy Markdown
Collaborator

@maresb maresb commented Mar 6, 2026

Summary

Details

fworkspace_per_block (gh-52): The Python-side workspace allocation had the 3 and vec_dim multipliers swapped relative to the C kernel layout:

# Before (buggy):
fworkspace_per_block = n_cols + n_rows + 3 * n_cols + vec_dim * n_rows
# After (matches kernel layout):
fworkspace_per_block = n_cols + n_rows + vec_dim * n_cols + 3 * n_rows

For displacement (vec_dim=3) both expressions are identical, so the bug was invisible. For strain (vec_dim=6), blocks with n_cols > n_rows caused heap buffer overflow (SIGABRT on Linux, silent corruption on macOS).

max_iter=0: When max_iter=0, the ACA loop never executes but n_terms was set to k + 1 = 1. Now correctly returns 0 terms.

Made with Cursor

maresb added 4 commits March 6, 2026 11:47
When max_iter=0, no ACA terms should be produced and the result
should be a zero-rank approximation.
When max_iter is 0 (either passed explicitly or due to tiny blocks),
the ACA loop never executes but n_terms was incorrectly set to 1.
This caused the Python post-processing to read uninitialized buffer
memory. Now correctly sets n_terms to 0 when no iterations run.
…h-52)

With vec_dim=6 and n_src > 2*n_obs, the undersized workspace causes
a heap buffer overflow (SIGABRT on Linux, silent corruption on macOS).
The 3rd and 4th terms had swapped multipliers: used 3*n_cols and
vec_dim*n_rows instead of vec_dim*n_cols and 3*n_rows. This matched
the kernel layout for displacement (vec_dim=3) but was undersized
for strain (vec_dim=6) when n_cols > n_rows.
@maresb maresb force-pushed the fix/aca-edge-cases branch from b740a22 to fbcf264 Compare March 6, 2026 10:47
@maresb maresb merged commit 221dc80 into cutde-org:main Mar 6, 2026
23 checks passed
@maresb maresb deleted the fix/aca-edge-cases branch March 6, 2026 11:01
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.

Bug: fworkspace allocation in aca.py undersized for strain (vec_dim=6) with asymmetric blocks

1 participant