Skip to content

Commit 12015fb

Browse files
authored
Merge branch 'master' into patch-1
2 parents 391c8d1 + e1884b9 commit 12015fb

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

src/pdiagmat.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ LinearAlgebra.cholesky(a::PDiagMat) = cholesky(Diagonal(a.diag))
3030

3131
### Inheriting from AbstractMatrix
3232

33-
Base.size(a::PDiagMat) = (a.dim, a.dim)
34-
Base.getindex(a::PDiagMat{T},i::Integer) where {T} = i % a.dim == (i ÷ a.dim + 1) ? a.diag[i % a.dim] : zero(T)
33+
function Base.getindex(a::PDiagMat, i::Integer)
34+
ncol, nrow = fldmod1(i, a.dim)
35+
ncol == nrow ? a.diag[nrow] : zero(eltype(a))
36+
end
3537
Base.getindex(a::PDiagMat{T},i::Integer,j::Integer) where {T} = i == j ? a.diag[i] : zero(T)
3638

3739
### Arithmetics

src/pdmat.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ LinearAlgebra.cholesky(a::PDMat) = a.chol
3434

3535
### Inheriting from AbstractMatrix
3636

37-
Base.size(a::PDMat) = size(a.mat)
3837
Base.getindex(a::PDMat, i::Int) = getindex(a.mat, i)
3938
Base.getindex(a::PDMat, I::Vararg{Int, N}) where {N} = getindex(a.mat, I...)
4039

src/pdsparsemat.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ LinearAlgebra.cholesky(a::PDSparseMat) = a.chol
3232

3333
### Inheriting from AbstractMatrix
3434

35-
Base.size(a::PDSparseMat) = (a.dim, a.dim)
3635
Base.getindex(a::PDSparseMat,i::Integer) = getindex(a.mat, i)
3736
Base.getindex(a::PDSparseMat,I::Vararg{Int, N}) where {N} = getindex(a.mat, I...)
3837

src/scalmat.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ LinearAlgebra.cholesky(a::ScalMat) = cholesky(Diagonal(fill(a.value, a.dim)))
2222

2323
### Inheriting from AbstractMatrix
2424

25-
Base.size(a::ScalMat) = (a.dim, a.dim)
26-
Base.getindex(a::ScalMat{T}, i::Integer) where {T} = i%a.dim == (i ÷ a.dim + 1) ? a.value : zero(T)
25+
function Base.getindex(a::ScalMat, i::Integer)
26+
ncol, nrow = fldmod1(i, a.dim)
27+
ncol == nrow ? a.value : zero(eltype(a))
28+
end
2729
Base.getindex(a::ScalMat{T}, i::Integer, j::Integer) where {T} = i == j ? a.value : zero(T)
2830

2931
### Arithmetics

test/addition.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ for T in [Float64,Float32]
77
printstyled("Testing addition with eltype = $T\n", color=:blue)
88
M = convert(Array{T,2},[4. -2. -1.; -2. 5. -1.; -1. -1. 6.])
99
V = convert(Array{T,1},[1.5, 2.5, 2.0])
10-
X = convert(T,2.0)
10+
local X = convert(T,2.0)
1111

1212
pm1 = PDMat(M)
1313
pm2 = PDiagMat(V)

test/testutils.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,14 @@ function pdtest_basics(C::AbstractPDMat, Cmat::Matrix, d::Int, verbose::Int)
7979
_pdt(verbose, "eltype")
8080
@test eltype(C) == eltype(Cmat)
8181
# @test eltype(typeof(C)) == eltype(typeof(Cmat))
82-
82+
83+
_pdt(verbose, "index")
84+
@test all(C[i] == Cmat[i] for i in 1:(d^2))
85+
@test all(C[i, j] == Cmat[i, j] for j in 1:d, i in 1:d)
86+
8387
_pdt(verbose, "isposdef")
8488
@test isposdef(C)
85-
89+
8690
_pdt(verbose, "ishermitian")
8791
@test ishermitian(C)
8892
end
@@ -186,9 +190,15 @@ function pdtest_mul(C::AbstractPDMat, Cmat::Matrix, X::Matrix, verbose::Int)
186190
_pdt(verbose, "multiply")
187191
@test C * X Cmat * X
188192

193+
y = similar(C * X, size(C, 1))
194+
ymat = similar(Cmat * X, size(Cmat, 1))
189195
for i = 1:size(X,2)
190196
xi = vec(copy(X[:,i]))
191197
@test C * xi Cmat * xi
198+
199+
mul!(y, C, xi)
200+
mul!(ymat, Cmat, xi)
201+
@test y ymat
192202
end
193203
end
194204

0 commit comments

Comments
 (0)