You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This adds a "constructor cascade" that allows one to coerce the inputs
to the chosen type. This is frequently useful in generic programming
where you want an object to be of the same type as something else,
for example when appending to a list of objects.
Co-authored-by: David Widmann <[email protected]>
PDMat{T,S}(m::AbstractMatrix{T},c::Cholesky{T,S}) where {T,S} =new{T,S}(m,c)
9
-
end
10
-
11
-
functionPDMat(mat::AbstractMatrix,chol::Cholesky{T,S}) where {T,S}
12
-
d = LinearAlgebra.checksquare(mat)
13
-
ifsize(chol, 1) != d
14
-
throw(DimensionMismatch("Dimensions of mat and chol are inconsistent."))
8
+
functionPDMat{T,S}(m::AbstractMatrix, c::Cholesky) where {T<:Real,S<:AbstractMatrix{T}}
9
+
d = LinearAlgebra.checksquare(m)
10
+
ifsize(c, 1) != d
11
+
throw(DimensionMismatch("Dimensions of mat and chol are inconsistent."))
12
+
end
13
+
# in principle we might want to check that `c` is a Cholesky factorization of `m`,
14
+
# but that's slow
15
+
returnnew{T,S}(m,c)
15
16
end
16
-
PDMat{T,S}(convert(S, mat), chol)
17
17
end
18
+
functionPDMat{T}(m::AbstractMatrix, c::Cholesky) where T<:Real
19
+
c =convert(Cholesky{T}, c)
20
+
returnPDMat{T,typeof(c.factors)}(m, c)
21
+
end
22
+
PDMat(mat::AbstractMatrix,chol::Cholesky{T,S}) where {T<:Real,S<:AbstractMatrix{T}} =PDMat{T,S}(mat, chol)
18
23
24
+
# Construction from another PDMat
25
+
PDMat{T,S}(pdm::PDMat{T,S}) where {T<:Real,S<:AbstractMatrix{T}} = pdm # since PDMat doesn't support `setindex!` it's not mutable (xref https://docs.julialang.org/en/v1/manual/conversion-and-promotion/#Mutable-collections)
26
+
PDMat{T,S}(pdm::PDMat) where {T<:Real,S<:AbstractMatrix{T}} =PDMat{T,S}(pdm.mat, pdm.chol)
27
+
PDMat{T}(pdm::PDMat{T}) where T<:Real= pdm
28
+
PDMat{T}(pdm::PDMat) where T<:Real=PDMat{T}(pdm.mat, pdm.chol)
29
+
PDMat(pdm::PDMat) = pdm
30
+
31
+
# Construction from an AbstractMatrix
32
+
functionPDMat{T,S}(mat::AbstractMatrix) where {T<:Real,S<:AbstractMatrix{T}}
33
+
mat =convert(S, mat)
34
+
returnPDMat{T,S}(mat, cholesky(mat))
35
+
end
36
+
functionPDMat{T}(mat::AbstractMatrix) where T<:Real
0 commit comments