Using "√" with a vector


#1

I’m using Julia v0.6.0 and my old codes with √(x) where x is a Vector is giving warning as

julia> √(x)
WARNING: sqrt{T <: Number}(x::AbstractArray{T}) is deprecated, use sqrt.(x) instead.
Stacktrace:
 [1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
 [2] sqrt(::Array{Float64,1}) at ./deprecated.jl:57
 [3] eval(::Module, ::Any) at ./boot.jl:235
 [4] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:66
 [5] macro expansion at ./REPL.jl:97 [inlined]
 [6] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73
while loading no file, in expression starting on line 0

As expeceted, sqrt.(x) works without warning.

However using dot with squareroot symbol raises error

julia> √.(x)
ERROR: syntax: invalid identifier name "."

How can I use over a vector with new version of julia?


#2

(√).(x) and @. √(x) work, but I don’t completely understand why √.(x) isn’t parsed so that it does what you want.


#3

The is actually an infix operator (and not just a function name) so you can do things like √2. This means that it gets dotted like all the other operators — with a dot prefix.

julia> .√[1,2,3]
3-element Array{Float64,1}:
 1.0
 1.41421
 1.73205

julia> .![true,false,true]
3-element BitArray{1}:
 false
  true
 false

julia> .-[1,2,3]
3-element Array{Int64,1}:
 -1
 -2
 -3

#4

Operators can take their dot before the operator (this is inherited from binary operators (.+ .*), etc, so
.√(x) works I believe (as does .√x) . Still, there should be no problem with making the √.(x) syntax work. Do file an issue about it.


#5

See https://github.com/JuliaLang/julia/issues/23814.