-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Magic Dots #4
base: master
Are you sure you want to change the base?
Magic Dots #4
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 function So 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)::Matrix
as usual, but alsof(Array3, Array3)::Array3
with one more dimension. And ideally alsof(Array4, Matrix)::Array4
with varying numbers of dimensions, obeying broadcasting rules.This is an implementation which adds extra loops over one
CartesianIndex{N}
, using clever things fromBase.Broadcast
to 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.