You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After investigating the source of JuliaAI/ScientificTypes.jl#104 I came up with the following MWE which, it appears to me, points to a Julia bug.
I've no idea why a SentinelArray triggers the weird dispatch and the other AbstractArray examples don't.
So here's the unexpected (I dare say wrong) behaviour.
using SentinelArrays, SparseArrays
abstract type IncorrectDispatch endconst dict =Dict{Symbol,Function}()
# as `dict` is empty the contents of the `for` block shouldn't matter:functiontrait(X)::Symbolfor (name, f) in dict
iff(X)
return name
endendreturn:otherendscitype(X) =scitype(X, Val(trait(X)))
scitype(X, ::Val{:other}) = IncorrectDispatch
# overload for AbstractArrays:scitype(A::AbstractArray{T}, ::Val{:other}) where T ="correct dispatch"# three different AbstractArrays with same elements:
a = [1, 2, 3, 4]
b =sparse(a)
c =SentinelArray(a)
# The `trait` function appears to work:@asserttrait(a) ==:other@asserttrait(b) ==:other@asserttrait(c) ==:other# these should all return "correct dispatch" but the last one does not:
julia>scitype(a)
"correct dispatch"
julia>scitype(b)
"correct dispatch"
julia>scitype(c)
IncorrectDispatch
If, however, I change the contents of the for loop (which ought never to be executed) the wrong behaviour goes away:
functiontrait(X)::Symbolfor (name, f) in dict
iff(X)
return:otherendendreturn:otherend
julia>scitype(c)
"correct dispatch"
julia> Pkg.installed()
┌ Warning: Pkg.installed() is deprecated
└ @ Pkg /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/Pkg/src/Pkg.jl:531
Dict{String,VersionNumber} with 3 entries:"ScientificTypes"=>v"0.8.1"
julia>versioninfo()
Julia Version 1.4.2
Commit 44fa15b150* (2020-05-2318:35 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin18.7.0)
CPU:Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
WORD_SIZE:64
LIBM: libopenlibm
LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
JULIA_PATH =/Applications/Julia-1.4.app/Contents/Resources/julia/bin/julia
JULIA_NUM_THREADS =5
The text was updated successfully, but these errors were encountered:
SentinelArrays currently triggers some bad code paths in the type system (#36869). Probably worth waiting for that to be fixing before trying to reduce this much farther, since bad type system behavior can have all sorts of unexpected impacts.
After investigating the source of JuliaAI/ScientificTypes.jl#104 I came up with the following MWE which, it appears to me, points to a Julia bug.
I've no idea why a
SentinelArray
triggers the weird dispatch and the otherAbstractArray
examples don't.So here's the unexpected (I dare say wrong) behaviour.
If, however, I change the contents of the for loop (which ought never to be executed) the wrong behaviour goes away:
The text was updated successfully, but these errors were encountered: