Skip to content

Commit

Permalink
fix xlogx, xlogy
Browse files Browse the repository at this point in the history
  • Loading branch information
cossio committed May 19, 2020
1 parent b7a603d commit 3638892
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/basicfuns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ julia> StatsFuns.xlogx(0)
"""
function xlogx(x)
result = x * log(x)
ifelse(x > zero(x), result, zero(result))
ifelse(iszero(x), zero(result), result)
end

"""
Expand All @@ -23,7 +23,7 @@ Return `x * log(y)` for `y > 0` with correct limit at `x = 0`.
"""
function xlogy(x, y)
result = x * log(y)
ifelse(x > zero(x), result, zero(result))
ifelse(iszero(x), zero(result), result)
end

# The following bounds are precomputed versions of the following abstract
Expand Down
4 changes: 3 additions & 1 deletion test/basicfuns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ using StatsFuns, Test
@testset "xlogx & xlogy" begin
@test iszero(xlogx(0))
@test xlogx(2) 2.0 * log(2.0)
@test_throws DomainError xlogx(-1)

@test iszero(xlogy(0, 1))
@test xlogy(2, 3) 2.0 * log(3.0)
@test_throws DomainError xlogy(1, -1)
end

@testset "logistic & logit" begin
Expand Down Expand Up @@ -94,7 +96,7 @@ end
@test logsumexp(arguments) result
end
end

@test isnan(logsubexp(Inf, Inf))
@test isnan(logsubexp(-Inf, -Inf))
@test logsubexp(Inf, 9.0) Inf
Expand Down

0 comments on commit 3638892

Please sign in to comment.