Skip to content

Commit

Permalink
misc alignment cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thchr committed Mar 9, 2021
1 parent e463591 commit cadbbf7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/SmithNormalForm.jl
@@ -1,6 +1,5 @@
module SmithNormalForm

# import Base: show, getindex
using LinearAlgebra
using SparseArrays
using Base.CoreLogging
Expand All @@ -13,6 +12,7 @@ export snf, smith, Smith
include("bezout.jl")
include("snf.jl")

# ---------------------------------------------------------------------------------------- #

struct Smith{P,Q<:AbstractMatrix{P},V<:AbstractVector{P}} <: Factorization{P}
S::Q
Expand All @@ -27,6 +27,8 @@ end
Smith(S::AbstractMatrix{P}, T::AbstractMatrix{P}, SNF::AbstractVector{P}) where {P} =
Smith{P,typeof(S),typeof(SNF)}(S, similar(S, 0, 0), T, similar(T, 0, 0), SNF)

# ---------------------------------------------------------------------------------------- #

"""
smith(X::AbstractMatrix{P}; inverse::Bool=true) --> Smith{P,Q,V}
Expand All @@ -48,6 +50,8 @@ function smith(X::AbstractMatrix{P}; inverse::Bool=true) where {P}
return Smith{P, typeof(X), typeof(SNF)}(S, Sinv, T, Tinv, SNF)
end

# ---------------------------------------------------------------------------------------- #

"""
diagm(F::Smith) --> AbstractMatrix
Expand Down
16 changes: 8 additions & 8 deletions src/snf.jl
@@ -1,6 +1,6 @@
# Smith Normal Form

function divisable(y::R, x::R ) where {R}
function divisable(y::R, x::R) where {R}
x == zero(R) && return y == zero(R)
return div(y,x)*x == y
end
Expand Down Expand Up @@ -115,11 +115,11 @@ function colpivot(V::AbstractArray{R,2},
end
end

function smithpivot(U::AbstractArray{R,2},
Uinv::AbstractArray{R,2},
V::AbstractArray{R,2},
Vinv::AbstractArray{R,2},
D::AbstractArray{R,2},
function smithpivot(U::AbstractMatrix{R},
Uinv::AbstractMatrix{R},
V::AbstractMatrix{R},
Vinv::AbstractMatrix{R},
D::AbstractMatrix{R},
i, j; inverse=true) where {R}

pivot = D[i,j]
Expand Down Expand Up @@ -240,11 +240,11 @@ function snf(M::AbstractMatrix{R}; inverse=true) where {R}
j > cols && break
Λⱼ = D[j,j]
if Λⱼ < 0
@views V[j,:] .*= -1 # T′ = sign(Λ)*T [rows]
@views V[j,:] .*= -1 # T′ = sign(Λ)*T [rows]
if inverse
@views Vinv[:,j] .*= -1 # T⁻¹′ = T⁻¹*sign(Λ) [columns]
end
D[j,j] = abs(Λⱼ) # Λ′ = Λ*sign(Λ)
D[j,j] = abs(Λⱼ) # Λ′ = Λ*sign(Λ)
end
end
@logmsg (Base.CoreLogging.Debug-1) "Factorization" D=formatmtx(D) U=formatmtx(U) V=formatmtx(V) U⁻¹=formatmtx(Uinv) V⁻¹=formatmtx(Vinv)
Expand Down

0 comments on commit cadbbf7

Please sign in to comment.