Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/Sparse/HNF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,18 @@
return hnf_kannan_bachem(A; truncate, full_hnf, auto, limit)
end

function hnf_with_trafo(A::SMat{ZZRingElem}; truncate::Bool = false, full_hnf::Bool = true, auto::Bool = false, limit::Int=typemax(Int))
B, T = hnf_kannan_bachem(A, Val(true); truncate, full_hnf, auto, limit)
I = sparse_matrix(ZZ, 0, nrows(A))
for i in 1:nrows(A)
push!(I, sparse_row(ZZ, [(i, ZZ(1))]))
end
for (i, TT) in enumerate(T)
apply_left!(I, TT)
end
return B, I

Check warning on line 837 in src/Sparse/HNF.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/HNF.jl#L828-L837

Added lines #L828 - L837 were not covered by tests
end

@doc raw"""
hnf!(A::SMat{ZZRingElem})

Expand All @@ -838,20 +850,40 @@
A.c = B.c
end

function hnf_with_trafo!(A::SMat{ZZRingElem}, I::SMat{ZZRingElem}; truncate::Bool = false, full_hnf::Bool = true, auto::Bool = false)
B, U = hnf_with_trafo(A; truncate, full_hnf, auto)
A.rows = B.rows
A.nnz = B.nnz
A.r = B.r
A.c = B.c
I.rows = U.rows
I.nnz = U.nnz
I.r = U.r
I.c = U.c

Check warning on line 862 in src/Sparse/HNF.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/HNF.jl#L853-L862

Added lines #L853 - L862 were not covered by tests
end

@doc raw"""
diagonal_form(A::SMat{ZZRingElem}) -> SMat{ZZRingElem}

A matrix $D$ that is diagonal and obtained via unimodular row and column operations.
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?

sa = size(A)
if nrows(A) < ncols(A)
A = transpose(A)
else
A = deepcopy(A)
end
el_div = ZZRingElem[]
U = []
V = []
if with_right_trafo
V = identity_matrix(ZZ, ncols(A))

Check warning on line 882 in src/Sparse/HNF.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/HNF.jl#L882

Added line #L882 was not covered by tests
end
if with_left_trafo
U = identity_matrix(ZZ, nrows(A))

Check warning on line 885 in src/Sparse/HNF.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/HNF.jl#L885

Added line #L885 was not covered by tests
end
while true
r = nrows(A)
hnf!(A; auto = true, truncate = true)
Expand All @@ -865,6 +897,7 @@
append!(el_div, [ZZ(1) for j = 1:i-1])
if i > 1
A = sub(A, i:nrows(A), 1:ncols(A))
print(Matrix(A))
end
if all(x->length(x) == 1, A.rows)
for x = A.rows
Expand Down
69 changes: 69 additions & 0 deletions src/Sparse/UpperTriangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,75 @@
#
################################################################################

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?

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

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

Check warning on line 13 in src/Sparse/UpperTriangular.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/UpperTriangular.jl#L7-L13

Added lines #L7 - L13 were not covered by tests
Comment on lines +10 to +13
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))

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

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

Check warning on line 19 in src/Sparse/UpperTriangular.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/UpperTriangular.jl#L15-L19

Added lines #L15 - L19 were not covered by tests
Comment on lines +16 to +19
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))

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)

if n % 2 == 1
if left == false
hnf!(A, truncate=false, full_hnf=true, auto=false)

Check warning on line 24 in src/Sparse/UpperTriangular.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/UpperTriangular.jl#L21-L24

Added lines #L21 - L24 were not covered by tests
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))

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

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)

rR = row * C
R[i] = rR
end
C = R

Check warning on line 36 in src/Sparse/UpperTriangular.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/UpperTriangular.jl#L26-L36

Added lines #L26 - L36 were not covered by tests
end
A = transpose(A)
n = n + 1

Check warning on line 39 in src/Sparse/UpperTriangular.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/UpperTriangular.jl#L38-L39

Added lines #L38 - L39 were not covered by tests
else
if right == false
hnf!(A, truncate=false, full_hnf=true, auto=false)

Check warning on line 42 in src/Sparse/UpperTriangular.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/UpperTriangular.jl#L41-L42

Added lines #L41 - L42 were not covered by tests
else
I = sparse_matrix(ZZ, 0, ncols(A))
for i in 1:ncols(A)
push!(I, sparse_row(ZZ, [(i, ZZ(1))]))
end
Comment on lines +44 to +47
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))

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)

rR = row * D
R[i] = rR
end
D = R

Check warning on line 54 in src/Sparse/UpperTriangular.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/UpperTriangular.jl#L44-L54

Added lines #L44 - L54 were not covered by tests
end
A = transpose(A)
n = n + 1

Check warning on line 57 in src/Sparse/UpperTriangular.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/UpperTriangular.jl#L56-L57

Added lines #L56 - L57 were not covered by tests
end
end
if n % 2 == 0
A = transpose(A)

Check warning on line 61 in src/Sparse/UpperTriangular.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/UpperTriangular.jl#L59-L61

Added lines #L59 - L61 were not covered by tests
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

return C, A, transpose(D)

Check warning on line 64 in src/Sparse/UpperTriangular.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/UpperTriangular.jl#L63-L64

Added lines #L63 - L64 were not covered by tests
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

return C, A

Check warning on line 67 in src/Sparse/UpperTriangular.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/UpperTriangular.jl#L66-L67

Added lines #L66 - L67 were not covered by tests
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

return A, transpose(D)

Check warning on line 70 in src/Sparse/UpperTriangular.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/UpperTriangular.jl#L69-L70

Added lines #L69 - L70 were not covered by tests
else
return A

Check warning on line 72 in src/Sparse/UpperTriangular.jl

View check run for this annotation

Codecov / codecov/patch

src/Sparse/UpperTriangular.jl#L72

Added line #L72 was not covered by tests
end
end

@doc raw"""
diagonal(A::SMat) -> ZZRingElem[]

Expand Down
Loading