Mercurial > repos > public > sbplib_julia
comparison test/LazyTensors/tuple_manipulation_test.jl @ 1858:4a9be96f2569 feature/documenter_logo
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sun, 12 Jan 2025 21:18:44 +0100 |
parents | 471a948cd2b2 |
children |
comparison
equal
deleted
inserted
replaced
1857:ffde7dad9da5 | 1858:4a9be96f2569 |
---|---|
1 using Test | |
2 using Diffinitive.LazyTensors | |
3 | |
4 @testset "split_index" begin | |
5 @test LazyTensors.split_index(2,1,2,2, 1,2,3,4,5,6) == ((1,2,:,5,6),(3,4)) | |
6 @test LazyTensors.split_index(2,3,2,2, 1,2,3,4,5,6) == ((1,2,:,:,:,5,6),(3,4)) | |
7 @test LazyTensors.split_index(3,1,1,2, 1,2,3,4,5,6) == ((1,2,3,:,5,6),(4,)) | |
8 @test LazyTensors.split_index(3,2,1,2, 1,2,3,4,5,6) == ((1,2,3,:,:,5,6),(4,)) | |
9 @test LazyTensors.split_index(1,1,2,3, 1,2,3,4,5,6) == ((1,:,4,5,6),(2,3)) | |
10 @test LazyTensors.split_index(1,2,2,3, 1,2,3,4,5,6) == ((1,:,:,4,5,6),(2,3)) | |
11 | |
12 @test LazyTensors.split_index(0,1,3,3, 1,2,3,4,5,6) == ((:,4,5,6),(1,2,3)) | |
13 @test LazyTensors.split_index(3,1,3,0, 1,2,3,4,5,6) == ((1,2,3,:),(4,5,6)) | |
14 | |
15 split_index_static(::Val{dim_before}, | |
16 ::Val{dim_view}, | |
17 ::Val{dim_index}, | |
18 ::Val{dim_after}, I...) where {dim_before,dim_view,dim_index,dim_after} = | |
19 LazyTensors.split_index(dim_before, dim_view, dim_index, dim_after, I...) | |
20 @inferred split_index_static(Val(2),Val(3),Val(2),Val(2),1,2,3,2,2,4) | |
21 end | |
22 | |
23 @testset "split_tuple" begin | |
24 @testset "general" begin | |
25 @test LazyTensors.split_tuple((),()) == () | |
26 @test LazyTensors.split_tuple((),(0,)) == ((),) | |
27 @test LazyTensors.split_tuple((1,), (1,)) == tuple((1,)) | |
28 @test LazyTensors.split_tuple((1,2), (1,1)) == tuple((1,),(2,)) | |
29 @test LazyTensors.split_tuple((1,2), (0,1,1)) == tuple((),(1,),(2,)) | |
30 @test LazyTensors.split_tuple((1,2), (1,0,1)) == tuple((1,),(),(2,)) | |
31 @test LazyTensors.split_tuple((1,2), (1,1,0)) == tuple((1,),(2,),()) | |
32 @test LazyTensors.split_tuple((1,2,3,4), (2,0,1,1)) == tuple((1,2),(),(3,),(4,)) | |
33 | |
34 err_msg = "length(t) must equal sum(szs)" | |
35 @test_throws ArgumentError(err_msg) LazyTensors.split_tuple((), (2,)) | |
36 @test_throws ArgumentError(err_msg) LazyTensors.split_tuple((2,), ()) | |
37 @test_throws ArgumentError(err_msg) LazyTensors.split_tuple((1,), (2,)) | |
38 @test_throws ArgumentError(err_msg) LazyTensors.split_tuple((1,2), (1,2)) | |
39 @test_throws ArgumentError(err_msg) LazyTensors.split_tuple((1,2), (1)) | |
40 | |
41 split_tuple_static(t, ::Val{SZS}) where {SZS} = LazyTensors.split_tuple(t,SZS) | |
42 @inferred split_tuple_static((1,2,3,4,5,6), Val((3,1,2))) | |
43 @inferred split_tuple_static((1,2,3,4),Val((3,1))) | |
44 @inferred split_tuple_static((1,2,true,4),Val((3,1))) | |
45 @inferred split_tuple_static((1,2,3,4,5,6),Val((3,2,1))) | |
46 @inferred split_tuple_static((1,true,3),Val((1,1,1))) | |
47 end | |
48 end | |
49 | |
50 @testset "sizes_to_ranges" begin | |
51 @test LazyTensors.sizes_to_ranges((1,)) == (1:1,) | |
52 @test LazyTensors.sizes_to_ranges((2,)) == (1:2,) | |
53 @test LazyTensors.sizes_to_ranges((2,3)) == (1:2,3:5) | |
54 @test LazyTensors.sizes_to_ranges((3,2,4)) == (1:3,4:5,6:9) | |
55 @test LazyTensors.sizes_to_ranges((0,2)) == (1:0,1:2) | |
56 @test LazyTensors.sizes_to_ranges((2,0)) == (1:2,2:1) | |
57 @test LazyTensors.sizes_to_ranges((2,0,3)) == (1:2,2:1,3:5) | |
58 end | |
59 | |
60 @testset "concatenate_tuples" begin | |
61 @test LazyTensors.concatenate_tuples(()) == () | |
62 @test LazyTensors.concatenate_tuples((1,)) == (1,) | |
63 @test LazyTensors.concatenate_tuples((1,), ()) == (1,) | |
64 @test LazyTensors.concatenate_tuples((),(1,)) == (1,) | |
65 @test LazyTensors.concatenate_tuples((1,2,3),(4,5)) == (1,2,3,4,5) | |
66 @test LazyTensors.concatenate_tuples((1,2,3),(4,5),(6,7)) == (1,2,3,4,5,6,7) | |
67 end | |
68 | |
69 @testset "left_pad_tuple" begin | |
70 @test LazyTensors.left_pad_tuple((1,2), 0, 2) == (1,2) | |
71 @test LazyTensors.left_pad_tuple((1,2), 0, 3) == (0,1,2) | |
72 @test LazyTensors.left_pad_tuple((3,2), 1, 6) == (1,1,1,1,3,2) | |
73 err_msg = "Can't pad tuple of length 2 to 0 elements" | |
74 @test_throws DomainError(0, err_msg) LazyTensors.left_pad_tuple((1,2), 0, 0) == (1,2) | |
75 end | |
76 | |
77 @testset "right_pad_tuple" begin | |
78 @test LazyTensors.right_pad_tuple((1,2), 0, 2) == (1,2) | |
79 @test LazyTensors.right_pad_tuple((1,2), 0, 3) == (1,2,0) | |
80 @test LazyTensors.right_pad_tuple((3,2), 1, 6) == (3,2,1,1,1,1) | |
81 err_msg = "Can't pad tuple of length 2 to 0 elements" | |
82 @test_throws DomainError(0,err_msg) LazyTensors.right_pad_tuple((1,2), 0, 0) == (1,2) | |
83 end |