@@ -7,40 +7,40 @@ using Compat
7
7
8
8
export OffsetArray, @unsafe
9
9
10
- immutable OffsetArray{T,N,AA<: AbstractArray } <: AbstractArray{T,N}
10
+ struct OffsetArray{T,N,AA<: AbstractArray } <: AbstractArray{T,N}
11
11
parent:: AA
12
12
offsets:: NTuple{N,Int}
13
13
end
14
- @compat OffsetVector{T,AA<: AbstractArray } = OffsetArray{T,1 ,AA}
14
+ OffsetVector{T,AA<: AbstractArray } = OffsetArray{T,1 ,AA}
15
15
16
- OffsetArray {T,N} (A:: AbstractArray{T,N} , offsets:: NTuple{N,Int} ) =
16
+ OffsetArray (A:: AbstractArray{T,N} , offsets:: NTuple{N,Int} ) where {T,N} =
17
17
OffsetArray {T,N,typeof(A)} (A, offsets)
18
- OffsetArray {T,N} (A:: AbstractArray{T,N} , offsets:: Vararg{Int,N} ) =
18
+ OffsetArray (A:: AbstractArray{T,N} , offsets:: Vararg{Int,N} ) where {T,N} =
19
19
OffsetArray (A, offsets)
20
20
21
- ( :: Type{ OffsetArray{T,N}} ){T,N} (inds:: Indices{N} ) =
21
+ OffsetArray {T,N} (inds:: Indices{N} ) where {T,N} =
22
22
OffsetArray {T,N,Array{T,N}} (Array {T,N} (map (length, inds)), map (indexoffset, inds))
23
- ( :: Type{ OffsetArray{T}} ){T,N} (inds:: Indices{N} ) = OffsetArray {T,N} (inds)
24
- ( :: Type{ OffsetArray{T,N}} ){T,N} (inds:: Vararg{AbstractUnitRange,N} ) = OffsetArray {T,N} (inds)
25
- ( :: Type{ OffsetArray{T}} ){T,N} (inds:: Vararg{AbstractUnitRange,N} ) = OffsetArray {T,N} (inds)
26
- OffsetArray {T} (A:: AbstractArray{T,0} ) = OffsetArray {T,0,typeof(A)} (A, ())
27
- OffsetArray {T,N} (:: Type{T} , inds:: Vararg{UnitRange{Int},N} ) = OffsetArray {T,N} (inds)
23
+ OffsetArray {T} (inds:: Indices{N} ) where {T,N} = OffsetArray {T,N} (inds)
24
+ OffsetArray {T,N} (inds:: Vararg{AbstractUnitRange,N} ) where {T,N} = OffsetArray {T,N} (inds)
25
+ OffsetArray {T} (inds:: Vararg{AbstractUnitRange,N} ) where {T,N} = OffsetArray {T,N} (inds)
26
+ OffsetArray (A:: AbstractArray{T,0} ) where {T} = OffsetArray {T,0,typeof(A)} (A, ())
27
+ OffsetArray (:: Type{T} , inds:: Vararg{UnitRange{Int},N} ) where {T,N} = OffsetArray {T,N} (inds)
28
28
29
29
# The next two are necessary for ambiguity resolution. Really, the
30
30
# second method should not be necessary.
31
- OffsetArray {T} (A:: AbstractArray{T,0} , inds:: Tuple{} ) = OffsetArray {T,0,typeof(A)} (A, ())
32
- OffsetArray {T,N} (A:: AbstractArray{T,N} , inds:: Tuple{} ) = error (" this should never be called" )
33
- function OffsetArray {T,N} (A:: AbstractArray{T,N} , inds:: NTuple{N,AbstractUnitRange} )
31
+ OffsetArray (A:: AbstractArray{T,0} , inds:: Tuple{} ) where {T} = OffsetArray {T,0,typeof(A)} (A, ())
32
+ OffsetArray (A:: AbstractArray{T,N} , inds:: Tuple{} ) where {T,N} = error (" this should never be called" )
33
+ function OffsetArray (A:: AbstractArray{T,N} , inds:: NTuple{N,AbstractUnitRange} ) where {T,N}
34
34
lA = map (length, indices (A))
35
35
lI = map (length, inds)
36
36
lA == lI || throw (DimensionMismatch (" supplied indices do not agree with the size of the array (got size $lA for the array and $lI for the indices" ))
37
37
OffsetArray (A, map (indexoffset, inds))
38
38
end
39
- OffsetArray {T,N} (A:: AbstractArray{T,N} , inds:: Vararg{AbstractUnitRange,N} ) =
39
+ OffsetArray (A:: AbstractArray{T,N} , inds:: Vararg{AbstractUnitRange,N} ) where {T,N} =
40
40
OffsetArray (A, inds)
41
41
42
- @compat Compat. IndexStyle {OA<:OffsetArray} (:: Type{OA} ) = IndexStyle (parenttype (OA))
43
- parenttype {T,N,AA} (:: Type{OffsetArray{T,N,AA}} ) = AA
42
+ Compat. IndexStyle (:: Type{OA} ) where {OA <: OffsetArray } = IndexStyle (parenttype (OA))
43
+ parenttype (:: Type{OffsetArray{T,N,AA}} ) where {T,N,AA} = AA
44
44
parenttype (A:: OffsetArray ) = parenttype (typeof (A))
45
45
46
46
Base. parent (A:: OffsetArray ) = A. parent
@@ -61,12 +61,12 @@ Base.eachindex(::IndexLinear, A::OffsetVector) = indices(A, 1)
61
61
@inline _indices (inds, offsets) =
62
62
(inds[1 ]+ offsets[1 ], _indices (tail (inds), tail (offsets))... )
63
63
_indices (:: Tuple{} , :: Tuple{} ) = ()
64
- Base. indices1 {T} (A:: OffsetArray{T,0} ) = 1 : 1 # we only need to specialize this one
64
+ Base. indices1 (A:: OffsetArray{T,0} ) where {T} = 1 : 1 # we only need to specialize this one
65
65
66
- function Base. similar {T} (A:: OffsetArray , :: Type{T} , dims:: Dims )
66
+ function Base. similar (A:: OffsetArray , :: Type{T} , dims:: Dims ) where T
67
67
B = similar (parent (A), T, dims)
68
68
end
69
- function Base. similar {T} (A:: AbstractArray , :: Type{T} , inds:: Tuple{UnitRange,Vararg{UnitRange}} )
69
+ function Base. similar (A:: AbstractArray , :: Type{T} , inds:: Tuple{UnitRange,Vararg{UnitRange}} ) where T
70
70
B = similar (A, T, map (length, inds))
71
71
OffsetArray (B, map (indexoffset, inds))
72
72
end
@@ -85,7 +85,7 @@ function Base.reshape(A::OffsetArray, inds::Tuple{UnitRange,Vararg{Union{UnitRan
85
85
end
86
86
87
87
# Don't allow bounds-checks to be removed during Julia 0.5
88
- @inline function Base. getindex {T,N} (A:: OffsetArray{T,N} , I:: Vararg{Int,N} )
88
+ @inline function Base. getindex (A:: OffsetArray{T,N} , I:: Vararg{Int,N} ) where {T,N}
89
89
checkbounds (A, I... )
90
90
@inbounds ret = parent (A)[offset (A. offsets, I)... ]
91
91
ret
100
100
@inbounds ret = parent (A)[i]
101
101
ret
102
102
end
103
- @inline function Base. setindex! {T,N} (A:: OffsetArray{T,N} , val, I:: Vararg{Int,N} )
103
+ @inline function Base. setindex! (A:: OffsetArray{T,N} , val, I:: Vararg{Int,N} ) where {T,N}
104
104
checkbounds (A, I... )
105
105
@inbounds parent (A)[offset (A. offsets, I)... ] = val
106
106
val
@@ -125,7 +125,7 @@ Base.fill(x, inds::Tuple{UnitRange,Vararg{UnitRange}}) =
125
125
# ## Low-level utilities ###
126
126
127
127
# Computing a shifted index (subtracting the offset)
128
- @inline offset {N} (offsets:: NTuple{N,Int} , inds:: NTuple{N,Int} ) = _offset ((), offsets, inds)
128
+ @inline offset (offsets:: NTuple{N,Int} , inds:: NTuple{N,Int} ) where {N} = _offset ((), offsets, inds)
129
129
_offset (out, :: Tuple{} , :: Tuple{} ) = out
130
130
@inline _offset (out, offsets, inds) =
131
131
_offset ((out... , inds[1 ]- offsets[1 ]), Base. tail (offsets), Base. tail (inds))
@@ -201,12 +201,12 @@ end
201
201
@inline unsafe_setindex! (a:: OffsetArray , val, I... ) = unsafe_setindex! (a, val, Base. IteratorsMD. flatten (I)... )
202
202
203
203
# Indexing a SubArray which has OffsetArray indices
204
- @compat OffsetSubArray{T,N,P,I<: Tuple{OffsetArray,Vararg{OffsetArray}} } = SubArray{T,N,P,I,false }
205
- @inline function unsafe_getindex {T,N} (a:: OffsetSubArray{T,N} , I:: Vararg{Int,N} )
204
+ OffsetSubArray{T,N,P,I<: Tuple{OffsetArray,Vararg{OffsetArray}} } = SubArray{T,N,P,I,false }
205
+ @inline function unsafe_getindex (a:: OffsetSubArray{T,N} , I:: Vararg{Int,N} ) where {T,N}
206
206
J = map (unsafe_getindex, a. indexes, I)
207
207
unsafe_getindex (parent (a), J... )
208
208
end
209
- @inline function unsafe_setindex! {T,N} (a:: OffsetSubArray{T,N} , val, I:: Vararg{Int,N} )
209
+ @inline function unsafe_setindex! (a:: OffsetSubArray{T,N} , val, I:: Vararg{Int,N} ) where {T,N}
210
210
J = map (unsafe_getindex, a. indexes, I)
211
211
unsafe_setindex! (parent (a), val, J... )
212
212
end
0 commit comments