You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Convert to OffsetArrays
* Add no-op conversion tests
* new constructors
* convert instead of constructing the parent type
* Avoid stack overflow in Vararg
* rename _maybemap to _of_eltype
Co-authored-by: Johnny Chen <johnnychen94@hotmail.com>
* fix indexing on nightly
* use UnitRange{Int} instead of UnitRange for indexing
* strip offset before converting
* fix conversion to nested OffsetArrays
* add test for custom indices
* add tests
* remove redundant methods
* further reduce methods
Co-authored-by: Johnny Chen <johnnychen94@hotmail.com>
@inlineOffsetArray{T}(M::AbstractArray, I...) where {T} =OffsetArray{T,ndims(M)}(M, I...)
225
+
226
+
@inlinefunctionOffsetArray{T,N}(M::AbstractArray{<:Any,N}, I...) where {T,N}
227
+
M2 =_of_eltype(T, M)
228
+
OffsetArray{T,N,typeof(M2)}(M2, I...)
229
+
end
230
+
231
+
@inlineOffsetArray{T,N,A}(M::AbstractArray{<:Any,N}, I::Vararg) where {T,N,A<:AbstractArray{T,N}} =OffsetArray{T,N,A}(M, I)
232
+
@inlinefunctionOffsetArray{T,N,A}(M::AbstractArray{<:Any,N}, I::NTuple{N,Int}) where {T,N,A<:AbstractArray{T,N}}
233
+
map(overflow_check, axes(M), I)
234
+
Mv =no_offset_view(M)
235
+
MvA =convert(A, Mv)::A
236
+
Iof =map(+, _offsets(M), I)
237
+
OffsetArray{T,N,A}(MvA, Iof)
238
+
end
239
+
@inlinefunctionOffsetArray{T, N, AA}(parent::AbstractArray{<:Any,N}, offsets::NTuple{N, Integer}) where {T, N, AA<:AbstractArray{T,N}}
240
+
OffsetArray{T, N, AA}(parent, map(Int, offsets)::NTuple{N,Int})
241
+
end
242
+
@inlinefunctionOffsetArray{T,N,A}(M::AbstractArray{<:Any,N}, I::Tuple{AbstractUnitRange,Vararg{AbstractUnitRange}}) where {T,N,A<:AbstractArray{T,N}}
243
+
_checkindices(M, I, "indices")
244
+
# Performance gain by wrapping the error in a function: see https://github.com/JuliaLang/julia/issues/37558
245
+
throw_dimerr(lA, lI) =throw(DimensionMismatch("supplied axes do not agree with the size of the array (got size $lA for the array and $lI for the indices"))
246
+
lM =size(M)
247
+
lI =map(length, I)
248
+
lM == lI ||throw_dimerr(lM, lI)
249
+
OffsetArray{T,N,A}(M, map(_offset, axes(M), I))
250
+
end
251
+
@inlinefunctionOffsetArray{T,N,A}(M::AbstractArray{<:Any,N}, I::Tuple) where {T,N,A<:AbstractArray{T,N}}
0 commit comments