Mercurial > repos > public > sbplib_julia
changeset 625:1c512e796c6d feature/volume_and_boundary_operators
Allow split_tuple to split tuples containing different types.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 31 Dec 2020 08:10:56 +0100 |
parents | a85db383484f |
children | 8581610da4f1 |
files | src/LazyTensors/lazy_tensor_operations.jl test/testLazyTensors.jl |
diffstat | 2 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/LazyTensors/lazy_tensor_operations.jl Mon Dec 21 23:12:37 2020 +0100 +++ b/src/LazyTensors/lazy_tensor_operations.jl Thu Dec 31 08:10:56 2020 +0100 @@ -331,7 +331,7 @@ split_tuple((1,2,3,4),Val(3)) -> (1,2,3), (4,) ``` """ -function split_tuple(t::NTuple{N},::Val{M}) where {N,M} +function split_tuple(t::NTuple{N,Any},::Val{M}) where {N,M} return slice_tuple(t,Val(1), Val(M)), slice_tuple(t,Val(M+1), Val(N)) end @@ -341,7 +341,7 @@ Same as `split_tuple(t::NTuple{N},::Val{M})` but splits the tuple in three parts. With the first two parts having lenght `M` and `K`. """ -function split_tuple(t::NTuple{N},::Val{M},::Val{K}) where {N,M,K} +function split_tuple(t::NTuple{N,Any},::Val{M},::Val{K}) where {N,M,K} p1, tail = split_tuple(t, Val(M)) p2, p3 = split_tuple(tail, Val(K)) return p1,p2,p3
--- a/test/testLazyTensors.jl Mon Dec 21 23:12:37 2020 +0100 +++ b/test/testLazyTensors.jl Thu Dec 31 08:10:56 2020 +0100 @@ -487,17 +487,22 @@ @test LazyTensors.split_tuple((1,2,3,4),Val(3)) == ((1,2,3),(4,)) @test LazyTensors.split_tuple((1,2,3,4),Val(4)) == ((1,2,3,4),()) + @test LazyTensors.split_tuple((1,2,true,4),Val(3)) == ((1,2,true),(4,)) + @inferred LazyTensors.split_tuple((1,2,3,4),Val(3)) + @inferred LazyTensors.split_tuple((1,2,true,4),Val(3)) end @testset "3 parts" begin @test LazyTensors.split_tuple((),Val(0),Val(0)) == ((),(),()) @test LazyTensors.split_tuple((1,2,3),Val(1), Val(1)) == ((1,),(2,),(3,)) + @test LazyTensors.split_tuple((1,true,3),Val(1), Val(1)) == ((1,),(true,),(3,)) @test LazyTensors.split_tuple((1,2,3,4,5,6),Val(1),Val(2)) == ((1,),(2,3),(4,5,6)) @test LazyTensors.split_tuple((1,2,3,4,5,6),Val(3),Val(2)) == ((1,2,3),(4,5),(6,)) @inferred LazyTensors.split_tuple((1,2,3,4,5,6),Val(3),Val(2)) + @inferred LazyTensors.split_tuple((1,true,3),Val(1), Val(1)) end end