@@ -114,8 +114,6 @@ function Base.similar(A::AbstractArray, ::Type{T}, inds::Tuple{UnitRange,Vararg{
114
114
OffsetArray (B, map (indexoffset, inds))
115
115
end
116
116
117
- Base. similar (f:: Function , shape:: Tuple{UnitRange,Vararg{UnitRange}} ) =
118
- OffsetArray (f (map (length, shape)), map (indexoffset, shape))
119
117
Base. similar (:: Type{T} , shape:: Tuple{UnitRange,Vararg{UnitRange}} ) where {T<: OffsetArray } =
120
118
OffsetArray (T (map (length, shape)), map (indexoffset, shape))
121
119
Base. similar (:: Type{T} , shape:: Tuple{UnitRange,Vararg{UnitRange}} ) where {T<: Array } =
@@ -133,6 +131,24 @@ function Base.reshape(A::OffsetArray, inds::Tuple{UnitRange,Vararg{Union{UnitRan
133
131
throw (ArgumentError (" reshape must supply UnitRange axes, got $(typeof (inds)) .\n Note that reshape(A, Val{N}) is not supported for OffsetArrays." ))
134
132
end
135
133
134
+ if VERSION < v " 0.7.0-DEV.4873"
135
+ # Julia PR #26733 removed similar(f, ...) in favor of just using method extension directly
136
+ # https://github.com/JuliaLang/julia/pull/26733
137
+ Base. similar (f:: Function , shape:: Tuple{UnitRange,Vararg{UnitRange}} ) =
138
+ OffsetArray (f (map (length, shape)), map (indexoffset, shape))
139
+ else
140
+ Base. fill (v, inds:: NTuple{N, Union{Integer, AbstractUnitRange}} ) where {N} =
141
+ fill! (OffsetArray (Array {typeof(v), N} (undef, map (indexlength, inds)), map (indexoffset, inds)), v)
142
+ Base. zeros (:: Type{T} , inds:: NTuple{N, Union{Integer, AbstractUnitRange}} ) where {T, N} =
143
+ fill! (OffsetArray (Array {T, N} (undef, map (indexlength, inds)), map (indexoffset, inds)), zero (T))
144
+ Base. ones (:: Type{T} , inds:: NTuple{N, Union{Integer, AbstractUnitRange}} ) where {T, N} =
145
+ fill! (OffsetArray (Array {T, N} (undef, map (indexlength, inds)), map (indexoffset, inds)), one (T))
146
+ Base. trues (inds:: NTuple{N, Union{Integer, AbstractUnitRange}} ) where {N} =
147
+ fill! (OffsetArray (BitArray {N} (undef, map (indexlength, inds)), map (indexoffset, inds)), true )
148
+ Base. falses (inds:: NTuple{N, Union{Integer, AbstractUnitRange}} ) where {N} =
149
+ fill! (OffsetArray (BitArray {N} (undef, map (indexlength, inds)), map (indexoffset, inds)), false )
150
+ end
151
+
136
152
# Don't allow bounds-checks to be removed during Julia 0.5
137
153
@inline function Base. getindex (A:: OffsetArray{T,N} , I:: Vararg{Int,N} ) where {T,N}
138
154
checkbounds (A, I... )
@@ -185,6 +201,8 @@ offset(offsets::Tuple{Vararg{Int}}, inds::Tuple{}) = error("inds cannot be short
185
201
186
202
indexoffset (r:: AbstractRange ) = first (r) - 1
187
203
indexoffset (i:: Integer ) = 0
204
+ indexlength (r:: AbstractRange ) = length (r)
205
+ indexlength (i:: Integer ) = i
188
206
189
207
macro unsafe (ex)
190
208
esc (unsafe (ex))
0 commit comments