Skip to content

Commit

Permalink
Merge pull request #34 from milankl/mk/masked
Browse files Browse the repository at this point in the history
use === for masked_value comparison for NaN
  • Loading branch information
milankl authored Mar 29, 2022
2 parents ca05176 + 4825cf9 commit f0e3cd8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mutual_information.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ function bitinformation(A::AbstractArray{T};
masked_value::Union{T,Nothing}=nothing,
kwargs...) where {T<:Union{Integer,AbstractFloat}}

# create a BitArray mask if a masked_value is provided
isnothing(masked_value) || return bitinformation(A,A .== masked_value;dim,kwargs...)
# create a BitArray mask if a masked_value is provided, use === to also allow NaN comparison
isnothing(masked_value) || return bitinformation(A,A .=== masked_value;dim,kwargs...)

A = permute_dim_forward(A,dim) # Permute A to take adjacent entry in dimension dim
n = size(A)[1] # n elements in dim
Expand Down
7 changes: 7 additions & 0 deletions test/information.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,12 @@ end
round!(A,1)
mask = A .== masked_value
@test bitinformation(A,mask) == bitinformation(A;masked_value)

# check that masked_value=NaN also works
A[:,2] .= NaN # put some NaNs somewhere
mask = BitArray(undef,size(A)...) # create corresponding mask
fill!(mask,false)
mask[:,2] .= true
@test bitinformation(A,mask) == bitinformation(A;masked_value=convert(T,NaN))
end
end

2 comments on commit f0e3cd8

@milankl
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: "Tag with name v0.4.0 already exists and points to a different commit"

Please sign in to comment.