Skip to content

Commit

Permalink
test: add inverse wishart wishart product
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimrais committed Oct 24, 2024
1 parent 25283dc commit 2c11b39
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
29 changes: 29 additions & 0 deletions test/distributions/wishart_inverse_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,32 @@ end
end
end
end

@testitem "InverseWishart: prod between InverseWishart and InverseWishartFast" begin
include("distributions_setuptests.jl")

import ExponentialFamily: InverseWishartFast
import Distributions: InverseWishart

for Sleft in rand(InverseWishart(10, Array(Eye(2))), 2), Sright in rand(InverseWishart(10, Array(Eye(2))), 2), νright in (6, 7), νleft in (4, 5)
let left = InverseWishart(νleft, Sleft), right = InverseWishartFast(νright, Sright)
# Test commutativity of the product
prod_result1 = prod(PreserveTypeProd(Distribution), left, right)
prod_result2 = prod(PreserveTypeProd(Distribution), right, left)

@test prod_result1.ν prod_result2.ν
@test prod_result1.S prod_result2.S

# Test that the product preserves type
@test prod_result1 isa InverseWishartFast
@test prod_result2 isa InverseWishartFast

# prod prod stays if we convert fisrt and then do product
left_fast = convert(InverseWishartFast, left)
prod_fast = prod(ClosedProd(), left_fast, right)

@test prod_fast.ν prod_result1.ν
@test prod_fast.S prod_result2.S
end
end
end
5 changes: 3 additions & 2 deletions test/distributions/wishart_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,13 @@ end
@test prod_result1 isa WishartFast
@test prod_result2 isa WishartFast

# prod the same before conversion
# prod stays the same if we convert fisrt and then do product
left_fast = convert(WishartFast, left)
prod_fast = prod(ClosedProd(), left_fast, right)

@test prod_fast.ν prod_result1.ν
@test prod_fast.invS prod_result2.invS
end
end
end
end

0 comments on commit 2c11b39

Please sign in to comment.