-
Notifications
You must be signed in to change notification settings - Fork 14
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
align: refine_names
+ permutedims
#96
Comments
Edit: Isn't what you're describing just a method of Earlier: I made an julia> using NamedPlus
julia> align(NamedDimsArray{(:A, :B)}(ones(3,5)), (:B, :A)) |> summary
"5×3 NamedDimsArray(::LinearAlgebra.Transpose{Float64,Array{Float64,2}}, (:B, :A))"
julia> align(NamedDimsArray{(:A, :B)}(ones(3,5)), (:NOPE, :A)) |> summary
"1×3×5 NamedDimsArray(TransmutedDimsArray(::Array{Float64,2}, (0, 1, 2)), (:_, :A, :B))"
# and with wildcards:
julia> align(NamedDimsArray{(:A, :_)}(ones(3,5)), (:B, :A)) |> summary
"1×3×5 NamedDimsArray(TransmutedDimsArray(::Array{Float64,2}, (0, 1, 2)), (:_, :A, :_))"
julia> align(NamedDimsArray{(:A, :_, :_)}(ones(1,3,5)), (:C, :B, :A)) |> summary
ERROR: input must have unique names, got (:A, :_, :_)
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] align(::NamedDimsArray{(:A, :_, :_),Float64,3,Array{Float64,3}}, ::Tuple{Symbol,Symbol,Symbol}) at /Users/me/.julia/dev/NamedPlus/src/permute.jl:27
[3] top-level scope at REPL[70]:1 I'm not precisely sure how wildcards in It always returns a view, often a slightly generalised (and faster) variant of |
A key difference is the following case:
On plain arrays it turrns them into |
OK. But it would be entirely natural that a |
We can't redefine It's no more a bug magnet then the current way |
Anytime an array has more than one wildcard things get confusing. |
Yes, good point about piracy. But IMO this still sounds like a variant of permutedims. I can see the value of guaranteeing that a matrix It seems to break the rule of this package that (1) operations not mentioning names should do exactly what they do on ordinary arrays, but propagate names, and error if mismatch, and (2) operations whose result depends on the given names only work on named arrays, and don't guess. It would be a huge bug-magnet if Anyway you will be shocked to hear that I had a branch playing with wildcards at some point... https://github.com/mcabbott/NamedDims.jl/blob/wild/test/name_core.jl#L90 . This tries to allow them in source or destination or both at once, but I think it got messy. |
I have been thinking about an option that i call
align
which combined
permutedims
withrefine_named
.With the following behavour:
This would generally replace most uses of
refine_names
as the thing you call if you are not sure if you are going to have names.It would mean as long as you followed convention of what each dimension meant when using general
AbstractArray
s all is well.But when you use
NamedDimsArray
s you can be more relaxed and get the order wrong, knowing it will fix it for you.Note: this is subtly different from PyTorch's
align_to
which only supports the
permutedims
like features, not therefine_names
features, and errors if applied to non-named Tensors.We could call it
align_and_refine
maybe instead.but we don't have a
align
as we basically usepermutedims
for that.Once we have this we can also add:
and maybe for matmul:
The text was updated successfully, but these errors were encountered: