Comments (3)
Is the fix as easy as defining
julia> using LinearAlgebra
julia> function LinearAlgebra.cholesky!(A::Diagonal{T}, ::RowMaximum; tol=0.0, check::Bool=true) where {T <: Real}
A .= T.(sqrt.(A))
rank = size(A, 1)
uplo = 'L'
info = 0
return CholeskyPivoted(A, uplo, 1:rank, rank, tol, info)
end
julia> function LinearAlgebra.cholesky(A::Diagonal, ::RowMaximum; tol=0.0, check::Bool=true)
A = sqrt.(A)
rank = size(A, 1)
uplo = 'L'
info = 0
return CholeskyPivoted(A, uplo, 1:rank, rank, tol, info)
end
julia> cholesky(2 * I(2))
Cholesky{Float64, Diagonal{Float64, Vector{Float64}}}
U factor:
2×2 Diagonal{Float64, Vector{Float64}}:
1.41421 ⋅
⋅ 1.41421
julia> cholesky(2 * I(2), RowMaximum())
CholeskyPivoted{Float64, Diagonal{Float64, Vector{Float64}}, UnitRange{Int64}}
L factor with rank 2:
2×2 LowerTriangular{Float64, Diagonal{Float64, Vector{Float64}}}:
1.41421 ⋅
0.0 1.41421
permutation:
1:2
julia> cholesky!(2 * I(2), RowMaximum())
ERROR: InexactError: Int64(1.4142135623730951)
Stacktrace:
[1] Int64
@ ./float.jl:900 [inlined]
[2] _broadcast_getindex_evalf
@ ./broadcast.jl:683 [inlined]
[3] _broadcast_getindex
@ ./broadcast.jl:656 [inlined]
[4] copyto!(dest::Diagonal{Int64, Vector{Int64}}, bc::Base.Broadcast.Broadcasted{LinearAlgebra.StructuredMatrixStyle{Diagonal{Int64, Vector{Int64}}}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}, Type{Int64}, Tuple{Base.Broadcast.Broadcasted{LinearAlgebra.StructuredMatrixStyle{Diagonal{Int64, Vector{Int64}}}, Nothing, typeof(sqrt), Tuple{Diagonal{Int64, Vector{Int64}}}}}})
@ LinearAlgebra ~/.julia/juliaup/julia-1.9.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.9/LinearAlgebra/src/structuredbroadcast.jl:160
[5] materialize!
@ ./broadcast.jl:884 [inlined]
[6] materialize!
@ ./broadcast.jl:881 [inlined]
[7] #cholesky!#7
@ ./REPL[5]:2 [inlined]
[8] cholesky!(A::Diagonal{Int64, Vector{Int64}}, ::RowMaximum)
@ Main ./REPL[5]:1
[9] top-level scope
@ REPL[9]:1
julia> cholesky!(4 * I(2), RowMaximum())
CholeskyPivoted{Int64, Diagonal{Int64, Vector{Int64}}, UnitRange{Int64}}
L factor with rank 2:
2×2 LowerTriangular{Int64, Diagonal{Int64, Vector{Int64}}}:
2 ⋅
0 2
permutation:
1:2
julia> cholesky!(2.0 * I(2), RowMaximum())
CholeskyPivoted{Float64, Diagonal{Float64, Vector{Float64}}, UnitRange{Int64}}
L factor with rank 2:
2×2 LowerTriangular{Float64, Diagonal{Float64, Vector{Float64}}}:
1.41421 ⋅
0.0 1.41421
permutation:
1:2
julia> cholesky(2 * I(2), RowMaximum())
CholeskyPivoted{Float64, Diagonal{Float64, Vector{Float64}}, UnitRange{Int64}}
L factor with rank 2:
2×2 LowerTriangular{Float64, Diagonal{Float64, Vector{Float64}}}:
1.41421 ⋅
0.0 1.41421
permutation:
1:2
julia> cholesky(2.0 * I(2), RowMaximum())
CholeskyPivoted{Float64, Diagonal{Float64, Vector{Float64}}, UnitRange{Int64}}
L factor with rank 2:
2×2 LowerTriangular{Float64, Diagonal{Float64, Vector{Float64}}}:
1.41421 ⋅
0.0 1.41421
permutation:
1:2
?
I'm unsure how I feel about
function LinearAlgebra.cholesky!(A::Diagonal{T}, ::RowMaximum; tol=0.0, check::Bool=true) where {T <: Real}
A .= T.(sqrt.(A))
rank = size(A, 1)
uplo = 'L'
info = 0
return CholeskyPivoted(A, uplo, 1:rank, rank, tol, info)
end
It means that sometimes it works for Int
and sometimes doesn't. I guess we could be more restrictive and do
function LinearAlgebra.cholesky!(A::Diagonal{<:AbstractFloat}, ::RowMaximum; tol=0.0, check::Bool=true)
A .= sqrt.(A)
rank = size(A, 1)
uplo = 'L'
info = 0
return CholeskyPivoted(A, uplo, 1:rank, rank, tol, info)
end
thoughts @dkarrasch ? The other question is whether we should call collect(1:rank)
or just return the range. Let me know and I'll open up a PR.
from julia.
Hmmm, I guess I need to also handle the case where one of the diagonal elements is zero. In that case, I would call collect(1:rank)
for consistency when there's an actual pivot.
from julia.
I'm not sure how exactly the pivoting works, but I thought that pivoted Cholesky is rank revealing in the sense that the (almost) zero diagonal entries come at the end:
julia> using LinearAlgebra
julia> D = Diagonal(collect(0:9));
julia> cholesky(Matrix(D), RowMaximum(), check = false)
CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}
U factor with rank 9:
10×10 UpperTriangular{Float64, Matrix{Float64}}:
3.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
⋅ 2.82843 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
⋅ ⋅ 2.64575 0.0 0.0 0.0 0.0 0.0 0.0 0.0
⋅ ⋅ ⋅ 2.44949 0.0 0.0 0.0 0.0 0.0 0.0
⋅ ⋅ ⋅ ⋅ 2.23607 0.0 0.0 0.0 0.0 0.0
⋅ ⋅ ⋅ ⋅ ⋅ 2.0 0.0 0.0 0.0 0.0
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.73205 0.0 0.0 0.0
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.41421 0.0 0.0
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 0.0
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 0.0
permutation:
10-element Vector{Int64}:
10
9
8
7
6
5
4
3
2
1
ADDENDUM: Also, in this simple case with a clear zero we need to set check = false
because otherwise the matrix method throws a RankDeficientException(1)
.
from julia.
Related Issues (20)
- `make test-all` does not emit error even if test dependencies are missing in stdlib
- Document to use nightly Julia to contribute to the standard library HOT 2
- Over/underflow in complex power function
- Proposed Negation Default Broadcast Behavior HOT 4
- Dotplot not overlaying violin plot HOT 1
- Filenames on Windows in coverage output are missing drive letter HOT 2
- Add ability to specify multiple paths via --code-coverage=@<path>
- ^C inside pkg-add prompt causes assertion abort
- Argument destructuring returned from macro accidentally assigns global
- Potentially erring paths in matrix logarithms HOT 1
- `nm -D --with-symbol-versions` unreliable
- julia1.10.4 using CUDA ERROR: failed to parse TOML output from running "~/.julia/packages/CUDA_Runtime_jll/VNnmC/.pkg/select_artifacts.jl", got: TOML Parser error: none:1:7 error: expected equal sign after key
- Stack overflow during gc_read_stack on win32 HOT 2
- Make an `isdense` trait HOT 8
- `factorize(<:AbstractMatrix)` prefers `Cholesky` but `factorize(<:Hermitian)` prefers `BunchKaufman` HOT 2
- Concurrent program crashes 1.12 nightly build (1.10 is fine) HOT 1
- Intermittent segmentation fault while running CFITSIO tests on nightly HOT 2
- Conversion to pointer not defined for `Base.ReinterpretArray` on v1.11 and above HOT 2
- Julia Rejecting this target due to use of runtime-disabled feature HOT 3
- Base.PersistentDict/HAMT: rehashing is ineffective HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia.