Conversation
|
Another approach would be, if there are any @generated function f_outer(A, B)
DA, DB = ndims(A)-1, ndims(B)-1
DC = max(DA, DB)
bs = [Symbol(:b, i) for i in 1:DC]
:(@tullio C[i,j,$(bs...)] := A[i,k,$(bs[1:DA]...)] * B[k,j,$(bs[1:DB]...)])
end
f_outer(rand(2,2), rand(2,2))
# ERROR: LoadError: eval cannot be used in a generated functionSo I can't do this until I find a way to avoid An even simpler approach would be to allow |
|
Note to self about |
|
Further note: that won't work, because What might work is something more like this. Write the body of the function in one generated function, and call that outside the quote of a second: Of course right now The low-tech way, however, is just to allow trivial indices. For |
Sometimes it would be neat if the same function could allow for several dimensionalities. Perhaps this is written:
which accepts
f(Matrix, Matrix)::Matrixas usual, but alsof(Array3, Array3)::Array3with one more dimension. And ideally alsof(Array4, Matrix)::Array4with varying numbers of dimensions, obeying broadcasting rules.This is an implementation which adds extra loops over one
CartesianIndex{N}, using clever things fromBase.Broadcastto work out the appropriate ranges. It adds a bit more complication than I pictured before starting!First working version. Multi-threading is disabled, no idea whether gradients will work.