diff --git a/base/array.jl b/base/array.jl index 56df3a1a45d42..f7dc11f1e0471 100644 --- a/base/array.jl +++ b/base/array.jl @@ -26,7 +26,14 @@ 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). @@ -34,7 +41,7 @@ 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). @@ -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) ] diff --git a/base/bitarray.jl b/base/bitarray.jl index 3a9014122a2f4..3b7c7b576ab3a 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -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 @@ -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}: @@ -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}: diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index 02e228114cd8e..32d1cd78accd5 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -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) diff --git a/doc/src/stdlib/arrays.md b/doc/src/stdlib/arrays.md index 692ac5387cbd6..dcc46529e9b6f 100644 --- a/doc/src/stdlib/arrays.md +++ b/doc/src/stdlib/arrays.md @@ -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 @@ -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