diff return type

64 views
Skip to first unread message

i.cos...@me.com

unread,
Dec 29, 2014, 2:29:12 AM12/29/14
to julia...@googlegroups.com
Would someone be able to explain why `diff()` returns Any when its input is a vector of `Real` values but returns Float64 when its input is a vector of `Float64` values?

julia> diff(Real[1., 2.])

1-element Array{Any,1}:

 1.0


vs

julia> diff(Float64[1,2])

1-element Array{Float64,1}:

 1.0



julia> versioninfo()

Julia Version 0.3.3

Commit b24213b* (2014-11-23 20:19 UTC)

Platform Info:

  System: Darwin (x86_64-apple-darwin14.1.0)

  CPU: Intel(R) Core(TM) i5-4260U CPU @ 1.40GHz

  WORD_SIZE: 64

  BLAS: libopenblas (DYNAMIC_ARCH NO_AFFINITY Haswell)

  LAPACK: libopenblas

  LIBM: libopenlibm

  LLVM: libLLVM-3.3


Thanks

ele...@gmail.com

unread,
Dec 29, 2014, 2:56:54 AM12/29/14
to julia...@googlegroups.com
Because diff is computed with a comprehension which is typed by inference.  Thats ok for a concrete type like Float64, but when faced with an abstract type like Real, inference currently says its all too hard and goes for Any.  See also https://github.com/JuliaLang/julia/issues/7258.

Cheers
Lex

i.cos...@me.com

unread,
Dec 29, 2014, 3:58:25 AM12/29/14
to julia...@googlegroups.com
Thanks makes sense.
Reply all
Reply to author
Forward
0 new messages