Skip to content

Commit

Permalink
ntuple(Val(N)) -> tuplen
Browse files Browse the repository at this point in the history
  • Loading branch information
cossio committed May 11, 2020
1 parent 1e6e20d commit 6702eb8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end
argmax of `A` over its first `N` dimensions and drops them. By default `N = 1`.
"""
function argmaxdropfirst(A::AbstractArray, ::Val{N} = Val(1)) where {N}
dims = ntuple(Val(N))
dims = tuplen(Val(N))
argmaxdrop(A; dims=dims)
end

Expand All @@ -35,8 +35,8 @@ function columns(A::AbstractArray)
end

"""
ntuple(Val(N))
tuplen(Val(N))
Constructs the tuple `(1, 2, ..., N)`.
"""
@generated Base.ntuple(::Val{N}) where {N} = ntuple(identity, Val(N))
@generated tuplen(::Val{N}) where {N} = ntuple(identity, Val(N))
7 changes: 6 additions & 1 deletion test/util.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using OneHot, Test, Random
using OneHot: argmaxdrop, argmaxdropfirst
using OneHot: argmaxdrop, argmaxdropfirst, tuplen

@testset "argmaxdrop" begin
@inferred argmaxdrop(randn(3,2,4); dims=2)
Expand All @@ -16,3 +16,8 @@ end
i = argmaxdropfirst(A)
@test A[i] == [3, 4]
end

@testset "tuplen" begin
@inferred tuplen(Val(5))
@test tuplen(Val(5)) == (1,2,3,4,5)
end

2 comments on commit 6702eb8

@cossio
Copy link
Owner

@cossio cossio commented on 6702eb8 May 11, 2020

Choose a reason for hiding this comment

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

@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 updated: JuliaRegistries/General/14441

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 the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" 6702eb8cc660c6bbd856f59cd8d42c7623def22e
git push origin v0.1.0

Please sign in to comment.