Skip to content

Commit

Permalink
Merge 6b0231e into 9f97462
Browse files Browse the repository at this point in the history
  • Loading branch information
theogf committed Nov 18, 2019
2 parents 9f97462 + 6b0231e commit 1e930ec
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/PDMats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module PDMats
"""
The base type for positive definite matrices.
"""
abstract type AbstractPDMat{T<:Real} end
abstract type AbstractPDMat{T<:Real} <: AbstractMatrix{T} end

const HAVE_CHOLMOD = isdefined(SuiteSparse, :CHOLMOD)

Expand Down
6 changes: 6 additions & 0 deletions src/pdiagmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ Base.Matrix(a::PDiagMat) = Matrix(Diagonal(a.diag))
LinearAlgebra.diag(a::PDiagMat) = copy(a.diag)
LinearAlgebra.cholesky(a::PDiagMat) = cholesky(Diagonal(a.diag))

### Inheriting from AbstractMatrix

Base.size(a::PDiagMat) = (a.dim,a.dim)
Base.getindex(a::PDiagMat{T},i::Integer) where {T} = i%a.dim == (i÷a.dim+1) ? a.diag[i%a.dim] : zero(T)
Base.getindex(a::PDiagMat{T},i::Integer,j::Integer) where {T} = i == j ? a.diag[i] : zero(T)

### Arithmetics

function pdadd!(r::Matrix, a::Matrix, b::PDiagMat, c)
Expand Down
8 changes: 7 additions & 1 deletion src/pdmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ Base.Matrix(a::PDMat) = copy(a.mat)
LinearAlgebra.diag(a::PDMat) = diag(a.mat)
LinearAlgebra.cholesky(a::PDMat) = a.chol

### Inheriting from AbstractMatrix

Base.size(a::PDMat) = size(a.mat)
Base.getindex(a::PDMat,i::Int) = getindex(a.mat,i)
Base.getindex(a::PDMat,i::Int,j::Int) = getindex(a.mat,i,j)

### Arithmetics

Expand All @@ -41,7 +46,8 @@ function pdadd!(r::Matrix, a::Matrix, b::PDMat, c)
end

*(a::PDMat{S}, c::T) where {S<:Real, T<:Real} = PDMat(a.mat * c)
*(a::PDMat, x::AbstractVecOrMat) = a.mat * x
*(a::PDMat, x::AbstractVector{T}) where {T} = a.mat * x
*(a::PDMat, x::AbstractMatrix{T}) where {T} = a.mat * x
\(a::PDMat, x::AbstractVecOrMat) = a.chol \ x


Expand Down
5 changes: 5 additions & 0 deletions src/pdsparsemat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ Base.Matrix(a::PDSparseMat) = Matrix(a.mat)
LinearAlgebra.diag(a::PDSparseMat) = diag(a.mat)
LinearAlgebra.cholesky(a::PDSparseMat) = a.chol

### Inheriting from AbstractMatrix

Base.size(a::PDSparseMat) = (a.dim,a.dim)
Base.getindex(a::PDSparseMat,i::Integer) = getindex(a.mat,i)
Base.getindex(a::PDSparseMat,i::Integer,j::Integer) = getindex(a.mat,i,j)

### Arithmetics

Expand Down
6 changes: 6 additions & 0 deletions src/scalmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ Base.Matrix(a::ScalMat) = Matrix(Diagonal(fill(a.value, a.dim)))
LinearAlgebra.diag(a::ScalMat) = fill(a.value, a.dim)
LinearAlgebra.cholesky(a::ScalMat) = cholesky(Diagonal(fill(a.value, a.dim)))

### Inheriting from AbstractMatrix

Base.size(a::ScalMat) = (a.dim,a.dim)
Base.getindex(a::ScalMat{T},i::Integer) where {T} = i%a.dim == (i÷a.dim+1) ? a.value : zero(T)
Base.getindex(a::ScalMat{T},i::Integer,j::Integer) where {T} = i == j ? a.value : zero(T)

### Arithmetics

function pdadd!(r::Matrix, a::Matrix, b::ScalMat, c)
Expand Down

0 comments on commit 1e930ec

Please sign in to comment.