@@ -80,15 +80,47 @@ v = AxisArray(collect(.1:.1:10.0), .1:.1:10.0)
80
80
@test v[:] == v. data[:] == v[Axis {:row} (:)]
81
81
@test v[3 : 8 ] == v. data[3 : 8 ] == v[ClosedInterval (.25 ,.85 )] == v[Axis {:row} (3 : 8 )] == v[Axis {:row} (ClosedInterval (.22 ,.88 ))]
82
82
83
- # Test repeated intervals
84
- A = AxisArray ([1 : 100 - 1 : - 1 : - 100 ], .1 : .1 : 10.0 , [:c1 , :c2 ])
85
- @test A[2.0 .. 3.0 , :] == A[atindex (- 0.5 .. 0.5 , 25 ), :] == [20 : 30 - 20 : - 1 : - 30 ]
86
- @test A[2.0 .. 3.0 , [:c1 ,:c2 ]] == A[atindex (- 0.5 .. 0.5 , 25 ), [:c1 , :c2 ]] == [20 : 30 - 20 : - 1 : - 30 ]
87
- @test A[2.0 .. 3.0 , :c1 ] == A[atindex (- 0.5 .. 0.5 , 25 ), :c1 ] == collect (20 : 30 )
88
- @test A[atindex (- 0.5 .. 0.5 , 25 ), :c1 ] == collect (20 : 30 )
89
- @test A[atindex (- 0.5 .. 0.5 , [25 , 35 ]), :c1 ] == [20 : 30 30 : 40 ]
90
- @test_throws BoundsError A[atindex (- 0.5 .. 0.5 , 5 ), :c1 ]
91
- @test_throws BoundsError A[atindex (- 0.5 .. 0.5 , [5 , 15 , 25 ]), :]
83
+ # Test repeated intervals, for different range types
84
+
85
+ # First, since integers mean "location" rather than value, we have to
86
+ # create a number type from which we build a StepRange but which is
87
+ # not an Int.
88
+ module IL # put in a module so this file can be re-run
89
+ immutable IntLike <: Number
90
+ val:: Int
91
+ end
92
+ Base. one (x:: IntLike ) = IntLike (0 )
93
+ Base. zero (x:: IntLike ) = IntLike (0 )
94
+ Base. isless (x:: IntLike , y:: IntLike ) = isless (x. val, y. val)
95
+ Base.:+ (x:: IntLike , y:: IntLike ) = IntLike (x. val+ y. val)
96
+ Base.:- (x:: IntLike , y:: IntLike ) = IntLike (x. val- y. val)
97
+ Base.:/ (x:: IntLike , y:: IntLike ) = x. val / y. val
98
+ Base. rem (x:: IntLike , y:: IntLike ) = IntLike (rem (x. val, y. val))
99
+ Base. div (x:: IntLike , y:: IntLike ) = div (x. val, y. val)
100
+ Base.:* (x:: IntLike , y:: Int ) = IntLike (x. val * y)
101
+ Base.:* (x:: Int , y:: IntLike ) = y* x
102
+ Base.:/ (x:: IntLike , y:: Int ) = IntLike (x. val / y)
103
+ Base. promote_rule (:: Type{IntLike} , :: Type{Int} ) = Int
104
+ Base. convert (:: Type{Int} , x:: IntLike ) = x. val
105
+ using AxisArrays
106
+ AxisArrays. axistrait (:: AbstractVector{IntLike} ) = AxisArrays. Dimensional
107
+ end
108
+
109
+ for (r, Irel) in ((0.1 : 0.1 : 10.0 , - 0.5 .. 0.5 ), # FloatRange
110
+ (IL. IntLike (1 ): IL. IntLike (1 ): IL. IntLike (100 ),
111
+ IL. IntLike (- 5 ).. IL. IntLike (5 ))) # StepRange
112
+ Iabs = r[20 ]. . r[30 ]
113
+ A = AxisArray ([1 : 100 - 1 : - 1 : - 100 ], r, [:c1 , :c2 ])
114
+ @test A[Iabs, :] == A[atindex (Irel, 25 ), :] == [20 : 30 - 20 : - 1 : - 30 ]
115
+ @test A[Iabs, :] == A[r[25 ]+ Irel, :] == [20 : 30 - 20 : - 1 : - 30 ]
116
+ @test A[Iabs, [:c1 ,:c2 ]] == A[atindex (Irel, 25 ), [:c1 , :c2 ]] == [20 : 30 - 20 : - 1 : - 30 ]
117
+ @test A[Iabs, :c1 ] == A[atindex (Irel, 25 ), :c1 ] == collect (20 : 30 )
118
+ @test A[atindex (Irel, 25 ), :c1 ] == collect (20 : 30 )
119
+ @test A[atindex (Irel, [25 , 35 ]), :c1 ] == [20 : 30 30 : 40 ]
120
+ @test A[r[[25 , 35 ]] + Irel, :c1 ] == [20 : 30 30 : 40 ]
121
+ @test_throws BoundsError A[atindex (Irel, 5 ), :c1 ]
122
+ @test_throws BoundsError A[atindex (Irel, [5 , 15 , 25 ]), :]
123
+ end
92
124
93
125
# Indexing with CartesianIndex{0}
94
126
A = AxisArray (reshape (1 : 15 , 3 , 5 ), :x , :y )
0 commit comments