Skip to content
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

[Speculative] Recursively look for names inside wrapper types #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/wrapper_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,22 @@ Base.parent(x::NamedDimsArray) = x.data

Returns a tuple of containing the names of all the dimensions of the array `A`.
"""
names(::Type{<:NamedDimsArray{L}}) where L = L
names(::Type{<:AbstractArray{T, N}}) where {T,N} = ntuple(_->:_, N)
names(x::T) where T<:AbstractArray = names(T)
names(x::NamedDimsArray{L}}) where L = L
function names(x::T) where T<:AbstractArray
inner = parent(x)
# things that are not wrapper arrays are there own parents,
# so at that point we can give up looking for names
# also we have no way to deal with inner arrays of different dimensions, even if they do have names
# so give up then too
Copy link
Contributor

@nickrobinson251 nickrobinson251 Apr 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe helpful to add an example (cos it's a bit of a weird case)? e.g.

also parent arrays can have a different number of dimensions, e.g. parent of a Diagonal is a Vector
we have no way to deal with the names in this case so give up then too

if x === inner || ndims(inner) != ndims(x)
return default_names(x)
else
# recurse to look for names on what was wrapped
return names(inner)
end
end
names(x::Array{T,N}) where {T,N} = default_names(x) # shortcut of the above
default_names(x::AbstractArray{T, N}) where {T,N} = ntuple(_->:_, N)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these really the names of an un-named thing?

Aren't these the names of something which has names, they're just unknown/wildcards

The names of an unnamed thing is nothing or maybe ntuple(i -> nothing, N)?


dim(a::NamedDimsArray{L}, name) where L = dim(L, name)

Expand Down