Skip to content

Commit 2b77520

Browse files
tpapptimholy
authored andcommitted
Add docstring to constructor
1 parent 7667bc7 commit 2b77520

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/OffsetArrays.jl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,24 @@ OffsetArray{T}(init::ArrayInitializer, inds::Vararg{AbstractUnitRange,N}) where
8484
OffsetVector(A::AbstractVector, offset) = OffsetArray(A, offset)
8585
OffsetVector{T}(init::ArrayInitializer, inds::AbstractUnitRange) where {T} = OffsetArray{T}(init, inds)
8686

87-
# # The next two are necessary for ambiguity resolution. Really, the
88-
# # second method should not be necessary.
89-
# OffsetArray(A::AbstractArray{T,0}, inds::Tuple{}) where {T} = OffsetArray{T,0,typeof(A)}(A, ())
90-
# OffsetArray(A::AbstractArray{T,N}, inds::Tuple{}) where {T,N} = error("this should never be called")
87+
"""
88+
OffsetArray(A, indices...)
89+
90+
Return an `AbstractArray` that shares element type and size with the first argument, but
91+
used the given `indices`, which are checked for compatible size.
92+
93+
# Example
9194
95+
```jldoctest
96+
julia> A = OffsetArray(reshape(1:6, 2, 3), 0:1, -1:1)
97+
OffsetArray(reshape(::UnitRange{Int64}, 2, 3), 0:1, -1:1) with eltype Int64 with indices 0:1×-1:1:
98+
1 3 5
99+
2 4 6
100+
101+
julia> A[0, 1]
102+
5
103+
```
104+
"""
92105
function OffsetArray(A::AbstractArray{T,N}, inds::NTuple{N,AbstractUnitRange}) where {T,N}
93106
axparent = axes(A)
94107
lA = map(length, axparent)

0 commit comments

Comments
 (0)