Skip to content

Added functions to get HNF transformation matrices#1879

Open
jstriete wants to merge 1 commit intothofma:masterfrom
jstriete:add_hnf_fuunctions
Open

Added functions to get HNF transformation matrices#1879
jstriete wants to merge 1 commit intothofma:masterfrom
jstriete:add_hnf_fuunctions

Conversation

@jstriete
Copy link
Copy Markdown

@jstriete jstriete commented Jun 5, 2025

Edits HNF.jl and UpperTriangular.jl to add some functions that will return requested transformation matrices for the HNF decomposition.

Copy link
Copy Markdown
Owner

@thofma thofma left a comment

Choose a reason for hiding this comment

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

Thanks! I left a few minor comments. Apart from these things and adding tests, this looks good.

Like a snf without the divisibility condition.
"""
function diagonal_form(A::SMat{ZZRingElem})
function diagonal_form(A::SMat{ZZRingElem}, with_right_trafo = false, with_left_trafo = false)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I guess this is not used anymore, right?

#
################################################################################

function diagonal_form_with_transform(A::SMat, left=false, right=false)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you add a docstring or comment in the code?

end
hnf_with_trafo!(A, I, truncate=false, full_hnf=true, auto=false)
R = sparse_matrix(base_ring(C), nrows(I), ncols(C))
for (i, row) in enumerate(I.rows)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
for (i, row) in enumerate(I.rows)
for (i, row) in enumerate(I)

if left == false
hnf!(A, truncate=false, full_hnf=true, auto=false)
else
I = sparse_matrix(ZZ, 0, nrows(A))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
I = sparse_matrix(ZZ, 0, nrows(A))
I = sparse_matrix(ZZ, 0, nrows(A))

end
hnf_with_trafo!(A, I, truncate=false, full_hnf=true, auto=false)
R = sparse_matrix(base_ring(D), nrows(I), ncols(D))
for (i, row) in enumerate(I.rows)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
for (i, row) in enumerate(I.rows)
for (i, row) in enumerate(I)

if n % 2 == 0
A = transpose(A)
end
if left == true && right == true
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
if left == true && right == true
if left && right

if left == true && right == true
return C, A, transpose(D)
end
if left == true
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
if left == true
if left

if left == true
return C, A
end
if right == true
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
if right == true
if right


function diagonal_form_with_transform(A::SMat, left=false, right=false)
n = 1
if left == true
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
if left == true
if left

push!(C, sparse_row(ZZ, [(i, ZZ(1))]))
end
end
if right == true
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
if right == true
if right

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 5, 2025

Codecov Report

Attention: Patch coverage is 7.31707% with 76 lines in your changes missing coverage. Please review.

Project coverage is 76.46%. Comparing base (d0f456f) to head (12820f7).

Files with missing lines Patch % Lines
src/Sparse/UpperTriangular.jl 0.00% 54 Missing ⚠️
src/Sparse/HNF.jl 21.42% 22 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1879      +/-   ##
==========================================
- Coverage   76.54%   76.46%   -0.08%     
==========================================
  Files         364      364              
  Lines      115639   115720      +81     
==========================================
- Hits        88513    88489      -24     
- Misses      27126    27231     +105     
Files with missing lines Coverage Δ
src/Sparse/HNF.jl 69.44% <21.42%> (-2.57%) ⬇️
src/Sparse/UpperTriangular.jl 18.94% <0.00%> (-24.96%) ⬇️

... and 33 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +10 to +13
C = sparse_matrix(ZZ, 0, nrows(A))
for i in 1:nrows(A)
push!(C, sparse_row(ZZ, [(i, ZZ(1))]))
end
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.

Suggested change
C = sparse_matrix(ZZ, 0, nrows(A))
for i in 1:nrows(A)
push!(C, sparse_row(ZZ, [(i, ZZ(1))]))
end
C = identity_matrix(SMat, ZZ, nrows(A))

Comment on lines +16 to +19
D = sparse_matrix(ZZ, 0, ncols(A))
for i in 1:ncols(A)
push!(D, sparse_row(ZZ, [(i, ZZ(1))]))
end
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.

Suggested change
D = sparse_matrix(ZZ, 0, ncols(A))
for i in 1:ncols(A)
push!(D, sparse_row(ZZ, [(i, ZZ(1))]))
end
D = identity_matrix(SMat, ZZ, ncols(A))

push!(D, sparse_row(ZZ, [(i, ZZ(1))]))
end
end
while(!is_diagonal(A))
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.

Suggested change
while(!is_diagonal(A))
while !is_diagonal(A)

Comment on lines +26 to +29
I = sparse_matrix(ZZ, 0, nrows(A))
for i in 1:nrows(A)
push!(I, sparse_row(ZZ, [(i, ZZ(1))]))
end
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.

Suggested change
I = sparse_matrix(ZZ, 0, nrows(A))
for i in 1:nrows(A)
push!(I, sparse_row(ZZ, [(i, ZZ(1))]))
end
I = identity_matrix(SMat, ZZ, nrows(A))

Comment on lines +44 to +47
I = sparse_matrix(ZZ, 0, ncols(A))
for i in 1:ncols(A)
push!(I, sparse_row(ZZ, [(i, ZZ(1))]))
end
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.

Suggested change
I = sparse_matrix(ZZ, 0, ncols(A))
for i in 1:ncols(A)
push!(I, sparse_row(ZZ, [(i, ZZ(1))]))
end
I = identity_matrix(SMat, ZZ, ncols(A))

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.

4 participants