Open
Description
Hey,
I'm trying to figure out how we could use Tullio to generalize some n-dimensional functions.
Let's say I've got a n-dimensional array and I want to use Tullio for that. At the moment I need to treat dimensions differently.
using Tullio
using Random
Random.seed!(42)
function spatial_grad_square_1D(arr)
resi = let
@tullio resi = abs2(arr[i + 1] - arr[i - 1])
end
return resi
end
function spatial_grad_square_2D(arr)
resi = let
@tullio resi = abs2(arr[i + 1, j] - arr[i - 1, j])
end
resj = let
@tullio resj = abs2(arr[i, j + 1] - arr[i, j - 1])
end
return resi + resj
end
arr_1D = randn((10))
arr_2D = randn((10, 10))
spatial_grad_square_1D(arr_1D)
spatial_grad_square_2D(arr_2D)
Do you have any hints on how to achieve this in a more elegant way? Using the Julia metaprogramming documentation I couldn't figure it out 😞
Thanks,
Felix
Metadata
Metadata
Assignees
Labels
No labels