From 6702eb8cc660c6bbd856f59cd8d42c7623def22e Mon Sep 17 00:00:00 2001 From: cossio Date: Tue, 12 May 2020 01:21:25 +0200 Subject: [PATCH] ntuple(Val(N)) -> tuplen --- src/util.jl | 6 +++--- test/util.jl | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/util.jl b/src/util.jl index 99926fd..c73eb83 100644 --- a/src/util.jl +++ b/src/util.jl @@ -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 @@ -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)) diff --git a/test/util.jl b/test/util.jl index dd7d8c4..36f994b 100644 --- a/test/util.jl +++ b/test/util.jl @@ -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) @@ -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