Skip to content

Commit

Permalink
selectdim (#74)
Browse files Browse the repository at this point in the history
* selectdim

* bump version
  • Loading branch information
mcabbott authored and oxinabox committed Oct 14, 2019
1 parent a4ac17b commit 613e405
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NamedDims"
uuid = "356022a1-0364-5f58-8944-0da4b18d706f"
authors = ["Invenia Technical Computing Corporation"]
version = "0.2.7"
version = "0.2.8"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
4 changes: 4 additions & 0 deletions src/functions_dims.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ function Base.permutedims(nda::NamedDimsArray{L}, perm) where {L}
return NamedDimsArray{new_names}(permutedims(parent(nda), numerical_perm))
end

function Base.selectdim(nda::NamedDimsArray, s::Symbol, i)
return selectdim(nda, dim(nda, s), i)
end

for f in (
:(Base.transpose),
:(Base.adjoint),
Expand Down
14 changes: 12 additions & 2 deletions test/functions_dims.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using NamedDims: names
using Test

@testset "rename" begin
nda = NamedDimsArray{(:a, :b, :c, :d)}(ones(10,1,1,20))
nda = NamedDimsArray{(:a, :b, :c, :d)}(ones(10, 1, 1, 20))
new_nda = rename(nda, (:w, :x, :y, :z))

@test names(new_nda) === (:w, :x, :y, :z)
Expand All @@ -24,9 +24,19 @@ end
@test names(dropdims(nda; dims=(:b, :c))) == (:a, :d) == names(dropdims(nda; dims=(2, 3)))
end

@testset "selectdim" begin
nda = NamedDimsArray{(:r, :c)}(rand(2, 3))

@test selectdim(nda, :r, 1) == nda[r=1]
@test NamedDims.names(selectdim(nda, :r, 1)) == (:c,)
@test NamedDims.names(selectdim(nda, :r, 1:1)) == (:r, :c)

@test_throws ArgumentError selectdim(nda, :z, 4)
end

@testset "$f" for f in (adjoint, transpose, permutedims)
@testset "Vector $f" begin
ndv = NamedDimsArray{(:foo,)}([10,20,30])
ndv = NamedDimsArray{(:foo,)}([10, 20, 30])
@test f(ndv) == [10 20 30]
@test names(f(ndv)) == (:_, :foo)

Expand Down

2 comments on commit 613e405

@oxinabox
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/4341

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.8 -m "<description of version>" 613e4056d11a2f233ce569407a864b22e7dfa08d
git push origin v0.2.8

Please sign in to comment.