Broadcasting performance

Yes - sorry it took me a while to see this.

If you define your function as:

f(x) = @tturbo sin(x)cos(x)tan(x)exp(x)sin(x)cos(x)tan(x)exp(x)

Then, to work with TidierData, all you need to do is:

@chain begin
    DataFrame(X=X)   
    @mutate X2 = f(X)
end

For awareness, the expression X2 = f(X) gets vectorized to X2 = f.(X) by TidierData before it is evaluated. Vectorization here is appropriate because f(x) is designed to operate on scalars. I haven’t benchmarked this, but it is totally doable.

If you want to keep the function f(x) defined as-is without including @tturbo in its definition, then another way to use this within TidierData is the following:

@chain begin
    DataFrame(X=X)
    @mutate(across(X, x -> @tturbo f.(x)))
end
2 Likes