Open wjholden opened 2 hours ago
julia> xicor([1], [1]; noties=true)
NaN
julia> xicor([1], [1]; noties=false)
NaN
julia> xicor([], []; noties=true)
1.0
julia> xicor([], []; noties=false)
ERROR: ArgumentError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
Stacktrace:
[1] _empty_reduce_error()
@ Base .\reduce.jl:319
[2] mapreduce_empty(f::Function, op::Function, T::Type)
@ Base .\reduce.jl:321
[3] reduce_empty(op::Base.MappingRF{Xicor.var"#4#7"{Int64}, typeof(Base.add_sum)}, ::Type{Int64})
@ Base .\reduce.jl:358
[4] reduce_empty_iter
@ .\reduce.jl:381 [inlined]
[5] mapreduce_empty_iter(f::Function, op::Function, itr::Vector{Int64}, ItrEltype::Base.HasEltype)
@ Base .\reduce.jl:377
[6] _mapreduce
@ .\reduce.jl:429 [inlined]
[7] _mapreduce_dim
@ .\reducedim.jl:337 [inlined]
[8] mapreduce
@ .\reducedim.jl:329 [inlined]
[9] _sum
@ .\reducedim.jl:987 [inlined]
[10] sum
@ .\reducedim.jl:983 [inlined]
[11] xicor(X::Vector{Any}, Y::Vector{Any}; rank::typeof(StatsBase.denserank), noties::Bool)
@ Xicor C:\Users\wjhol\Documents\GitHub\Xicor.jl\src\Xicor.jl:27
[12] top-level scope
@ REPL[5]:1
https://github.com/stefftaelman/Xicor.jl/blob/f6c9155ef2efcda7e2ef8ea3a1e9b6f434a2cad8/src/Xicor.jl#L16
I propose a small check here that the input vectors have at least two elements each. The program returns a
NaN
statistic ifn=1
(with our without ties). Ifn=0
, then we get a meaningless statistic of 1.0 with no ties and a confusing error with ties.I recommend an explicit
ArgumentError
orDomainError
to explicitly tell the user that they cannot use this function on inputs withn<2
.