Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AxisKeys"
uuid = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
license = "MIT"
version = "0.1.5"
version = "0.1.6"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think 0.1.5 was ever tagged?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Oh I always mess that up, thanks, fixed now.


[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand All @@ -20,7 +20,7 @@ BenchmarkTools = "0.5"
IntervalSets = "0.5.1"
InvertedIndices = "1.0"
LazyStack = "0.0.7, 0.0.8"
NamedDims = "0.2.21"
NamedDims = "0.2.27"
OffsetArrays = "0.10, 0.11, 1.0"
Tables = "0.2, 1"
julia = "1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AxisKeys.jl

[![Build Status](https://travis-ci.org/mcabbott/AxisKeys.jl.svg?branch=master)](https://travis-ci.org/mcabbott/AxisKeys.jl)
[![Build Status](https://travis-ci.org/mcabbott/AxisKeys.jl.svg?branch=master)](https://travis-ci.com/mcabbott/AxisKeys.jl)

<!--<img src="docs/readmefigure.png" alt="block picture" width="400" align="right">-->

Expand Down
25 changes: 19 additions & 6 deletions src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ end

for (T, S) in [(:KeyedVecOrMat, :KeyedVecOrMat), # KeyedArray gives ambiguities
(:KeyedVecOrMat, :AbstractVecOrMat), (:AbstractVecOrMat, :KeyedVecOrMat),
(:NdaKaVoM, :NdaKaVoM), # These are needed because hcat(NamedDimsArray...) relies on similar()
(:NdaKaVoM, :NdaKaVoM),
(:NdaKaVoM, :KeyedVecOrMat), (:KeyedVecOrMat, :NdaKaVoM),
(:NdaKaVoM, :AbstractVecOrMat), (:AbstractVecOrMat, :NdaKaVoM) ]
(:NdaKaVoM, :AbstractVecOrMat), (:AbstractVecOrMat, :NdaKaVoM),
]

@eval function Base.vcat(A::$T, B::$S, Cs::AbstractVecOrMat...)
data = vcat(keyless(A), keyless(B), keyless.(Cs)...)
Expand All @@ -118,13 +119,23 @@ for (T, S) in [ (:KeyedArray, :KeyedArray),
(:KeyedArray, :NamedDimsArray), (:NamedDimsArray, :KeyedArray),
(:NdaKa, :NdaKa),
(:NdaKa, :KeyedArray), (:KeyedArray, :NdaKa),
(:NdaKa, :AbstractArray), (:AbstractArray, :NdaKa) ]
(:NdaKa, :AbstractArray), (:AbstractArray, :NdaKa),
]

@eval function Base.cat(A::$T, B::$S, Cs::AbstractArray...; dims)
# numerical_dims = hasnames(A) || hasnames(B) ? ... todo!
data = cat(keyless(A), keyless(B), keyless.(Cs)...; dims=dims)
numerical_dims, data = if any(hasnames.((A, B, Cs...)))
old_names = NamedDims.unify_names_longest(dimnames(A), dimnames(B), dimnames.(Cs)...)
new_names = NamedDims.expand_dimnames(old_names, dims)
α = NamedDims.dim(new_names, dims)
β = cat(keyless(A), keyless(B), keyless.(Cs)...; dims=dims)
α, β
else
α = val_strip(dims)
β = cat(keyless(A), keyless(B), keyless.(Cs)...; dims=numerical_dims)
α, β
end
new_keys = ntuple(ndims(data)) do d
if d in dims
if d in numerical_dims
key_vcat(keys_or_axes(A,d), keys_or_axes(B,d), keys_or_axes.(Cs,d)...)
else
unify_one(keys_or_axes(A,d), keys_or_axes(B,d), keys_or_axes.(Cs,d)...)
Expand All @@ -134,6 +145,8 @@ for (T, S) in [ (:KeyedArray, :KeyedArray),
end

end
val_strip(dims::Val{d}) where {d} = d
val_strip(dims) = dims
key_vcat(a::AbstractVector, b::AbstractVector) = vcat(a,b)
key_vcat(a::Base.OneTo, b::Base.OneTo) = Base.OneTo(a.stop + b.stop)
key_vcat(a,b,cs...) = key_vcat(key_vcat(a,b),cs...)
Expand Down
4 changes: 3 additions & 1 deletion src/names.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ using NamedDims

NdaKa{L,T,N} = NamedDimsArray{L,T,N,<:KeyedArray{T,N}}
KaNda{L,T,N} = KeyedArray{T,N,<:NamedDimsArray{L,T,N}}
NdaKaVoM{L,T,N} = NamedDimsArray{L,T,N,<:KeyedVecOrMat}

NdaKaVoM{L,T} = Union{NamedDimsArray{L,T,1,<:KeyedArray}, NamedDimsArray{L,T,2,<:KeyedArray}}
# NdaKaV{L,T} = NamedDimsArray{L,T,1,<:KeyedArray{T,1}}

# NamedDims now uses dimnames, which behaves like size(A,d), axes(A,d) etc.

Expand Down
7 changes: 6 additions & 1 deletion test/_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ M = wrapdims(rand(Int8, 3,4), r='a':'c', c=2:5)
MN = NamedDimsArray(M.data.data, r='a':'c', c=2:5)
V = wrapdims(rand(1:99, 10), v=10:10:100)
VN = NamedDimsArray(V.data.data, v=10:10:100)
A3 = wrapdims(rand(Int8, 3,4,2), r='a':'c', c=2:5, p=[10.0, 20.0])

@testset "dims" begin

Expand Down Expand Up @@ -151,7 +152,11 @@ end
@test axiskeys(cat(MN,MN, dims=3)) == ('a':1:'c', 2:5, Base.OneTo(2))
@test axiskeys(cat(M,MN, dims=3)) == ('a':1:'c', 2:5, Base.OneTo(2))

@test_broken axiskeys(cat(M,M, dims=:r)) # doesn't work in NamedDims either
@test axiskeys(cat(M,M, dims=:z)) == ('a':1:'c', 2:5, Base.OneTo(2))
@test dimnames(cat(M,M, dims=:z)) == (:r, :c, :z)

@test axiskeys(cat(A3, A3, dims=:p)) == ('a':1:'c', 2:5, [10.0, 20.0, 10.0, 20.0])
@test axiskeys(hcat(A3, A3)) == ('a':1:'c', vcat(2:5,2:5), [10.0, 20.0])

end
@testset "matmul" begin
Expand Down