Skip to content

Commit 44bb49c

Browse files
committed
Add docs
1 parent 9d8fd12 commit 44bb49c

File tree

4 files changed

+47
-20
lines changed

4 files changed

+47
-20
lines changed

base/abstractarray.jl

+10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@ end
2121

2222
size{T,n}(t::AbstractArray{T,n}, d) = d <= n ? size(t)[d] : 1
2323
size(x, d1::Integer, d2::Integer, dx::Integer...) = tuple(size(x, d1), size(x, d2, dx...)...)
24+
"""
25+
indices(A, d)
26+
27+
Returns the valid range of indices for array `A` along dimension `d`.
28+
"""
2429
indices(A::AbstractArray, d) = 1:size(A,d)
30+
"""
31+
indices(A)
32+
33+
Returns the tuple of valid indices for array `A`.
34+
"""
2535
indices{T,N}(A::AbstractArray{T,N}) = ntuple(d->indices(A, d), Val{N})
2636
eltype{T}(::Type{AbstractArray{T}}) = T
2737
eltype{T,n}(::Type{AbstractArray{T,n}}) = T

doc/manual/arrays.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ Function Description
5050
:func:`length(A) <length>` the number of elements in ``A``
5151
:func:`ndims(A) <ndims>` the number of dimensions of ``A``
5252
:func:`size(A) <size>` a tuple containing the dimensions of ``A``
53-
:func:`size(A,n) <size>` the size of ``A`` in a particular dimension
53+
:func:`size(A,n) <size>` the size of ``A`` along a particular dimension
54+
:func:`indices(A) <indices>` a tuple containing the valid indices of ``A``
55+
:func:`indices(A,n) <indices>` a range expressing the valid indices along dimension ``n``
5456
:func:`eachindex(A) <eachindex>` an efficient iterator for visiting each position in ``A``
5557
:func:`stride(A,k) <stride>` the stride (linear index distance between adjacent elements) along dimension ``k``
5658
:func:`strides(A) <strides>` a tuple of the strides in each dimension

doc/manual/interfaces.rst

+22-19
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,28 @@ While this is starting to support more of the :ref:`indexing operations supporte
147147
Abstract Arrays
148148
---------------
149149

150-
========================================================== ============================================ =======================================================================================
151-
Methods to implement Brief description
152-
========================================================== ============================================ =======================================================================================
153-
:func:`size(A) <size>` Returns a tuple containing the dimensions of A
154-
:func:`Base.linearindexing(Type) <Base.linearindexing>` Returns either ``Base.LinearFast()`` or ``Base.LinearSlow()``. See the description below.
155-
:func:`getindex(A, i::Int) <getindex>` (if ``LinearFast``) Linear scalar indexing
156-
:func:`getindex(A, i1::Int, ..., iN::Int) <getindex>` (if ``LinearSlow``, where ``N = ndims(A)``) N-dimensional scalar indexing
157-
:func:`setindex!(A, v, i::Int) <getindex>` (if ``LinearFast``) Scalar indexed assignment
158-
:func:`setindex!(A, v, i1::Int, ..., iN::Int) <getindex>` (if ``LinearSlow``, where ``N = ndims(A)``) N-dimensional scalar indexed assignment
159-
**Optional methods** **Default definition** **Brief description**
160-
:func:`getindex(A, I...) <getindex>` defined in terms of scalar :func:`getindex` :ref:`Multidimensional and nonscalar indexing <man-array-indexing>`
161-
:func:`setindex!(A, I...) <setindex!>` defined in terms of scalar :func:`setindex!` :ref:`Multidimensional and nonscalar indexed assignment <man-array-indexing>`
162-
:func:`start`/:func:`next`/:func:`done` defined in terms of scalar :func:`getindex` Iteration
163-
:func:`length(A) <length>` ``prod(size(A))`` Number of elements
164-
:func:`similar(A) <similar>` ``similar(A, eltype(A), size(A))`` Return a mutable array with the same shape and element type
165-
:func:`similar(A, ::Type{S}) <similar>` ``similar(A, S, size(A))`` Return a mutable array with the same shape and the specified element type
166-
:func:`similar(A, dims::NTuple{Int}) <similar>` ``similar(A, eltype(A), dims)`` Return a mutable array with the same element type and the specified dimensions
167-
:func:`similar(A, ::Type{S}, dims::NTuple{Int}) <similar>` ``Array(S, dims)`` Return a mutable array with the specified element type and dimensions
168-
========================================================== ============================================ =======================================================================================
150+
===================================================================== ============================================ =======================================================================================
151+
Methods to implement Brief description
152+
===================================================================== ============================================ =======================================================================================
153+
:func:`size(A) <size>` Returns a tuple containing the dimensions of ``A``
154+
:func:`getindex(A, i::Int) <getindex>` (if ``LinearFast``) Linear scalar indexing
155+
:func:`getindex(A, i1::Int, ..., iN::Int) <getindex>` (if ``LinearSlow``, where ``N = ndims(A)``) N-dimensional scalar indexing
156+
:func:`setindex!(A, v, i::Int) <getindex>` (if ``LinearFast``) Scalar indexed assignment
157+
:func:`setindex!(A, v, i1::Int, ..., iN::Int) <getindex>` (if ``LinearSlow``, where ``N = ndims(A)``) N-dimensional scalar indexed assignment
158+
**Optional methods** **Default definition** **Brief description**
159+
:func:`Base.linearindexing(Type) <Base.linearindexing>` ``Base.LinearSlow()`` Returns either ``Base.LinearFast()`` or ``Base.LinearSlow()``. See the description below.
160+
:func:`indices(A, d) <indices>` ``1:size(A, d)`` Returns the range of valid indices along dimension ``d``
161+
:func:`getindex(A, I...) <getindex>` defined in terms of scalar :func:`getindex` :ref:`Multidimensional and nonscalar indexing <man-array-indexing>`
162+
:func:`setindex!(A, I...) <setindex!>` defined in terms of scalar :func:`setindex!` :ref:`Multidimensional and nonscalar indexed assignment <man-array-indexing>`
163+
:func:`start`/:func:`next`/:func:`done` defined in terms of scalar :func:`getindex` Iteration
164+
:func:`length(A) <length>` ``prod(size(A))`` Number of elements
165+
:func:`similar(A) <similar>` ``similar(A, eltype(A), indices(A))`` Return a mutable array with the same shape and element type
166+
:func:`similar(A, ::Type{S}) <similar>` ``similar(A, S, indices(A))`` Return a mutable array with the same shape and the specified element type
167+
:func:`similar(A, inds::NTuple{UnitRange{Int}}) <similar>` ``similar(A, eltype(A), inds)`` Return a mutable array with the same element type and the specified indices
168+
:func:`similar(A, dims::NTuple{Int}) <similar>` ``similar(A, eltype(A), dims)`` Return a mutable array with the same element type and size `dims`
169+
:func:`similar(A, ::Type{S}, inds::NTuple{UnitRange{Int}}) <similar>` ``Array(S, map(length, inds))`` Return a mutable array with the specified element type and indices
170+
:func:`similar(A, ::Type{S}, dims::NTuple{Int}) <similar>` ``Array(S, dims)`` Return a mutable array with the specified element type and size
171+
===================================================================== ============================================ =======================================================================================
169172

170173
If a type is defined as a subtype of ``AbstractArray``, it inherits a very large set of rich behaviors including iteration and multidimensional indexing built on top of single-element access. See the :ref:`arrays manual page <man-arrays>` and :ref:`standard library section <stdlib-arrays>` for more supported methods.
171174

doc/stdlib/arrays.rst

+12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ Basic functions
3131
julia> size(A,3,2)
3232
(4,3)
3333
34+
.. function:: indices(A)
35+
36+
.. Docstring generated from Julia source
37+
38+
Returns the tuple of valid indices for array ``A``\ .
39+
40+
.. function:: indices(A, d)
41+
42+
.. Docstring generated from Julia source
43+
44+
Returns the valid range of indices for array ``A`` along dimension ``d``\ .
45+
3446
.. function:: iseltype(A,T)
3547

3648
.. Docstring generated from Julia source

0 commit comments

Comments
 (0)