Skip to content

Commit 6c9eed9

Browse files
authored
Use step(r) instead of r.step... (#77)
* Use `step(r)` instead of r.step... when constructing StepRangeLen objects. This came up when using the new LinSpace objects -- their r.step is a DoublePrecision, which causes all sorts of downstream promotion/interaction problems. `step(r)` returns the ordinary precision number I expected. The fact that we this currently has `r.step` and `step(s)` immediately juxtaposed makes me think that using the field directly was intentional... but nothing breaks. * Add test * Add a bit of slop for LinSpace on 0.5
1 parent f9729fd commit 6c9eed9

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/search.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ else
5959
@inline inbounds_getindex(r::StepRangeLen, i::Integer) = Base.unsafe_getindex(r, i)
6060
@inline function inbounds_getindex(r::StepRangeLen, s::OrdinalRange)
6161
vfirst = Base.unsafe_getindex(r, first(s))
62-
StepRangeLen(vfirst, r.step*step(s), length(s))
62+
StepRangeLen(vfirst, step(r)*step(s), length(s))
6363
end
6464
""")
6565
end

test/indexing.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ AxisArrays.axistrait(::AbstractVector{IntLike}) = AxisArrays.Dimensional
114114
end
115115

116116
for (r, Irel) in ((0.1:0.1:10.0, -0.5..0.5), # FloatRange
117+
(linspace(0.1, 10.0, 100), -0.51..0.51), # LinSpace
117118
(IL.IntLike(1):IL.IntLike(1):IL.IntLike(100),
118119
IL.IntLike(-5)..IL.IntLike(5))) # StepRange
119120
Iabs = r[20]..r[30]
@@ -127,6 +128,9 @@ for (r, Irel) in ((0.1:0.1:10.0, -0.5..0.5), # FloatRange
127128
@test A[r[[25, 35]] + Irel, :c1] == [20:30 30:40]
128129
@test_throws BoundsError A[atindex(Irel, 5), :c1]
129130
@test_throws BoundsError A[atindex(Irel, [5, 15, 25]), :]
131+
132+
B = A[r[[25, 35]] + Irel, :c1]
133+
@test B[:,:] == B[Irel, :] == [20:30 30:40]
130134
end
131135

132136
# Indexing with CartesianIndex

0 commit comments

Comments
 (0)