Skip to content

Commit 79ee322

Browse files
authored
Merge pull request #72 from JuliaAI/dev
For a 0.1.14 release
2 parents 759bedc + 6559cb5 commit 79ee322

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CategoricalDistributions"
22
uuid = "af321ab8-2d2e-40a6-b165-3d674595d28e"
33
authors = ["Anthony D. Blaom <[email protected]>"]
4-
version = "0.1.13"
4+
version = "0.1.14"
55

66
[deps]
77
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"

src/arithmetic.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import Base: +, *, /, -
99
pdf_matrix(d::UnivariateFinite, L) = pdf.(d, L)
1010
pdf_matrix(d::AbstractArray{<:UnivariateFinite}, L) = pdf(d, L)
1111

12-
function +(d1::U, d2::U) where U <: SingletonOrArray
12+
function +(d1::UnivariateFinite{S, V}, d2::UnivariateFinite{S, V}) where {S, V}
13+
L = classes(d1)
14+
L == classes(d2) || throw(ERR_DIFFERENT_SAMPLE_SPACES)
15+
return UnivariateFinite(L, pdf_matrix(d1, L) + pdf_matrix(d2, L))
16+
end
17+
function +(d1::UnivariateFiniteArray{S, V}, d2::UnivariateFiniteArray{S, V}) where {S, V}
1318
L = classes(d1)
1419
L == classes(d2) || throw(ERR_DIFFERENT_SAMPLE_SPACES)
1520
return UnivariateFinite(L, pdf_matrix(d1, L) + pdf_matrix(d2, L))
@@ -27,7 +32,12 @@ end
2732
-(d::UnivariateFinite) = _minus(d, UnivariateFinite)
2833
-(d::UnivariateFiniteArray) = _minus(d, UnivariateFiniteArray)
2934

30-
function -(d1::U, d2::U) where U <: SingletonOrArray
35+
function -(d1::UnivariateFinite{S, V}, d2::UnivariateFinite{S, V}) where {S, V}
36+
L = classes(d1)
37+
L == classes(d2) || throw(ERR_DIFFERENT_SAMPLE_SPACES)
38+
return UnivariateFinite(L, pdf_matrix(d1, L) - pdf_matrix(d2, L))
39+
end
40+
function -(d1::UnivariateFiniteArray{S, V}, d2::UnivariateFiniteArray{S, V}) where {S, V}
3141
L = classes(d1)
3242
L == classes(d2) || throw(ERR_DIFFERENT_SAMPLE_SPACES)
3343
return UnivariateFinite(L, pdf_matrix(d1, L) - pdf_matrix(d2, L))

test/arithmetic.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ end
1313
L = ["yes", "no"]
1414
d1 = UnivariateFinite(L, rand(rng, 2), pool=missing)
1515
d2 = UnivariateFinite(L, rand(rng, 2), pool=missing)
16+
df32 = UnivariateFinite(L, rand(rng, Float32, 2), pool=missing)
1617

1718
@testset "arithmetic" begin
1819

1920
# addition and subtraction:
2021
for op in [:+, :-]
2122
quote
2223
s = $op(d1, d2 )
24+
s2 = $op(d1, df32 )
2325
@test $op(pdf.(d1, L), pdf.(d2, L)) pdf.(s, L)
26+
@test $op(pdf.(d1, L), pdf.(df32, L)) pdf.(s2, L)
2427
end |> eval
2528
end
2629

0 commit comments

Comments
 (0)