|
| 1 | +__precompile__() |
| 2 | + |
1 | 3 | module OffsetArrays
|
2 | 4 |
|
3 | 5 | Base.@deprecate_binding (..) Colon()
|
@@ -27,8 +29,12 @@ OffsetArray{T,N}(::Type{T}, inds::Vararg{UnitRange{Int},N}) = OffsetArray{T,N}(i
|
27 | 29 | # second method should not be necessary.
|
28 | 30 | OffsetArray{T}(A::AbstractArray{T,0}, inds::Tuple{}) = OffsetArray{T,0,typeof(A)}(A, ())
|
29 | 31 | OffsetArray{T,N}(A::AbstractArray{T,N}, inds::Tuple{}) = error("this should never be called")
|
30 |
| -OffsetArray{T,N}(A::AbstractArray{T,N}, inds::NTuple{N,AbstractUnitRange}) = |
| 32 | +function OffsetArray{T,N}(A::AbstractArray{T,N}, inds::NTuple{N,AbstractUnitRange}) |
| 33 | + lA = map(length, indices(A)) |
| 34 | + lI = map(length, inds) |
| 35 | + 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")) |
31 | 36 | OffsetArray(A, map(indexoffset, inds))
|
| 37 | +end |
32 | 38 | OffsetArray{T,N}(A::AbstractArray{T,N}, inds::Vararg{AbstractUnitRange,N}) =
|
33 | 39 | OffsetArray(A, inds)
|
34 | 40 |
|
@@ -66,6 +72,11 @@ Base.similar(f::Union{Function,DataType}, shape::Tuple{UnitRange,Vararg{UnitRang
|
66 | 72 | Base.reshape(A::AbstractArray, inds::Tuple{UnitRange,Vararg{UnitRange}}) = OffsetArray(reshape(A, map(length, inds)), map(indexoffset, inds))
|
67 | 73 |
|
68 | 74 | Base.reshape(A::OffsetArray, inds::Tuple{UnitRange,Vararg{UnitRange}}) = OffsetArray(reshape(parent(A), map(length, inds)), map(indexoffset, inds))
|
| 75 | + |
| 76 | +function Base.reshape(A::OffsetArray, inds::Tuple{UnitRange,Vararg{Union{UnitRange,Int,Base.OneTo}}}) |
| 77 | + throw(ArgumentError("reshape must supply UnitRange indices, got $(typeof(inds)).\n Note that reshape(A, Val{N}) is not supported for OffsetArrays.")) |
| 78 | +end |
| 79 | + |
69 | 80 | # Don't allow bounds-checks to be removed during Julia 0.5
|
70 | 81 | @inline function Base.getindex{T,N}(A::OffsetArray{T,N}, I::Vararg{Int,N})
|
71 | 82 | checkbounds(A, I...)
|
|
0 commit comments