dot syntax in pyjulia

Hello, I have a question about using dot syntax in python. In trying to write a broadcast-able function in julia that I can call from python, i have found it convenient to do the following:

export func

function func(x::Float64, y::Float64)
    <body>
end

func(x::Union{Float64, Array{Float64}}, y::Union{Float64, Array{Float64}})=func.(x, y)

I may be going off the rails here, but otherwise I’m not sure how to make broadcasting available on the python-side. Any thoughts would be much appreciated.

I would just do:

export func

function scalarfunc(x, y)
    <body>
end

func(x, y) = scalarfunc.(x, y)

Broadcasting works just fine on scalars and adds no overhead, so the “broadcasted” function can be completely separate from the scalar kernel.

so, do i lose anything by not specifying type in the function signature? that’s what worried me about this.

Nope! Method signatures are really only required if you specifically want to depend upon the internal structure of an argument or a particular behavior — so you can dispatch to it over a different (often more general) implementation. The performance of methods written as f(x::Float64) = ... vs. f(x::Number) = ... vs. f(x) = ... will be identical.

1 Like

thank you!