Basic functions with array


#1

Last time I was using this was 0.5 or so, but when I want to calculate
x=1:1000
y=cos(x)
it complains about
ERROR: MethodError: no method matching cos(::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}})
Closest candidates are:
cos(::BigFloat) at mpfr.jl:683
cos(::Missing) at math.jl:1056
cos(::Complex{Float16}) at math.jl:1005

Stacktrace:
[1] top-level scope at none:0

Is that not inteded anymore to use arrays on basic functions?


#2

Use 0.7 to upgrade old code — this will give you deprecation warnings for things that are removed from 1.0. If you are upgrading from Julia 0.5, you first need to upgrade to 0.6 (which is where cos(array) was deprecated) to get the deprecations, then upgrade to 0.7, then to 1.0.

Applying functions to arrays is now done with “dot calls” like cos.(1:1000). This is much more general (it works for any function) and has other benefits as well.


#3

Thanks for your reply. But this new syntax on functions as cos.(x) does not affect the old array dot multiplication like (cos.(x)).*cot.(x)./sin.(x)./x in any way or?


#4

It does, in that now .* is no longer something special but just the broadcasted use of *. This has benefits for both expressiveness and efficiency and is generally excellent. Please read the article that @stevengj linked, which explains all of this in detail.