Skip to content

Commit 00e74c3

Browse files
fredrikekreKristofferC
authored andcommitted
separate type docs and constructor docs (#22690)
* Vector - docstring for constructor * Matrix - docstring for constructor * Array - split type and constructor docstring * BitArray - type documentation
1 parent fb666b1 commit 00e74c3

File tree

4 files changed

+83
-30
lines changed

4 files changed

+83
-30
lines changed

base/array.jl

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ const DimsOrInds{N} = NTuple{N,DimOrInd}
2626
const NeedsShaping = Union{Tuple{Integer,Vararg{Integer}}, Tuple{OneTo,Vararg{OneTo}}}
2727

2828
"""
29-
Vector{T}
29+
Array{T,N} <: AbstractArray{T,N}
30+
31+
`N`-dimensional dense array with elements of type `T`.
32+
"""
33+
Array
34+
35+
"""
36+
Vector{T} <: AbstractVector{T}
3037
3138
One-dimensional dense array with elements of type `T`, often used to represent
3239
a mathematical vector. Alias for [`Array{T,1}`](@ref).
3340
"""
3441
const Vector{T} = Array{T,1}
3542

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

7582
import Core: arraysize, arrayset, arrayref
7683

77-
"""
78-
Array{T}(dims)
79-
Array{T,N}(dims)
80-
81-
Construct an uninitialized `N`-dimensional dense array with element type `T`,
82-
where `N` is determined from the length or number of `dims`. `dims` may
83-
be a tuple or a series of integer arguments corresponding to the lengths in each dimension.
84-
If the rank `N` is supplied explicitly as in `Array{T,N}(dims)`, then it must
85-
match the length or number of `dims`.
86-
87-
# Examples
88-
```jldoctest
89-
julia> A = Array{Float64, 2}(2, 2);
90-
91-
julia> ndims(A)
92-
2
93-
94-
julia> eltype(A)
95-
Float64
96-
```
97-
"""
98-
Array
99-
10084
vect() = Array{Any,1}(0)
10185
vect(X::T...) where {T} = T[ X[i] for i = 1:length(X) ]
10286

base/bitarray.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
# notes: bits are stored in contiguous chunks
66
# unused bits must always be set to 0
7+
"""
8+
BitArray{N} <: DenseArray{Bool, N}
9+
10+
Space-efficient `N`-dimensional boolean array, which stores one bit per boolean value.
11+
"""
712
mutable struct BitArray{N} <: DenseArray{Bool, N}
813
chunks::Vector{UInt64}
914
len::Int
@@ -32,9 +37,10 @@ end
3237
BitArray(dims::Integer...)
3338
BitArray{N}(dims::NTuple{N,Int})
3439
35-
Construct an uninitialized `BitArray` with the given dimensions.
40+
Construct an uninitialized [`BitArray`](@ref) with the given dimensions.
3641
Behaves identically to the [`Array`](@ref) constructor.
3742
43+
# Examples
3844
```julia-repl
3945
julia> BitArray(2, 2)
4046
2×2 BitArray{2}:
@@ -548,9 +554,10 @@ BitArray(A::AbstractArray{<:Any,N}) where {N} = convert(BitArray{N}, A)
548554
"""
549555
BitArray(itr)
550556
551-
Construct a `BitArray` generated by the given iterable object. The shape is inferred from
552-
the `itr` object.
557+
Construct a [`BitArray`](@ref) generated by the given iterable object.
558+
The shape is inferred from the `itr` object.
553559
560+
# Examples
554561
```jldoctest
555562
julia> BitArray([1 0; 0 1])
556563
2×2 BitArray{2}:

base/docs/helpdb/Base.jl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,3 +2317,60 @@ for bit in (8, 16, 32, 64, 128)
23172317
$(Symbol("UInt", bit))
23182318
end
23192319
end
2320+
2321+
"""
2322+
Vector{T}(n)
2323+
2324+
Construct an uninitialized [`Vector{T}`](@ref) of length `n`.
2325+
2326+
# Examples
2327+
```julia-repl
2328+
julia> Vector{Float64}(3)
2329+
3-element Array{Float64,1}:
2330+
6.90966e-310
2331+
6.90966e-310
2332+
6.90966e-310
2333+
```
2334+
"""
2335+
Vector{T}(n)
2336+
2337+
"""
2338+
Matrix{T}(m, n)
2339+
2340+
Construct an uninitialized [`Matrix{T}`](@ref) of size `m`×`n`.
2341+
2342+
# Examples
2343+
```julia-repl
2344+
julia> Matrix{Float64}(2, 3)
2345+
2×3 Array{Float64,2}:
2346+
6.93517e-310 6.93517e-310 6.93517e-310
2347+
6.93517e-310 6.93517e-310 1.29396e-320
2348+
```
2349+
"""
2350+
Matrix{T}(m, n)
2351+
2352+
"""
2353+
Array{T}(dims)
2354+
Array{T,N}(dims)
2355+
2356+
Construct an uninitialized `N`-dimensional [`Array`](@ref)
2357+
containing elements of type `T`. `N` can either be supplied explicitly,
2358+
as in `Array{T,N}(dims)`, or be determined by the length or number of `dims`.
2359+
`dims` may be a tuple or a series of integer arguments corresponding to the lengths
2360+
in each dimension. If the rank `N` is supplied explicitly, then it must
2361+
match the length or number of `dims`.
2362+
2363+
# Examples
2364+
```julia-repl
2365+
julia> A = Array{Float64,2}(2, 3) # N given explicitly
2366+
2×3 Array{Float64,2}:
2367+
6.90198e-310 6.90198e-310 6.90198e-310
2368+
6.90198e-310 6.90198e-310 0.0
2369+
2370+
julia> B = Array{Float64}(2) # N determined by the input
2371+
2-element Array{Float64,1}:
2372+
1.87103e-320
2373+
0.0
2374+
```
2375+
"""
2376+
Array{T,N}(dims)

doc/src/stdlib/arrays.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ Core.AbstractArray
77
Base.AbstractVector
88
Base.AbstractMatrix
99
Core.Array
10+
Core.Array(::Any)
1011
Base.Vector
12+
Base.Vector(::Any)
1113
Base.Matrix
14+
Base.Matrix(::Any, ::Any)
1215
Base.getindex(::Type, ::Any...)
1316
Base.zeros
1417
Base.ones
1518
Base.BitArray
19+
Base.BitArray(::Integer...)
20+
Base.BitArray(::Any)
1621
Base.trues
1722
Base.falses
1823
Base.fill
@@ -165,8 +170,8 @@ Base.reverse!
165170

166171
## BitArrays
167172

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

172177
```@docs

0 commit comments

Comments
 (0)