Skip to content

Commit

Permalink
add documentation for [Abstract]Vector/[Abstract]Matrix (#22674)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored and ararslan committed Jul 5, 2017
1 parent cf8d54a commit 5271cd8
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 9 deletions.
7 changes: 4 additions & 3 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
## Basic functions ##

"""
AbstractArray{T, N}
AbstractArray{T,N}
Abstract array supertype which arrays inherit from.
Abstract `N`-dimensional array supertype containing elements of type `T`.
[`Array`](@ref)s and some array-like objects inherit from this type.
"""
AbstractArray

Expand Down Expand Up @@ -877,7 +878,7 @@ end
getindex(A, inds...)
Return a subset of array `A` as specified by `inds`, where each `ind` may be an
`Int`, a `Range`, or a `Vector`. See the manual section on
`Int`, a `Range`, or a [`Vector`](@ref). See the manual section on
[array indexing](@ref man-array-indexing) for details.
# Examples
Expand Down
23 changes: 23 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@
## array.jl: Dense arrays

## Type aliases for convenience ##
"""
AbstractVector{T}
Abstract vector supertype containing elements of type `T`.
Alias for [`AbstractArray{T,1}`](@ref).
"""
const AbstractVector{T} = AbstractArray{T,1}

"""
AbstractMatrix{T}
Abstract matrix supertype containing elements of type `T`.
Alias for [`AbstractArray{T,2}`](@ref).
"""
const AbstractMatrix{T} = AbstractArray{T,2}
const AbstractVecOrMat{T} = Union{AbstractVector{T}, AbstractMatrix{T}}
const RangeIndex = Union{Int, Range{Int}, AbstractUnitRange{Int}}
Expand All @@ -13,7 +25,18 @@ const IntOrInd = Union{Int, AbstractUnitRange}
const DimsOrInds{N} = NTuple{N,DimOrInd}
const NeedsShaping = Union{Tuple{Integer,Vararg{Integer}}, Tuple{OneTo,Vararg{OneTo}}}

"""
Vector{T}
Vector type containing elements of type `T`. Alias for [`Array{T,1}`](@ref).
"""
const Vector{T} = Array{T,1}

"""
Matrix{T}
Matrix type containing elements of type `T`. Alias for [`Array{T,2}`](@ref).
"""
const Matrix{T} = Array{T,2}
const VecOrMat{T} = Union{Vector{T}, Matrix{T}}

Expand Down
2 changes: 1 addition & 1 deletion base/linalg/rowvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
RowVector(vector)
A lazy-view wrapper of an `AbstractVector`, which turns a length-`n` vector into a `1×n`
A lazy-view wrapper of an [`AbstractVector`](@ref), which turns a length-`n` vector into a `1×n`
shaped row vector and represents the transpose of a vector (the elements are also transposed
recursively). This type is usually constructed (and unwrapped) via the [`transpose`](@ref)
function or `.'` operator (or related [`ctranspose`](@ref) or `'` operator).
Expand Down
2 changes: 1 addition & 1 deletion doc/src/devdocs/offset-arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ can sometimes simplify such tests.

Some algorithms are most conveniently (or efficiently) written in terms of a single linear index,
`A[i]` even if `A` is multi-dimensional. In "true" linear indexing, the indices always range
from `1:length(A)`. However, this raises an ambiguity for one-dimensional arrays (a.k.a., `AbstractVector`):
from `1:length(A)`. However, this raises an ambiguity for one-dimensional arrays (a.k.a., [`AbstractVector`](@ref)):
does `v[i]` mean linear indexing, or Cartesian indexing with the array's native indices?

For this reason, if you want to use linear indexing in an algorithm, your best option is to get
Expand Down
6 changes: 3 additions & 3 deletions doc/src/manual/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,8 @@ julia> string.(1:3, ". ", ["First", "Second", "Third"])

### Implementation

The base array type in Julia is the abstract type `AbstractArray{T,N}`. It is parametrized by
the number of dimensions `N` and the element type `T`. `AbstractVector` and `AbstractMatrix` are
The base array type in Julia is the abstract type [`AbstractArray{T,N}`](@ref). It is parametrized by
the number of dimensions `N` and the element type `T`. [`AbstractVector`](@ref) and [`AbstractMatrix`](@ref) are
aliases for the 1-d and 2-d cases. Operations on `AbstractArray` objects are defined using higher
level operators and functions, in a way that is independent of the underlying storage. These operations
generally work correctly as a fallback for any specific array implementation.
Expand All @@ -644,7 +644,7 @@ method [`Base.unsafe_convert(Ptr{T}, A)`](@ref) is provided, the memory layout s
in the same way to these strides.

The [`Array`](@ref) type is a specific instance of `DenseArray` where elements are stored in column-major
order (see additional notes in [Performance Tips](@ref man-performance-tips)). `Vector` and `Matrix` are aliases for
order (see additional notes in [Performance Tips](@ref man-performance-tips)). [`Vector`](@ref) and [`Matrix`](@ref) are aliases for
the 1-d and 2-d cases. Specific operations such as scalar indexing, assignment, and a few other
basic storage-specific operations are all that have to be implemented for [`Array`](@ref), so
that the rest of the array library can be implemented in a generic manner.
Expand Down
2 changes: 1 addition & 1 deletion doc/src/manual/performance-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ is that with column-major arrays, the first index changes most rapidly. Essentia
that looping will be faster if the inner-most loop index is the first to appear in a slice expression.

Consider the following contrived example. Imagine we wanted to write a function that accepts a
`Vector` and returns a square `Matrix` with either the rows or the columns filled with copies
[`Vector`](@ref) and returns a square [`Matrix`](@ref) with either the rows or the columns filled with copies
of the input vector. Assume that it is not important whether rows or columns are filled with these
copies (perhaps the rest of the code can be easily adapted accordingly). We could conceivably
do this in at least four ways (in addition to the recommended call to the built-in [`repmat()`](@ref)):
Expand Down
4 changes: 4 additions & 0 deletions doc/src/stdlib/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

```@docs
Core.AbstractArray
Base.AbstractVector
Base.AbstractMatrix
Core.Array
Base.Vector
Base.Matrix
Base.getindex(::Type, ::Any...)
Base.zeros
Base.ones
Expand Down

0 comments on commit 5271cd8

Please sign in to comment.