Skip to content

Commit

Permalink
Merge 04145c4 into 83d2440
Browse files Browse the repository at this point in the history
  • Loading branch information
crbinz committed Dec 18, 2016
2 parents 83d2440 + 04145c4 commit 5dea4e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/pdmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function pdadd!(r::Matrix, a::Matrix, b::PDMat, c)
_addscal!(r, a, b.mat, c)
end

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

Expand Down
24 changes: 24 additions & 0 deletions test/generics.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

# test operators with pd matrix types
using PDMats
using Base.Test

# test scalar multiplication
print_with_color(:blue, "Testing scalar multiplication\n")
pm1 = PDMat(eye(3))
pm2 = PDiagMat(ones(3))
pm3 = ScalMat(3,1)

pm1a = PDMat(3.0 .* eye(3))
pm2a = PDiagMat(3.0 .* ones(3))
pm3a = ScalMat(3, 3)

pmats = Any[pm1, pm2, pm3]
pmatsa= Any[pm1a,pm2a,pm3a]

for i in 1:length(pmats)
@test full(3.0 * pmats[i]) == full(pmatsa[i])
@test full(pmats[i] * 3.0) == full(pmatsa[i])
@test full(3 * pmats[i]) == full(pmatsa[i])
@test full(pmats[i] * 3) == full(pmatsa[i])
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests = ["pdmtypes", "addition"]
tests = ["pdmtypes", "addition", "generics"]
println("Running tests ...")

for t in tests
Expand Down

0 comments on commit 5dea4e3

Please sign in to comment.