diff --git a/src/prod.jl b/src/prod.jl index b13e10b..ff514bd 100644 --- a/src/prod.jl +++ b/src/prod.jl @@ -387,12 +387,6 @@ function Base.prod( return push!(product, item) end -function Base.prod( - ::GenericProd, ::UnspecifiedProd, ::UnspecifiedProd, left::ProductOf{F,F}, right::F -) where {F} - return LinearizedProductOf(F[getleft(left), getright(left), right], 3) -end - function Base.prod( ::GenericProd, ::UnspecifiedProd, ::UnspecifiedProd, left::ProductOf{L,R}, right::R ) where {L,R} @@ -417,6 +411,18 @@ function Base.prod( return ProductOf(getleft(right), LinearizedProductOf(R[left, getright(right)], 2)) end +function Base.prod( + ::GenericProd, ::UnspecifiedProd, ::UnspecifiedProd, left::T, right::ProductOf{T,T} +) where {T} + return LinearizedProductOf(T[left, getleft(right), getright(right)], 3) +end + +function Base.prod( + ::GenericProd, ::UnspecifiedProd, ::UnspecifiedProd, left::ProductOf{T,T}, right::T +) where {T} + return LinearizedProductOf(T[getleft(left), getright(left), right], 3) +end + function Base.prod( ::GenericProd, ::UnspecifiedProd, diff --git a/test/prod_tests.jl b/test/prod_tests.jl index db372b8..6d492be 100644 --- a/test/prod_tests.jl +++ b/test/prod_tests.jl @@ -295,7 +295,6 @@ end end @testitem "`ProductOf` should support distributions that do not have explicitly defined `support`" begin - struct SomeComplexDistribution end BayesBase.support(::SomeComplexDistribution) = error("not defined") @@ -309,11 +308,9 @@ end @test !insupport(prod, -1) @test logpdf(prod, 1) === 2 @test logpdf(prod, 2) === 4 - end @testitem "`LinearizedProductOf` should support distributions that do not have explicitly defined `support`" begin - struct SomeComplexDistribution end BayesBase.support(::SomeComplexDistribution) = error("not defined") @@ -327,5 +324,34 @@ end @test !insupport(prod, -1) @test logpdf(prod, 1) === 2 @test logpdf(prod, 2) === 4 +end + +@testitem "There should be no ambiguity in `prod` for `ProductOf`" begin + struct SomeArbitraryDistribution end + + @test prod( + GenericProd(), + SomeArbitraryDistribution(), + ProductOf(SomeArbitraryDistribution(), SomeArbitraryDistribution()), + ) == LinearizedProductOf( + [ + SomeArbitraryDistribution(), + SomeArbitraryDistribution(), + SomeArbitraryDistribution(), + ], + 3, + ) + @test prod( + GenericProd(), + ProductOf(SomeArbitraryDistribution(), SomeArbitraryDistribution()), + SomeArbitraryDistribution(), + ) == LinearizedProductOf( + [ + SomeArbitraryDistribution(), + SomeArbitraryDistribution(), + SomeArbitraryDistribution(), + ], + 3, + ) end \ No newline at end of file