Skip to content

Commit

Permalink
separate type docs and constructor docs (#22690)
Browse files Browse the repository at this point in the history
* Vector - docstring for constructor

* Matrix - docstring for constructor

* Array - split type and constructor docstring

* BitArray - type documentation
  • Loading branch information
fredrikekre authored and KristofferC committed Jul 10, 2017
1 parent fb666b1 commit 00e74c3
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 30 deletions.
34 changes: 9 additions & 25 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,22 @@ const DimsOrInds{N} = NTuple{N,DimOrInd}
const NeedsShaping = Union{Tuple{Integer,Vararg{Integer}}, Tuple{OneTo,Vararg{OneTo}}}

"""
Vector{T}
Array{T,N} <: AbstractArray{T,N}
`N`-dimensional dense array with elements of type `T`.
"""
Array

"""
Vector{T} <: AbstractVector{T}
One-dimensional dense array with elements of type `T`, often used to represent
a mathematical vector. Alias for [`Array{T,1}`](@ref).
"""
const Vector{T} = Array{T,1}

"""
Matrix{T}
Matrix{T} <: AbstractMatrix{T}
Two-dimensional dense array with elements of type `T`, often used to represent
a mathematical matrix. Alias for [`Array{T,2}`](@ref).
Expand Down Expand Up @@ -74,29 +81,6 @@ eltype(x) = eltype(typeof(x))

import Core: arraysize, arrayset, arrayref

"""
Array{T}(dims)
Array{T,N}(dims)
Construct an uninitialized `N`-dimensional dense array with element type `T`,
where `N` is determined from the length or number of `dims`. `dims` may
be a tuple or a series of integer arguments corresponding to the lengths in each dimension.
If the rank `N` is supplied explicitly as in `Array{T,N}(dims)`, then it must
match the length or number of `dims`.
# Examples
```jldoctest
julia> A = Array{Float64, 2}(2, 2);
julia> ndims(A)
2
julia> eltype(A)
Float64
```
"""
Array

vect() = Array{Any,1}(0)
vect(X::T...) where {T} = T[ X[i] for i = 1:length(X) ]

Expand Down
13 changes: 10 additions & 3 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

# notes: bits are stored in contiguous chunks
# unused bits must always be set to 0
"""
BitArray{N} <: DenseArray{Bool, N}
Space-efficient `N`-dimensional boolean array, which stores one bit per boolean value.
"""
mutable struct BitArray{N} <: DenseArray{Bool, N}
chunks::Vector{UInt64}
len::Int
Expand Down Expand Up @@ -32,9 +37,10 @@ end
BitArray(dims::Integer...)
BitArray{N}(dims::NTuple{N,Int})
Construct an uninitialized `BitArray` with the given dimensions.
Construct an uninitialized [`BitArray`](@ref) with the given dimensions.
Behaves identically to the [`Array`](@ref) constructor.
# Examples
```julia-repl
julia> BitArray(2, 2)
2×2 BitArray{2}:
Expand Down Expand Up @@ -548,9 +554,10 @@ BitArray(A::AbstractArray{<:Any,N}) where {N} = convert(BitArray{N}, A)
"""
BitArray(itr)
Construct a `BitArray` generated by the given iterable object. The shape is inferred from
the `itr` object.
Construct a [`BitArray`](@ref) generated by the given iterable object.
The shape is inferred from the `itr` object.
# Examples
```jldoctest
julia> BitArray([1 0; 0 1])
2×2 BitArray{2}:
Expand Down
57 changes: 57 additions & 0 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2317,3 +2317,60 @@ for bit in (8, 16, 32, 64, 128)
$(Symbol("UInt", bit))
end
end

"""
Vector{T}(n)
Construct an uninitialized [`Vector{T}`](@ref) of length `n`.
# Examples
```julia-repl
julia> Vector{Float64}(3)
3-element Array{Float64,1}:
6.90966e-310
6.90966e-310
6.90966e-310
```
"""
Vector{T}(n)

"""
Matrix{T}(m, n)
Construct an uninitialized [`Matrix{T}`](@ref) of size `m`×`n`.
# Examples
```julia-repl
julia> Matrix{Float64}(2, 3)
2×3 Array{Float64,2}:
6.93517e-310 6.93517e-310 6.93517e-310
6.93517e-310 6.93517e-310 1.29396e-320
```
"""
Matrix{T}(m, n)

"""
Array{T}(dims)
Array{T,N}(dims)
Construct an uninitialized `N`-dimensional [`Array`](@ref)
containing elements of type `T`. `N` can either be supplied explicitly,
as in `Array{T,N}(dims)`, or be determined by the length or number of `dims`.
`dims` may be a tuple or a series of integer arguments corresponding to the lengths
in each dimension. If the rank `N` is supplied explicitly, then it must
match the length or number of `dims`.
# Examples
```julia-repl
julia> A = Array{Float64,2}(2, 3) # N given explicitly
2×3 Array{Float64,2}:
6.90198e-310 6.90198e-310 6.90198e-310
6.90198e-310 6.90198e-310 0.0
julia> B = Array{Float64}(2) # N determined by the input
2-element Array{Float64,1}:
1.87103e-320
0.0
```
"""
Array{T,N}(dims)
9 changes: 7 additions & 2 deletions doc/src/stdlib/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ Core.AbstractArray
Base.AbstractVector
Base.AbstractMatrix
Core.Array
Core.Array(::Any)
Base.Vector
Base.Vector(::Any)
Base.Matrix
Base.Matrix(::Any, ::Any)
Base.getindex(::Type, ::Any...)
Base.zeros
Base.ones
Base.BitArray
Base.BitArray(::Integer...)
Base.BitArray(::Any)
Base.trues
Base.falses
Base.fill
Expand Down Expand Up @@ -165,8 +170,8 @@ Base.reverse!

## BitArrays

`BitArray`s are space-efficient "packed" boolean arrays, which store one bit per boolean value.
They can be used similarly to `Array{Bool}` arrays (which store one byte per boolean value),
[`BitArray`](@ref)s are space-efficient "packed" boolean arrays, which store one bit per boolean value.
They can be used similarly to `Array{Bool}` arrays (which store one byte per boolean value),
and can be converted to/from the latter via `Array(bitarray)` and `BitArray(array)`, respectively.

```@docs
Expand Down

0 comments on commit 00e74c3

Please sign in to comment.