@@ -15,7 +15,7 @@ function one_to_n(a::Array)
15
15
end
16
16
one_to_n (s:: Tuple , :: Type{FT} ) where {FT} = one_to_n (zeros (FT, s... ))
17
17
ncomponents (:: Type{FT} , :: Type{S} ) where {FT, S} = div (sizeof (S), sizeof (FT))
18
- field_dim_to_one (s, dim) = Tuple (map (j-> j == dim ? 1 : s[j], 1 : length (s)))
18
+ field_dim_to_one (s, dim) = Tuple (map (j -> j == dim ? 1 : s[j], 1 : length (s)))
19
19
CI (s) = CartesianIndices (map (ξ -> Base. OneTo (ξ), s))
20
20
21
21
struct Foo{T}
72
72
@testset " get_struct - VIJFH indexing" begin
73
73
FT = Float64
74
74
S = Foo{FT}
75
- s = (2 , 2 , 2 , 2 , 2 )
76
- a = one_to_n (s, FT)
75
+ s_array = (2 , 2 , 2 , 2 , 2 )
76
+ s = field_dim_to_one (s_array, 4 )
77
+ a = one_to_n (s_array, FT)
77
78
@test ncomponents (FT, S) == 2
78
79
79
80
@test get_struct (a, S, Val (4 ), CI (s)[1 ]) == Foo {FT} (1.0 , 9.0 )
84
85
@test get_struct (a, S, Val (4 ), CI (s)[6 ]) == Foo {FT} (6.0 , 14.0 )
85
86
@test get_struct (a, S, Val (4 ), CI (s)[7 ]) == Foo {FT} (7.0 , 15.0 )
86
87
@test get_struct (a, S, Val (4 ), CI (s)[8 ]) == Foo {FT} (8.0 , 16.0 )
87
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[9 ])
88
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[10 ])
89
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[11 ])
90
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[12 ])
91
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[13 ])
92
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[14 ])
93
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[15 ])
94
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[16 ])
95
- @test get_struct (a, S, Val (4 ), CI (s)[17 ]) == Foo {FT} (17.0 , 25.0 )
96
- @test get_struct (a, S, Val (4 ), CI (s)[18 ]) == Foo {FT} (18.0 , 26.0 )
97
- @test get_struct (a, S, Val (4 ), CI (s)[19 ]) == Foo {FT} (19.0 , 27.0 )
98
- @test get_struct (a, S, Val (4 ), CI (s)[20 ]) == Foo {FT} (20.0 , 28.0 )
99
- @test get_struct (a, S, Val (4 ), CI (s)[21 ]) == Foo {FT} (21.0 , 29.0 )
100
- @test get_struct (a, S, Val (4 ), CI (s)[22 ]) == Foo {FT} (22.0 , 30.0 )
101
- @test get_struct (a, S, Val (4 ), CI (s)[23 ]) == Foo {FT} (23.0 , 31.0 )
102
- @test get_struct (a, S, Val (4 ), CI (s)[24 ]) == Foo {FT} (24.0 , 32.0 )
103
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[25 ])
104
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[26 ])
105
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[27 ])
106
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[28 ])
107
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[29 ])
108
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[30 ])
109
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[31 ])
110
- @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[32 ])
88
+ @test get_struct (a, S, Val (4 ), CI (s)[9 ]) == Foo {FT} (17.0 , 25.0 )
89
+ @test get_struct (a, S, Val (4 ), CI (s)[10 ]) == Foo {FT} (18.0 , 26.0 )
90
+ @test get_struct (a, S, Val (4 ), CI (s)[11 ]) == Foo {FT} (19.0 , 27.0 )
91
+ @test get_struct (a, S, Val (4 ), CI (s)[12 ]) == Foo {FT} (20.0 , 28.0 )
92
+ @test get_struct (a, S, Val (4 ), CI (s)[13 ]) == Foo {FT} (21.0 , 29.0 )
93
+ @test get_struct (a, S, Val (4 ), CI (s)[14 ]) == Foo {FT} (22.0 , 30.0 )
94
+ @test get_struct (a, S, Val (4 ), CI (s)[15 ]) == Foo {FT} (23.0 , 31.0 )
95
+ @test get_struct (a, S, Val (4 ), CI (s)[16 ]) == Foo {FT} (24.0 , 32.0 )
96
+ @test_throws BoundsError get_struct (a, S, Val (4 ), CI (s)[17 ])
111
97
end
112
98
113
99
# TODO : add set_struct!
0 commit comments