Skip to content

[WIP] Add upper_tri and diag_mat affine atoms#54

Merged
dance858 merged 6 commits intomainfrom
adds-more-affine-atoms
Apr 12, 2026
Merged

[WIP] Add upper_tri and diag_mat affine atoms#54
dance858 merged 6 commits intomainfrom
adds-more-affine-atoms

Conversation

@Transurgeon
Copy link
Copy Markdown
Collaborator

Both are thin wrappers that compute flat column-major index arrays and delegate to new_index. diag_mat extracts the diagonal of a square matrix into a vector. upper_tri extracts strict upper triangular elements (excluding diagonal).

Also removes a duplicate new_diag_vec declaration in affine.h.

Both are thin wrappers that compute flat column-major index arrays
and delegate to new_index. diag_mat extracts the diagonal of a
square matrix into a vector. upper_tri extracts strict upper
triangular elements (excluding diagonal).

Also removes a duplicate new_diag_vec declaration in affine.h.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Transurgeon Transurgeon changed the title Add upper_tri and diag_mat affine atoms [Ready for review] Add upper_tri and diag_mat affine atoms Mar 26, 2026
@Transurgeon
Copy link
Copy Markdown
Collaborator Author

@dance858 you can wait before reviewing this.
I encountered a nasty bug about ordering with upper_tri while testing from python.
I think for some reason in python it takes the upper_tri values in row-major order.. I will explore this a bit more before we keep looking at this.

@Transurgeon Transurgeon marked this pull request as draft March 27, 2026 02:50
@Transurgeon Transurgeon changed the title [Ready for review] Add upper_tri and diag_mat affine atoms [WIP] Add upper_tri and diag_mat affine atoms Mar 27, 2026
@Transurgeon Transurgeon marked this pull request as ready for review April 12, 2026 11:39
Transurgeon and others added 5 commits April 12, 2026 07:51
# Conflicts:
#	include/atoms/affine.h
#	src/atoms/affine/diag_mat.c
#	src/atoms/affine/upper_tri.c
#	tests/all_tests.c
CVXPY's upper_tri returns elements row-by-row (i outer, j inner),
which differs from the engine's typical column-major convention.
Swap the loop nesting to iterate rows-then-columns for compatibility.
Add a 4x4 forward test that distinguishes the two orderings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The 3x3 tests produced identical indices for both row-major and
column-major orderings, so they didn't actually verify the fix.
4x4 indices [4,8,12,9,13,14] differ from column-major [4,8,9,12,13,14].

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Transurgeon
Copy link
Copy Markdown
Collaborator Author

@dance858 this PR is ready for review!
I cleaned it up and synced with master, then also made it so that upper_tri returns values in row-major order.

@dance858
Copy link
Copy Markdown
Collaborator

Beautiful code @Transurgeon. Very nice abstraction.

Let's remember to test it on the python side when we have bindings and make a new SparseDiffPy release. I'm merging this but creating an issue to remember it.

@dance858 dance858 merged commit e71b945 into main Apr 12, 2026
11 checks passed
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.

2 participants