diff --git a/base/abstractdict.jl b/base/abstractdict.jl index 3b538817809ff..d4233f95782d8 100644 --- a/base/abstractdict.jl +++ b/base/abstractdict.jl @@ -90,15 +90,15 @@ return the elements in the same order. # Examples ```jldoctest -julia> a = Dict('a'=>2, 'b'=>3) +julia> D = Dict('a'=>2, 'b'=>3) Dict{Char,Int64} with 2 entries: - 'b' => 3 'a' => 2 + 'b' => 3 -julia> collect(keys(a)) +julia> collect(keys(D)) 2-element Array{Char,1}: - 'b' 'a' + 'b' ``` """ keys(a::AbstractDict) = KeySet(a) @@ -115,15 +115,15 @@ return the elements in the same order. # Examples ```jldoctest -julia> a = Dict('a'=>2, 'b'=>3) +julia> D = Dict('a'=>2, 'b'=>3) Dict{Char,Int64} with 2 entries: - 'b' => 3 'a' => 2 + 'b' => 3 -julia> collect(values(a)) +julia> collect(values(D)) 2-element Array{Int64,1}: - 3 2 + 3 ``` """ values(a::AbstractDict) = ValueIterator(a) diff --git a/base/array.jl b/base/array.jl index 668beb348ddfd..16c23f862ecfb 100644 --- a/base/array.jl +++ b/base/array.jl @@ -1523,8 +1523,7 @@ julia> A = [false, false, true, false] julia> findnext(A, 1) 3 -julia> findnext(A, 4) == nothing -true +julia> findnext(A, 4) # returns nothing, but not printed in the REPL julia> A = [false false; true false] 2×2 Array{Bool,2}: @@ -1575,8 +1574,7 @@ julia> A = [false, false, true, false] julia> findfirst(A) 3 -julia> findfirst(falses(3)) == nothing -true +julia> findfirst(falses(3)) # returns nothing, but not printed in the REPL julia> A = [false false; true false] 2×2 Array{Bool,2}: @@ -1615,23 +1613,14 @@ and [`pairs(A)`](@ref). # Examples ```jldoctest -A = [1, 4, 2, 2] -4-element Array{Int64,1}: - 1 - 4 - 2 - 2 +julia> A = [1, 4, 2, 2]; julia> findnext(isodd, A, 1) 1 -julia> findnext(isodd, A, 2) == nothing -true +julia> findnext(isodd, A, 2) # returns nothing, but not printed in the REPL -julia> A = [1 4; 2 2] -2×2 Array{Int64,2}: - 1 4 - 2 2 +julia> A = [1 4; 2 2]; julia> findnext(isodd, A, CartesianIndex(1, 1)) CartesianIndex(1, 1) @@ -1670,8 +1659,7 @@ julia> A = [1, 4, 2, 2] julia> findfirst(iseven, A) 2 -julia> findfirst(x -> x>10, A) == nothing -true +julia> findfirst(x -> x>10, A) # returns nothing, but not printed in the REPL julia> findfirst(equalto(4), A) 2 @@ -1717,8 +1705,7 @@ julia> A = [false, false, true, true] julia> findprev(A, 3) 3 -julia> findprev(A, 1) == nothing -true +julia> findprev(A, 1) # returns nothing, but not printed in the REPL julia> A = [false false; true true] 2×2 Array{Bool,2}: @@ -1767,8 +1754,7 @@ julia> findlast(A) julia> A = falses(2,2); -julia> findlast(A) == nothing -true +julia> findlast(A) # returns nothing, but not printed in the REPL julia> A = [true false; true false] 2×2 Array{Bool,2}: @@ -1814,8 +1800,7 @@ julia> A = [4, 6, 1, 2] 1 2 -julia> findprev(isodd, A, 1) == nothing -true +julia> findprev(isodd, A, 1) # returns nothing, but not printed in the REPL julia> findprev(isodd, A, 3) 3 @@ -1859,8 +1844,7 @@ julia> A = [1, 2, 3, 4] julia> findlast(isodd, A) 3 -julia> findlast(x -> x > 5, A) == nothing -true +julia> findlast(x -> x > 5, A) # returns nothing, but not printed in the REPL julia> A = [1 2; 3 4] 2×2 Array{Int64,2}: @@ -1965,9 +1949,9 @@ julia> A = [true false; false true] false true julia> findall(A) -2-element Array{Int64,1}: - 1 - 4 +2-element Array{CartesianIndex{2},1}: + CartesianIndex(1, 1) + CartesianIndex(2, 2) julia> findall(falses(3)) 0-element Array{Int64,1} @@ -2137,9 +2121,9 @@ array contains `nothing` wherever `a` is not a member of `b`. # Examples ```jldoctest -julia> a = ['a', 'b', 'c', 'b', 'd', 'a'] +julia> a = ['a', 'b', 'c', 'b', 'd', 'a']; -julia> b = ['a', 'b', 'c'] +julia> b = ['a', 'b', 'c']; julia> indexin(a, b) 6-element Array{Union{Nothing, Int64},1}: diff --git a/base/broadcast.jl b/base/broadcast.jl index f2c550c65aba9..f3210fca4ae8d 100644 --- a/base/broadcast.jl +++ b/base/broadcast.jl @@ -700,7 +700,7 @@ would be the broadcast `inds`). The shape of the output is equal to the shape of element of `indsb`. # Examples -```jldoctest +```jldoctest bc_getindex julia> A = [11 12; 21 22] 2×2 Array{Int64,2}: 11 12 @@ -729,7 +729,7 @@ julia> broadcast_getindex(A, 1:2, 2:-1:1) Because the indices are all vectors, these calls are like `[A[i[k], j[k]] for k = 1:2]` where `i` and `j` are the two index vectors. -```jldoctest +```jldoctest bc_getindex julia> broadcast_getindex(A, 1:2, (1:2)') 2×2 Array{Int64,2}: 11 12 diff --git a/base/dict.jl b/base/dict.jl index b967e957baaf4..eacbbb2b0bf44 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -530,15 +530,15 @@ end Determine whether a collection has a mapping for a given key. ```jldoctest -julia> a = Dict('a'=>2, 'b'=>3) +julia> D = Dict('a'=>2, 'b'=>3) Dict{Char,Int64} with 2 entries: - 'b' => 3 'a' => 2 + 'b' => 3 -julia> haskey(a,'a') +julia> haskey(D, 'a') true -julia> haskey(a,'c') +julia> haskey(D, 'c') false ``` """ @@ -551,15 +551,15 @@ in(key, v::KeySet{<:Any, <:Dict}) = (ht_keyindex(v.dict, key) >= 0) Return the key matching argument `key` if one exists in `collection`, otherwise return `default`. ```jldoctest -julia> a = Dict('a'=>2, 'b'=>3) +julia> D = Dict('a'=>2, 'b'=>3) Dict{Char,Int64} with 2 entries: - 'b' => 3 'a' => 2 + 'b' => 3 -julia> getkey(a,'a',1) +julia> getkey(D, 'a', 1) 'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase) -julia> getkey(a,'d','a') +julia> getkey(D, 'd', 'a') 'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase) ``` """ diff --git a/base/docs/basedocs.jl b/base/docs/basedocs.jl index 673a098d1c69a..454d8fd3dbf34 100644 --- a/base/docs/basedocs.jl +++ b/base/docs/basedocs.jl @@ -924,25 +924,28 @@ OutOfMemoryError An indexing operation into an array, `a`, tried to access an out-of-bounds element at index `i`. # Examples -```jldoctest +```jldoctest; filter = r"Stacktrace:(\\n \\[[0-9]+\\].*)*" julia> A = fill(1.0, 7); julia> A[8] ERROR: BoundsError: attempt to access 7-element Array{Float64,1} at index [8] Stacktrace: - [1] getindex(::Array{Float64,1}, ::Int64) at ./array.jl:758 + [1] getindex(::Array{Float64,1}, ::Int64) at ./array.jl:660 + [2] top-level scope julia> B = fill(1.0, (2,3)); julia> B[2, 4] ERROR: BoundsError: attempt to access 2×3 Array{Float64,2} at index [2, 4] Stacktrace: - [1] getindex(::Array{Float64,2}, ::Int64, ::Int64) at ./array.jl:759 + [1] getindex(::Array{Float64,2}, ::Int64, ::Int64) at ./array.jl:661 + [2] top-level scope julia> B[9] ERROR: BoundsError: attempt to access 2×3 Array{Float64,2} at index [9] Stacktrace: - [1] getindex(::Array{Float64,2}, ::Int64) at ./array.jl:758 + [1] getindex(::Array{Float64,2}, ::Int64) at ./array.jl:660 + [2] top-level scope ``` """ BoundsError @@ -955,9 +958,9 @@ Cannot exactly convert `val` to type `T` in a method of function `name`. # Examples ```jldoctest julia> convert(Float64, 1+2im) -ERROR: InexactError: convert(Float64, 1 + 2im) +ERROR: InexactError: Float64(Float64, 1 + 2im) Stacktrace: - [1] convert(::Type{Float64}, ::Complex{Int64}) at ./complex.jl:37 +[...] ``` """ InexactError diff --git a/base/essentials.jl b/base/essentials.jl index 6ead9541b318e..b05fb0f5cb9d4 100644 --- a/base/essentials.jl +++ b/base/essentials.jl @@ -84,9 +84,9 @@ julia> convert(Int, 3.0) 3 julia> convert(Int, 3.5) -ERROR: InexactError: convert(Int64, 3.5) +ERROR: InexactError: Int64(Int64, 3.5) Stacktrace: - [1] convert(::Type{Int64}, ::Float64) at ./float.jl:703 +[...] ``` If `T` is a [`AbstractFloat`](@ref) or [`Rational`](@ref) type, @@ -414,22 +414,24 @@ Annotates the expression `blk` as a bounds checking block, allowing it to be eli its caller in order for `@inbounds` to have effect. # Examples -```jldoctest +```jldoctest; filter = r"Stacktrace:(\\n \\[[0-9]+\\].*)*" julia> @inline function g(A, i) @boundscheck checkbounds(A, i) return "accessing (\$A)[\$i]" - end - f1() = return g(1:2, -1) - f2() = @inbounds return g(1:2, -1) -f2 (generic function with 1 method) + end; + +julia> f1() = return g(1:2, -1); + +julia> f2() = @inbounds return g(1:2, -1); julia> f1() ERROR: BoundsError: attempt to access 2-element UnitRange{Int64} at index [-1] Stacktrace: - [1] throw_boundserror(::UnitRange{Int64}, ::Tuple{Int64}) at ./abstractarray.jl:435 - [2] checkbounds at ./abstractarray.jl:399 [inlined] + [1] throw_boundserror(::UnitRange{Int64}, ::Tuple{Int64}) at ./abstractarray.jl:455 + [2] checkbounds at ./abstractarray.jl:420 [inlined] [3] g at ./none:2 [inlined] [4] f1() at ./none:1 + [5] top-level scope julia> f2() "accessing (1:2)[-1]" diff --git a/base/floatfuncs.jl b/base/floatfuncs.jl index 09c70c7fe27e5..249c4ee4204fd 100644 --- a/base/floatfuncs.jl +++ b/base/floatfuncs.jl @@ -90,7 +90,7 @@ julia> round(pi, 3, base = 2) rounded to 1.2. # Examples - ```jldoctest + ```jldoctest; setup = :(using Printf) julia> x = 1.15 1.15 diff --git a/base/io.jl b/base/io.jl index 6f1ed0b654b77..6fc3dde5f0209 100644 --- a/base/io.jl +++ b/base/io.jl @@ -315,9 +315,9 @@ julia> open("my_file.txt", "w") do io 57 julia> readuntil("my_file.txt", 'L') -"JuliaL" +"Julia" -julia> readuntil("my_file.txt", '.') +julia> readuntil("my_file.txt", '.', keep = true) "JuliaLang is a GitHub organization." julia> rm("my_file.txt") @@ -1003,7 +1003,7 @@ end with the EOL, matching the length returned by [`eachline`](@ref) and [`readl # Examples ```jldoctest -julia> io = IOBuffer("JuliaLang is a GitHub organization.\n"); +julia> io = IOBuffer("JuliaLang is a GitHub organization.\\n"); julia> countlines(io) 1 @@ -1014,7 +1014,7 @@ julia> countlines(io) 1 julia> countlines(io, eol = '.') -1 +0 ``` """ function countlines(io::IO; eol::Char='\n') diff --git a/base/iostream.jl b/base/iostream.jl index 611a8bc303b56..b8de905c101c9 100644 --- a/base/iostream.jl +++ b/base/iostream.jl @@ -48,7 +48,7 @@ iswritable(s::IOStream) = ccall(:ios_get_writable, Cint, (Ptr{Cvoid},), s.ios)!= isreadable(s::IOStream) = ccall(:ios_get_readable, Cint, (Ptr{Cvoid},), s.ios)!=0 """ - truncate(file,n) + truncate(file, n) Resize the file or buffer given by the first argument to exactly `n` bytes, filling previously unallocated space with '\\0' if the file or buffer is grown. @@ -73,7 +73,7 @@ julia> write(io, "JuliaLang is a GitHub organization."); julia> truncate(io, 40); julia> String(take!(io)) -"JuliaLang is a GitHub organization.\0\0\0\0\0" +"JuliaLang is a GitHub organization.\\0\\0\\0\\0\\0" ``` """ function truncate(s::IOStream, n::Integer) @@ -354,8 +354,8 @@ descriptor upon completion. # Examples ```jldoctest julia> open("myfile.txt", "w") do io - write(io, "Hello world!"); - end + write(io, "Hello world!") + end; julia> open(f->read(f, String), "myfile.txt") "Hello world!" diff --git a/base/iterators.jl b/base/iterators.jl index 817c699f26f9c..9ddec3c59f5db 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -376,7 +376,7 @@ See [`Base.filter`](@ref) for an eager implementation of filtering for arrays. # Examples ```jldoctest julia> f = Iterators.filter(isodd, [1, 2, 3, 4, 5]) -Base.Iterators.Filter{Base.#isodd,Array{Int64,1}}(isodd, [1, 2, 3, 4, 5]) +Base.Iterators.Filter{typeof(isodd),Array{Int64,1}}(isodd, [1, 2, 3, 4, 5]) julia> foreach(println, f) 1 diff --git a/base/meta.jl b/base/meta.jl index 36683fc569930..62b7b89a2dde9 100644 --- a/base/meta.jl +++ b/base/meta.jl @@ -152,7 +152,7 @@ julia> Meta.parse("x = ") :($(Expr(:incomplete, "incomplete: premature end of input"))) julia> Meta.parse("1.0.2") -ERROR: ParseError("invalid numeric constant \\\"1.0.\\\"") +ERROR: Base.Meta.ParseError("invalid numeric constant \\\"1.0.\\\"") Stacktrace: [...] diff --git a/base/missing.jl b/base/missing.jl index 7ca2c9373bbf1..95d40f3eea3ec 100644 --- a/base/missing.jl +++ b/base/missing.jl @@ -159,14 +159,13 @@ julia> sum(skipmissing([1, missing, 2])) julia> collect(skipmissing([1, missing, 2])) 2-element Array{Int64,1}: -1 -2 + 1 + 2 julia> collect(skipmissing([1 missing; 2 missing])) 2-element Array{Int64,1}: -1 -2 - + 1 + 2 ``` """ skipmissing(itr) = SkipMissing(itr) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 66c3e255adf48..130330f67bbe3 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -191,8 +191,8 @@ module IteratorsMD julia> CartesianIndices(fill(1, (2,3))) 2×3 CartesianIndices{2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}: - CartesianIndex(1, 1) CartesianIndex(1, 2) CartesianIndex(1, 3) - CartesianIndex(2, 1) CartesianIndex(2, 2) CartesianIndex(2, 3) + CartesianIndex(1, 1) CartesianIndex(1, 2) CartesianIndex(1, 3) + CartesianIndex(2, 1) CartesianIndex(2, 2) CartesianIndex(2, 3) ``` ## Conversion between linear and cartesian indices @@ -391,9 +391,9 @@ module IteratorsMD ```jldoctest subarray julia> linear = LinearIndices(1:3,1:2) LinearIndices{2,Tuple{UnitRange{Int64},UnitRange{Int64}}} with indices 1:3×1:2: - 1 4 - 2 5 - 3 6 + 1 4 + 2 5 + 3 6 julia> linear[1,2] 4 @@ -861,9 +861,9 @@ julia> cumprod(fill(1//2, 3)) julia> cumprod([fill(1//3, 2, 2) for i in 1:3]) 3-element Array{Array{Rational{Int64},2},1}: - Rational{Int64}[1//3 1//3; 1//3 1//3] - Rational{Int64}[2//9 2//9; 2//9 2//9] - Rational{Int64}[4//27 4//27; 4//27 4//27] + [1//3 1//3; 1//3 1//3] + [2//9 2//9; 2//9 2//9] + [4//27 4//27; 4//27 4//27] ``` """ cumprod(x::AbstractVector) = cumprod(x, dims=1) diff --git a/base/operators.jl b/base/operators.jl index d5e052a2dc76d..e918dcec16627 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -362,7 +362,6 @@ julia> cmp(2, 1) julia> cmp(2+im, 3-im) ERROR: MethodError: no method matching isless(::Complex{Int64}, ::Complex{Int64}) -Stacktrace: [...] ``` """ diff --git a/base/permuteddimsarray.jl b/base/permuteddimsarray.jl index 4a82f4670bf9d..de9c8c1944d7b 100644 --- a/base/permuteddimsarray.jl +++ b/base/permuteddimsarray.jl @@ -121,7 +121,7 @@ the matrix. Differs from `LinearAlgebra`'s [`transpose`](@ref) in that the operation is not recursive. # Examples -```jldoctest +```jldoctest; setup = :(using LinearAlgebra) julia> a = [1 2; 3 4]; julia> b = [5 6; 7 8]; @@ -141,7 +141,7 @@ julia> permutedims(X) [5 6; 7 8] [13 14; 15 16] julia> transpose(X) -2×2 LinearAlgebra.Transpose{LinearAlgebra.Transpose{Int64,Array{Int64,2}},Array{Array{Int64,2},2}}: +2×2 Transpose{Transpose{Int64,Array{Int64,2}},Array{Array{Int64,2},2}}: [1 3; 2 4] [9 11; 10 12] [5 7; 6 8] [13 15; 14 16] ``` @@ -156,7 +156,7 @@ Differs from `LinearAlgebra`'s [`transpose`](@ref) in that the operation is not recursive. # Examples -```jldoctest +```jldoctest; setup = :(using LinearAlgebra) julia> permutedims([1, 2, 3, 4]) 1×4 Array{Int64,2}: 1 2 3 4 @@ -171,7 +171,7 @@ julia> permutedims(V) [1 2; 3 4] [5 6; 7 8] julia> transpose(V) -1×2 LinearAlgebra.Transpose{LinearAlgebra.Transpose{Int64,Array{Int64,2}},Array{Array{Int64,2},1}}: +1×2 Transpose{Transpose{Int64,Array{Int64,2}},Array{Array{Int64,2},1}}: [1 3; 2 4] [5 7; 6 8] ``` """ diff --git a/base/show.jl b/base/show.jl index f8f83b7d9f25e..3ae04fe14b0fa 100644 --- a/base/show.jl +++ b/base/show.jl @@ -236,7 +236,7 @@ julia> io = IOBuffer(); julia> printstyled(IOContext(io, :color => true), "string", color=:red) julia> String(take!(io)) -"\e[31mstring\e[39m" +"\\e[31mstring\\e[39m" julia> printstyled(io, "string", color=:red) @@ -823,7 +823,7 @@ operators. Return `0` if `s` is not a valid operator. # Examples ```jldoctest julia> Base.operator_precedence(:+), Base.operator_precedence(:*), Base.operator_precedence(:.) -(9, 11, 15) +(11, 13, 17) julia> Base.operator_precedence(:sin), Base.operator_precedence(:+=), Base.operator_precedence(:(=)) # (Note the necessary parens on `:(=)`) (0, 1, 1) diff --git a/base/some.jl b/base/some.jl index 1c066bc5f0768..f75a493d91703 100644 --- a/base/some.jl +++ b/base/some.jl @@ -51,8 +51,7 @@ julia> coalesce(missing, 1) julia> coalesce(1, nothing) 1 -julia> coalesce(nothing, nothing) -nothing +julia> coalesce(nothing, nothing) # returns nothing, but not printed in the REPL julia> coalesce(Some(1)) 1 diff --git a/base/stat.jl b/base/stat.jl index fc1e3c399c7f2..1f5aca7921864 100644 --- a/base/stat.jl +++ b/base/stat.jl @@ -207,7 +207,7 @@ julia> f = open("test_file.txt", "w"); julia> isfile(f) true -julia> close(f) +julia> close(f); rm("test_file.txt") ``` """ isfile(st::StatStruct) = filemode(st) & 0xf000 == 0x8000 diff --git a/base/strings/basic.jl b/base/strings/basic.jl index 50091f5f11049..8b41bbff31be5 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -113,7 +113,7 @@ julia> isvalid(str, 2) false julia> str[2] -ERROR: StringIndexError: invalid character index +ERROR: StringIndexError("αβγdef", 2) Stacktrace: [...] ``` @@ -410,7 +410,10 @@ julia> prevind("αβγdef", 1) 0 julia> prevind("αβγdef", 0) --1 +ERROR: BoundsError: attempt to access "αβγdef" + at index [0] +Stacktrace: +[...] julia> prevind("αβγdef", 3, 2) 0 diff --git a/base/strings/search.jl b/base/strings/search.jl index 2b3c0633e07f3..72e434d1f96f6 100644 --- a/base/strings/search.jl +++ b/base/strings/search.jl @@ -244,8 +244,8 @@ julia> findnext("z", "Hello to the world", 1) julia> findnext("o", "Hello to the world", 6) 8:8 -julia> findnext("Julia", "JuliaLang", 2) -1:5 +julia> findnext("Lang", "JuliaLang", 2) +6:9 ``` """ findnext(t::AbstractString, s::AbstractString, i::Integer) = _search(s, t, i) diff --git a/base/strings/util.jl b/base/strings/util.jl index 397613e57f271..eff5dc9f36247 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -455,7 +455,7 @@ julia> hex2bytes(s) 0x39 julia> a = b"01abEF" -6-element Array{UInt8,1}: +6-element Base.CodeUnits{UInt8,String}: 0x30 0x31 0x61 diff --git a/doc/src/base/arrays.md b/doc/src/base/arrays.md index 402ebab2d4da8..11b3c6dbb7b2d 100644 --- a/doc/src/base/arrays.md +++ b/doc/src/base/arrays.md @@ -138,7 +138,7 @@ Base.promote_shape ## Array functions ```@docs -Base.accumulate(::Any, ::Any, ::Integer) +Base.accumulate Base.accumulate! Base.cumprod Base.cumprod! @@ -149,8 +149,6 @@ Base.repeat Base.rot180 Base.rotl90 Base.rotr90 -Base.reducedim -Base.mapreducedim Base.mapslices ``` diff --git a/doc/src/base/collections.md b/doc/src/base/collections.md index 43ba36a803bf2..cdc77c296de43 100644 --- a/doc/src/base/collections.md +++ b/doc/src/base/collections.md @@ -88,20 +88,16 @@ Base.foldl(::Any, ::Any, ::Any) Base.foldl(::Any, ::Any) Base.foldr(::Any, ::Any, ::Any) Base.foldr(::Any, ::Any) -Base.maximum(::Any) -Base.maximum(::Any, ::Any) +Base.maximum Base.maximum! -Base.minimum(::Any) -Base.minimum(::Any, ::Any) +Base.minimum Base.minimum! Base.extrema(::Any) Base.extrema(::AbstractArray, ::Any) Base.argmax Base.argmin -Base.findmax(::Any) -Base.findmax(::AbstractArray, ::Any) -Base.findmin(::Any) -Base.findmin(::AbstractArray, ::Any) +Base.findmax +Base.findmin Base.findmax! Base.findmin! Base.sum diff --git a/doc/src/base/io-network.md b/doc/src/base/io-network.md index c99684c3bd698..9c0cf8161da23 100644 --- a/doc/src/base/io-network.md +++ b/doc/src/base/io-network.md @@ -94,7 +94,7 @@ Base.Multimedia.redisplay Base.Multimedia.displayable Base.show(::Any, ::Any, ::Any) Base.Multimedia.showable -Base.repr(::Any, ::Any) +Base.repr(::MIME, ::Any) ``` As mentioned above, one can also define new display backends. For example, a module that can display diff --git a/doc/src/devdocs/reflection.md b/doc/src/devdocs/reflection.md index d664ef0aeb92d..23ff13b919b1d 100644 --- a/doc/src/devdocs/reflection.md +++ b/doc/src/devdocs/reflection.md @@ -11,7 +11,7 @@ returns symbols for all bindings in `m`, regardless of export status. ## DataType fields The names of `DataType` fields may be interrogated using [`fieldnames`](@ref). For example, -given the following type, `fieldnames(Point)` returns an arrays of [`Symbol`](@ref) elements representing +given the following type, `fieldnames(Point)` returns a tuple of [`Symbol`](@ref)s representing the field names: ```jldoctest struct_point @@ -21,9 +21,7 @@ julia> struct Point end julia> fieldnames(Point) -2-element Array{Symbol,1}: - :x - :y +(:x, :y) ``` The type of each field in a `Point` object is stored in the `types` field of the `Point` variable @@ -52,9 +50,9 @@ of these fields is the `types` field observed in the example above. The *direct* subtypes of any `DataType` may be listed using [`subtypes`](@ref). For example, the abstract `DataType` [`AbstractFloat`](@ref) has four (concrete) subtypes: -```jldoctest +```jldoctest; setup = :(using InteractiveUtils) julia> subtypes(AbstractFloat) -4-element Array{Union{DataType, UnionAll},1}: +4-element Array{Any,1}: BigFloat Float16 Float32 @@ -83,9 +81,9 @@ the unquoted and interpolated expression (`Expr`) form for a given macro. To use `quote` the expression block itself (otherwise, the macro will be evaluated and the result will be passed instead!). For example: -```jldoctest +```jldoctest; setup = :(using InteractiveUtils) julia> macroexpand(@__MODULE__, :(@edit println("")) ) -:((Base.edit)(println, (Base.typesof)(""))) +:((InteractiveUtils.edit)(println, (Base.typesof)(""))) ``` The functions `Base.Meta.show_sexpr` and [`dump`](@ref) are used to display S-expr style views @@ -97,14 +95,18 @@ and variable assignments: ```jldoctest julia> Meta.lower(@__MODULE__, :(f() = 1) ) -:(begin - $(Expr(:method, :f)) - $(Expr(:method, :f, :((Core.svec)((Core.svec)((Core.Typeof)(f)), (Core.svec)())), CodeInfo(:(begin - #= none:1 =# - return 1 - end)), false)) - return f - end) +:($(Expr(:thunk, CodeInfo(:(begin + $(Expr(:method, :f)) + Core.SSAValue(0) = (Core.Typeof)(f) + Core.SSAValue(1) = (Core.svec)(Core.SSAValue(0)) + Core.SSAValue(2) = (Core.svec)() + Core.SSAValue(3) = (Core.svec)(Core.SSAValue(1), Core.SSAValue(2)) + $(Expr(:method, :f, Core.SSAValue(3), CodeInfo(:(begin + #= none:1 =# + return 1 + end)))) + return f + end))))) ``` ## Intermediate and compiled representations diff --git a/doc/src/index.md b/doc/src/index.md index f7e5765a4bfb7..dba35ba7a1b56 100644 --- a/doc/src/index.md +++ b/doc/src/index.md @@ -79,7 +79,7 @@ Please read the [release notes](NEWS.md) to see what has changed since the last * [Base64](@ref) * [CRC32c](@ref) * [SHA](@ref) - * [Dates](@ref stdlib-dates) + * [Dates](@ref) * [Delimited Files](@ref) * [Distributed Computing](@ref) * [File Events](@ref lib-filewatching) @@ -114,7 +114,7 @@ Please read the [release notes](NEWS.md) to see what has changed since the last * [printf() and stdio in the Julia runtime](@ref) * [Bounds checking](@ref) * [Proper maintenance and care of multi-threading locks](@ref) - * [Arrays with custom indices](@ref) + * [Arrays with custom indices](@ref man-custom-indices) * [Module loading](@ref) * [Inference](@ref) * Developing/debugging Julia's C code diff --git a/doc/src/manual/arrays.md b/doc/src/manual/arrays.md index 09ca6a3af90b1..28f2c51f17a45 100644 --- a/doc/src/manual/arrays.md +++ b/doc/src/manual/arrays.md @@ -661,8 +661,8 @@ it also handles tuples and treats any argument that is not an array, tuple or [` ```jldoctest julia> convert.(Float32, [1, 2]) 2-element Array{Float32,1}: - 1.0f0 - 2.0f0 + 1.0 + 2.0 julia> ceil.((UInt8,), [1.2 3.4; 5.6 6.7]) 2×2 Array{UInt8,2}: diff --git a/doc/src/manual/complex-and-rational-numbers.md b/doc/src/manual/complex-and-rational-numbers.md index ebb7a0617f429..9f49aa0901139 100644 --- a/doc/src/manual/complex-and-rational-numbers.md +++ b/doc/src/manual/complex-and-rational-numbers.md @@ -37,7 +37,7 @@ julia> (-1 + 2im)^2 -3 - 4im julia> (-1 + 2im)^2.5 -2.7296244647840084 - 6.960664459571898im +2.729624464784009 - 6.9606644595719im julia> (-1 + 2im)^(1 + 1im) -0.27910381075826657 + 0.08708053414102428im diff --git a/doc/src/manual/constructors.md b/doc/src/manual/constructors.md index 153d6e35f8938..8ee79ea5ceaa9 100644 --- a/doc/src/manual/constructors.md +++ b/doc/src/manual/constructors.md @@ -97,14 +97,16 @@ julia> struct OrderedPair Now `OrderedPair` objects can only be constructed such that `x <= y`: -```jldoctest pairtype +```jldoctest pairtype; filter = r"Stacktrace:(\n \[[0-9]+\].*)*" julia> OrderedPair(1, 2) OrderedPair(1, 2) julia> OrderedPair(2,1) ERROR: out of order Stacktrace: - [1] OrderedPair(::Int64, ::Int64) at ./none:4 + [1] error at ./error.jl:33 [inlined] + [2] OrderedPair(::Int64, ::Int64) at ./none:4 + [3] top-level scope ``` If the type were declared `mutable`, you could reach in and directly change the field values to @@ -277,7 +279,7 @@ that, by default, instances of parametric composite types can be constructed eit given type parameters or with type parameters implied by the types of the arguments given to the constructor. Here are some examples: -```jldoctest parametric +```jldoctest parametric; filter = r"Closest candidates.*\n .*" julia> struct Point{T<:Real} x::T y::T @@ -292,16 +294,15 @@ Point{Float64}(1.0, 2.5) julia> Point(1,2.5) ## implicit T ## ERROR: MethodError: no method matching Point(::Int64, ::Float64) Closest candidates are: - Point(::T<:Real, !Matched::T<:Real) where T<:Real at none:2 + Point(::T<:Real, ::T<:Real) where T<:Real at none:2 julia> Point{Int64}(1, 2) ## explicit T ## Point{Int64}(1, 2) julia> Point{Int64}(1.0,2.5) ## explicit T ## -ERROR: InexactError: convert(Int64, 2.5) +ERROR: InexactError: Int64(Int64, 2.5) Stacktrace: - [1] convert at ./float.jl:703 [inlined] - [2] Point{Int64}(::Float64, ::Float64) at ./none:2 +[...] julia> Point{Float64}(1.0, 2.5) ## explicit T ## Point{Float64}(1.0, 2.5) @@ -502,7 +503,7 @@ julia> typeof(z) <: Complex{OurRational} false ``` -Thus, although the [`⊘`](@ref) operator usually returns an instance of `OurRational`, if either +Thus, although the `⊘` operator usually returns an instance of `OurRational`, if either of its arguments are complex integers, it will return an instance of `Complex{OurRational}` instead. The interested reader should consider perusing the rest of [`rational.jl`](https://github.com/JuliaLang/julia/blob/master/base/rational.jl): it is short, self-contained, and implements an entire basic Julia type. diff --git a/doc/src/manual/control-flow.md b/doc/src/manual/control-flow.md index 18dd9828087cb..5d38a7f4fdfa1 100644 --- a/doc/src/manual/control-flow.md +++ b/doc/src/manual/control-flow.md @@ -124,7 +124,7 @@ The variable `relation` is declared inside the `if` block, but used outside. How on this behavior, make sure all possible code paths define a value for the variable. The following change to the above function results in a runtime error -```jldoctest +```jldoctest; filter = r"Stacktrace:(\n \[[0-9]+\].*)*" julia> function test(x,y) if x < y relation = "less than" @@ -315,7 +315,7 @@ one can write ` || ` (which could be read as: *or else* For example, a recursive factorial routine could be defined like this: -```jldoctest +```jldoctest; filter = r"Stacktrace:(\n \[[0-9]+\].*)*" julia> function fact(n::Int) n >= 0 || error("n must be non-negative") n == 0 && return 1 @@ -332,7 +332,9 @@ julia> fact(0) julia> fact(-1) ERROR: n must be non-negative Stacktrace: - [1] fact(::Int64) at ./none:2 + [1] error at ./error.jl:33 [inlined] + [2] fact(::Int64) at ./none:2 + [3] top-level scope ``` Boolean operations *without* short-circuit evaluation can be done with the bitwise boolean operators @@ -589,7 +591,7 @@ Exceptions can be created explicitly with [`throw`](@ref). For example, a functi for nonnegative numbers could be written to [`throw`](@ref) a [`DomainError`](@ref) if the argument is negative: -```jldoctest +```jldoctest; filter = r"Stacktrace:(\n \[[0-9]+\].*)*" julia> f(x) = x>=0 ? exp(-x) : throw(DomainError(x, "argument must be nonnegative")) f (generic function with 1 method) @@ -652,7 +654,7 @@ Suppose we want to stop execution immediately if the square root of a negative n To do this, we can define a fussy version of the [`sqrt`](@ref) function that raises an error if its argument is negative: -```jldoctest fussy_sqrt +```jldoctest fussy_sqrt; filter = r"Stacktrace:(\n \[[0-9]+\].*)*" julia> fussy_sqrt(x) = x >= 0 ? sqrt(x) : error("negative x not allowed") fussy_sqrt (generic function with 1 method) @@ -662,14 +664,16 @@ julia> fussy_sqrt(2) julia> fussy_sqrt(-1) ERROR: negative x not allowed Stacktrace: - [1] fussy_sqrt(::Int64) at ./none:1 + [1] error at ./error.jl:33 [inlined] + [2] fussy_sqrt(::Int64) at ./none:1 + [3] top-level scope ``` If `fussy_sqrt` is called with a negative value from another function, instead of trying to continue execution of the calling function, it returns immediately, displaying the error message in the interactive session: -```jldoctest fussy_sqrt +```jldoctest fussy_sqrt; filter = r"Stacktrace:(\n \[[0-9]+\].*)*" julia> function verbose_fussy_sqrt(x) println("before fussy_sqrt") r = fussy_sqrt(x) @@ -687,8 +691,10 @@ julia> verbose_fussy_sqrt(-1) before fussy_sqrt ERROR: negative x not allowed Stacktrace: - [1] fussy_sqrt at ./none:1 [inlined] - [2] verbose_fussy_sqrt(::Int64) at ./none:3 + [1] error at ./error.jl:33 [inlined] + [2] fussy_sqrt at ./none:1 [inlined] + [3] verbose_fussy_sqrt(::Int64) at ./none:3 + [4] top-level scope ``` ### The `try/catch` statement diff --git a/doc/src/manual/conversion-and-promotion.md b/doc/src/manual/conversion-and-promotion.md index b824c97b6b015..7345334714953 100644 --- a/doc/src/manual/conversion-and-promotion.md +++ b/doc/src/manual/conversion-and-promotion.md @@ -88,7 +88,8 @@ doesn't know how to perform the requested conversion: ```jldoctest julia> convert(AbstractFloat, "foo") -ERROR: MethodError: Cannot `convert` an object of type String to an object of type AbstractFloat. +ERROR: MethodError: Cannot `convert` an object of type String to an object of type AbstractFloat +[...] ``` Some languages consider parsing strings as numbers or formatting numbers as strings to be conversions diff --git a/doc/src/manual/faq.md b/doc/src/manual/faq.md index fe8ca94e66d2a..da681180598be 100644 --- a/doc/src/manual/faq.md +++ b/doc/src/manual/faq.md @@ -147,18 +147,18 @@ argument is called slurping: ```jldoctest julia> function printargs(args...) - @printf("%s\n", typeof(args)) + println(typeof(args)) for (i, arg) in enumerate(args) - @printf("Arg %d = %s\n", i, arg) + println("Arg #$i = $arg") end end printargs (generic function with 1 method) julia> printargs(1, 2, 3) Tuple{Int64,Int64,Int64} -Arg 1 = 1 -Arg 2 = 2 -Arg 3 = 3 +Arg #1 = 1 +Arg #2 = 2 +Arg #3 = 3 ``` If Julia were a language that made more liberal use of ASCII characters, the slurping operator @@ -173,19 +173,19 @@ call. This use of `...` is called splatting: ```jldoctest julia> function threeargs(a, b, c) - @printf("a = %s::%s\n", a, typeof(a)) - @printf("b = %s::%s\n", b, typeof(b)) - @printf("c = %s::%s\n", c, typeof(c)) + println("a = $a::$(typeof(a))") + println("b = $b::$(typeof(b))") + println("c = $c::$(typeof(c))") end threeargs (generic function with 1 method) -julia> vec = [1, 2, 3] +julia> x = [1, 2, 3] 3-element Array{Int64,1}: 1 2 3 -julia> threeargs(vec...) +julia> threeargs(x...) a = 1::Int64 b = 2::Int64 c = 3::Int64 diff --git a/doc/src/manual/functions.md b/doc/src/manual/functions.md index db16602cca700..5779954cb6050 100644 --- a/doc/src/manual/functions.md +++ b/doc/src/manual/functions.md @@ -129,9 +129,12 @@ A return type can also be specified in the function declaration using the `::` o the return value to the specified type. ```jldoctest -function g(x,y)::Int8 - return x * y -end +julia> function g(x, y)::Int8 + return x * y + end; + +julia> typeof(g(1, 2)) +Int8 ``` This function will always return an `Int8` regardless of the types of `x` and `y`. diff --git a/doc/src/manual/index.md b/doc/src/manual/index.md index 5d776d5dbf22e..148d5e021ea54 100644 --- a/doc/src/manual/index.md +++ b/doc/src/manual/index.md @@ -22,7 +22,7 @@ * [Missing Values](@ref missing) * [Networking and Streams](@ref) * [Parallel Computing](@ref) - * [Date and DateTime](@ref) + * [Dates](@ref) * [Running External Programs](@ref) * [Calling C and Fortran Code](@ref) * [Handling Operating System Variation](@ref) diff --git a/doc/src/manual/interfaces.md b/doc/src/manual/interfaces.md index 9dd11fe22ef4b..2349da948f253 100644 --- a/doc/src/manual/interfaces.md +++ b/doc/src/manual/interfaces.md @@ -189,6 +189,7 @@ valid index. It is recommended to also define [`firstindex`](@ref) to specify th ```jldoctest squaretype julia> Base.firstindex(S::Squares) = 1 + julia> Base.lastindex(S::Squares) = length(S) julia> Squares(23)[end] @@ -400,7 +401,8 @@ julia> mean(A) If you are defining an array type that allows non-traditional indexing (indices that start at something other than 1), you should specialize `indices`. You should also specialize [`similar`](@ref) so that the `dims` argument (ordinarily a `Dims` size-tuple) can accept `AbstractUnitRange` objects, -perhaps range-types `Ind` of your own design. For more information, see [Arrays with custom indices](@ref). +perhaps range-types `Ind` of your own design. For more information, see +[Arrays with custom indices](@ref man-custom-indices). ## [Strided Arrays](@id man-interface-strided-arrays) @@ -505,7 +507,7 @@ However, if needed you can specialize on any or all of these arguments. For a complete example, let's say you have created a type, `ArrayAndChar`, that stores an array and a single character: -```jldoctest +```jldoctest ArrayAndChar struct ArrayAndChar{T,N} <: AbstractArray{T,N} data::Array{T,N} char::Char @@ -514,16 +516,20 @@ Base.size(A::ArrayAndChar) = size(A.data) Base.getindex(A::ArrayAndChar{T,N}, inds::Vararg{Int,N}) where {T,N} = A.data[inds...] Base.setindex!(A::ArrayAndChar{T,N}, val, inds::Vararg{Int,N}) where {T,N} = A.data[inds...] = val Base.showarg(io::IO, A::ArrayAndChar, toplevel) = print(io, typeof(A), " with char '", A.char, "'") +# output + ``` You might want broadcasting to preserve the `char` "metadata." First we define -```jldoctest +```jldoctest ArrayAndChar Base.BroadcastStyle(::Type{<:ArrayAndChar}) = Broadcast.ArrayStyle{ArrayAndChar}() +# output + ``` This forces us to also define a `broadcast_similar` method: -```jldoctest +```jldoctest ArrayAndChar; filter = r"(^find_aac \(generic function with 2 methods\)$|^$)" function Base.broadcast_similar(f, ::Broadcast.ArrayStyle{ArrayAndChar}, ::Type{ElType}, inds, As...) where ElType # Scan the inputs for the ArrayAndChar: A = find_aac(As...) @@ -533,11 +539,13 @@ end "`A = find_aac(As...)` returns the first ArrayAndChar among the arguments." find_aac(A::ArrayAndChar, B...) = A -find_aac(A, B...) = find_aac(B...) +find_aac(A, B...) = find_aac(B...); +# output + ``` From these definitions, one obtains the following behavior: -```jldoctest +```jldoctest ArrayAndChar julia> a = ArrayAndChar([1 2; 3 4], 'x') 2×2 ArrayAndChar{Int64,2} with char 'x': 1 2 diff --git a/doc/src/manual/mathematical-operations.md b/doc/src/manual/mathematical-operations.md index b539efbe3d0e5..f33449c9678db 100644 --- a/doc/src/manual/mathematical-operations.md +++ b/doc/src/manual/mathematical-operations.md @@ -380,7 +380,7 @@ You can also find the numerical precedence for any given operator via the built- ```jldoctest julia> Base.operator_precedence(:+), Base.operator_precedence(:*), Base.operator_precedence(:.) -(9, 11, 15) +(11, 13, 17) julia> Base.operator_precedence(:sin), Base.operator_precedence(:+=), Base.operator_precedence(:(=)) # (Note the necessary parens on `:(=)`) (0, 1, 1) @@ -424,25 +424,20 @@ julia> Int8(127) julia> Int8(128) ERROR: InexactError: trunc(Int8, 128) Stacktrace: - [1] throw_inexacterror(::Symbol, ::Type{Int8}, ::Int64) at ./int.jl:34 - [2] checked_trunc_sint at ./int.jl:438 [inlined] - [3] convert at ./int.jl:458 [inlined] - [4] Int8(::Int64) at ./sysimg.jl:114 +[...] julia> Int8(127.0) 127 julia> Int8(3.14) -ERROR: InexactError: convert(Int8, 3.14) +ERROR: InexactError: Int8(Int8, 3.14) Stacktrace: - [1] convert at ./float.jl:682 [inlined] - [2] Int8(::Float64) at ./sysimg.jl:114 +[...] julia> Int8(128.0) -ERROR: InexactError: convert(Int8, 128.0) +ERROR: InexactError: Int8(Int8, 128.0) Stacktrace: - [1] convert at ./float.jl:682 [inlined] - [2] Int8(::Float64) at ./sysimg.jl:114 +[...] julia> 127 % Int8 127 @@ -456,8 +451,7 @@ julia> round(Int8,127.4) julia> round(Int8,127.6) ERROR: InexactError: trunc(Int8, 128.0) Stacktrace: - [1] trunc at ./float.jl:675 [inlined] - [2] round(::Type{Int8}, ::Float64) at ./float.jl:353 +[...] ``` See [Conversion and Promotion](@ref conversion-and-promotion) for how to define your own conversions and promotions. diff --git a/doc/src/manual/metaprogramming.md b/doc/src/manual/metaprogramming.md index 2ac0c0c829e8e..901076ca9cee4 100644 --- a/doc/src/manual/metaprogramming.md +++ b/doc/src/manual/metaprogramming.md @@ -216,7 +216,7 @@ Interpolating into an unquoted expression is not supported and will cause a comp ```jldoctest interp1 julia> $a + b -ERROR: unsupported or misplaced expression $ +ERROR: syntax: "$" expression outside quote ``` In this example, the tuple `(1,2,3)` is interpolated as an expression into a conditional test: diff --git a/doc/src/manual/missing.md b/doc/src/manual/missing.md index 89ccb7fd0fa25..4467f587da162 100644 --- a/doc/src/manual/missing.md +++ b/doc/src/manual/missing.md @@ -276,10 +276,6 @@ julia> y = Union{Missing, String}[missing, "b"] julia> convert(Array{String}, y) ERROR: MethodError: Cannot `convert` an object of type Missing to an object of type String -This may have arisen from a call to the constructor String(...), -since type constructors fall back to convert methods. -Stacktrace: -[... ``` ## Skipping Missing Values diff --git a/doc/src/manual/performance-tips.md b/doc/src/manual/performance-tips.md index a832506733236..84dd79caf4b69 100644 --- a/doc/src/manual/performance-tips.md +++ b/doc/src/manual/performance-tips.md @@ -453,10 +453,7 @@ MyBetterContainer{Float64,UnitRange{Float64}} julia> b = MyBetterContainer{Int64, UnitRange{Float64}}(UnitRange(1.3, 5.0)); ERROR: MethodError: Cannot `convert` an object of type UnitRange{Float64} to an object of type MyBetterContainer{Int64,UnitRange{Float64}} -This may have arisen from a call to the constructor MyBetterContainer{Int64,UnitRange{Float64}}(...), -since type constructors fall back to convert methods. -Stacktrace: - [1] MyBetterContainer{Int64,UnitRange{Float64}}(::UnitRange{Float64}) at ./sysimg.jl:114 +[...] ``` The inner constructor requires that the element type of `A` be `T`. @@ -621,7 +618,7 @@ end ```jldoctest julia> function strange_twos(n) - a = Vector{rand(Bool) ? Int64 : Float64}(n) + a = Vector{rand(Bool) ? Int64 : Float64}(uninitialized, n) for i = 1:n a[i] = 2 end @@ -640,7 +637,7 @@ This should be written as: ```jldoctest julia> function fill_twos!(a) - for i=eachindex(a) + for i = eachindex(a) a[i] = 2 end end diff --git a/doc/src/manual/running-external-programs.md b/doc/src/manual/running-external-programs.md index 88fc04405e43c..749d88b75f2cf 100644 --- a/doc/src/manual/running-external-programs.md +++ b/doc/src/manual/running-external-programs.md @@ -29,7 +29,7 @@ julia> mycommand = `echo hello` julia> typeof(mycommand) Cmd -julia> run(mycommand) +julia> run(mycommand); hello ``` @@ -209,7 +209,7 @@ values. Let's try the above two examples in Julia: julia> A = `perl -le '$|=1; for (0..3) { print }'` `perl -le '$|=1; for (0..3) { print }'` -julia> run(A) +julia> run(A); 0 1 2 @@ -220,7 +220,7 @@ julia> first = "A"; second = "B"; julia> B = `perl -le 'print for @ARGV' "1: $first" "2: $second"` `perl -le 'print for @ARGV' '1: A' '2: B'` -julia> run(B) +julia> run(B); 1: A 2: B ``` @@ -236,10 +236,10 @@ easily and safely just examine its interpretation without doing any damage. Shell metacharacters, such as `|`, `&`, and `>`, need to be quoted (or escaped) inside of Julia's backticks: ```jldoctest -julia> run(`echo hello '|' sort`) +julia> run(`echo hello '|' sort`); hello | sort -julia> run(`echo hello \| sort`) +julia> run(`echo hello \| sort`); hello | sort ``` @@ -248,7 +248,7 @@ The result is that a single line is printed: `hello | sort`. How, then, does one pipeline? Instead of using `'|'` inside of backticks, one uses [`pipeline`](@ref): ```jldoctest -julia> run(pipeline(`echo hello`, `sort`)) +julia> run(pipeline(`echo hello`, `sort`)); hello ``` @@ -273,8 +273,8 @@ that shells cannot. Julia can run multiple commands in parallel: -```julia-repl -julia> run(`echo hello` & `echo world`) +```jldoctest; filter = r"(world\nhello|hello\nworld)" +julia> run(`echo hello` & `echo world`); world hello ``` @@ -285,7 +285,7 @@ share with each other and the `julia` parent process. Julia lets you pipe the ou of these processes to another program: ```jldoctest -julia> run(pipeline(`echo world` & `echo hello`, `sort`)) +julia> run(pipeline(`echo world` & `echo hello`, `sort`)); hello world ``` @@ -326,24 +326,20 @@ setup of pipes between processes is a powerful one. To give some sense of the co that can be created easily, here are some more sophisticated examples, with apologies for the excessive use of Perl one-liners: -```julia-repl +```jldoctest prefixer; filter = r"([A-B] [0-5])" julia> prefixer(prefix, sleep) = `perl -nle '$|=1; print "'$prefix' ", $_; sleep '$sleep';'`; -julia> run(pipeline(`perl -le '$|=1; for(0..9){ print; sleep 1 }'`, prefixer("A",2) & prefixer("B",2))) -A 0 -B 1 -A 2 -B 3 -A 4 -B 5 -A 6 -B 7 -A 8 -B 9 +julia> run(pipeline(`perl -le '$|=1; for(0..5){ print; sleep 1 }'`, prefixer("A",2) & prefixer("B",2))); +B 0 +A 1 +B 2 +A 3 +B 4 +A 5 ``` This is a classic example of a single producer feeding two concurrent consumers: one `perl` process -generates lines with the numbers 0 through 9 on them, while two parallel processes consume that +generates lines with the numbers 0 through 5 on them, while two parallel processes consume that output, one prefixing lines with the letter "A", the other with the letter "B". Which consumer gets the first line is non-deterministic, but once that race has been won, the lines are consumed alternately by one process and then the other. (Setting `$|=1` in Perl causes each print statement @@ -352,20 +348,16 @@ the output is buffered and printed to the pipe at once, to be read by just one c Here is an even more complex multi-stage producer-consumer example: -```julia-repl -julia> run(pipeline(`perl -le '$|=1; for(0..9){ print; sleep 1 }'`, +```jldoctest prefixer; filter = r"[A-B] [X-Z] [0-5]" +julia> run(pipeline(`perl -le '$|=1; for(0..5){ print; sleep 1 }'`, prefixer("X",3) & prefixer("Y",3) & prefixer("Z",3), - prefixer("A",2) & prefixer("B",2))) + prefixer("A",2) & prefixer("B",2))); A X 0 B Y 1 A Z 2 B X 3 A Y 4 B Z 5 -A X 6 -B Y 7 -A Z 8 -B X 9 ``` This example is similar to the previous one, except there are two stages of consumers, and the diff --git a/doc/src/manual/strings.md b/doc/src/manual/strings.md index dcfd739dbc3ae..50020168e3ccd 100644 --- a/doc/src/manual/strings.md +++ b/doc/src/manual/strings.md @@ -78,7 +78,7 @@ is a valid code point, use the [`isvalid`](@ref) function: ```jldoctest julia> Char(0x110000) -'\U110000': Unicode U+110000 (category Cn: Other, not assigned) +'\U110000': Unicode U+110000 (category In: Invalid, too high) julia> isvalid(Char, 0x110000) false @@ -129,9 +129,6 @@ julia> Int('\x7f') julia> Int('\177') 127 - -julia> Int('\xff') -255 ``` You can do comparisons and a limited amount of arithmetic with `Char` values: @@ -275,11 +272,12 @@ julia> s[1] '∀': Unicode U+2200 (category Sm: Symbol, math) julia> s[2] -ERROR: UnicodeError: invalid character index +ERROR: StringIndexError("∀ x ∃ y", 2) [...] julia> s[3] -ERROR: UnicodeError: invalid character index +ERROR: StringIndexError("∀ x ∃ y", 3) +Stacktrace: [...] julia> s[4] @@ -297,7 +295,8 @@ julia> s[1:1] "∀" julia> s[1:2] -ERROR: UnicodeError: invalid character index +ERROR: StringIndexError("∀ x ∃ y", 2) +Stacktrace: [...] julia> s[1:4] @@ -312,7 +311,7 @@ since each character in a string must have its own index. The following is an in verbose way to iterate through the characters of `s`: ```jldoctest unicodestring -julia> for i = begindex(s):lastindex(s) +julia> for i = firstindex(s):lastindex(s) try println(s[i]) catch @@ -824,7 +823,7 @@ produce arrays of bytes. Here is an example using all three: ```jldoctest julia> b"DATA\xff\u2200" -8-element Array{UInt8,1}: +8-element Base.CodeUnits{UInt8,String}: 0x44 0x41 0x54 @@ -851,11 +850,11 @@ is encoded as two bytes in UTF-8: ```jldoctest julia> b"\xff" -1-element Array{UInt8,1}: +1-element Base.CodeUnits{UInt8,String}: 0xff julia> b"\uff" -2-element Array{UInt8,1}: +2-element Base.CodeUnits{UInt8,String}: 0xc3 0xbf ``` diff --git a/doc/src/manual/types.md b/doc/src/manual/types.md index 6fc06ca3f4bbb..3260b396a2780 100644 --- a/doc/src/manual/types.md +++ b/doc/src/manual/types.md @@ -344,20 +344,16 @@ must be convertible to `Int`: ```jldoctest footype julia> Foo((), 23.5, 1) -ERROR: InexactError: convert(Int64, 23.5) +ERROR: InexactError: Int64(Int64, 23.5) Stacktrace: - [1] convert at ./float.jl:703 [inlined] - [2] Foo(::Tuple{}, ::Float64, ::Int64) at ./none:2 +[...] ``` You may find a list of field names using the `fieldnames` function. ```jldoctest footype julia> fieldnames(Foo) -3-element Array{Symbol,1}: - :bar - :baz - :qux +(:bar, :baz, :qux) ``` You can access the field values of a composite object using the traditional `foo.bar` notation: @@ -649,13 +645,11 @@ For the default constructor, exactly one argument must be supplied for each fiel ```jldoctest pointtype julia> Point{Float64}(1.0) ERROR: MethodError: Cannot `convert` an object of type Float64 to an object of type Point{Float64} -This may have arisen from a call to the constructor Point{Float64}(...), -since type constructors fall back to convert methods. -Stacktrace: - [1] Point{Float64}(::Float64) at ./sysimg.jl:114 +[...] julia> Point{Float64}(1.0,2.0,3.0) ERROR: MethodError: no method matching Point{Float64}(::Float64, ::Float64, ::Float64) +[...] ``` Only one default constructor is generated for parametric types, since overriding it is not possible. diff --git a/doc/src/manual/variables-and-scoping.md b/doc/src/manual/variables-and-scoping.md index 4fc5ba1ee0b1f..088aafdb19eb9 100644 --- a/doc/src/manual/variables-and-scoping.md +++ b/doc/src/manual/variables-and-scoping.md @@ -251,15 +251,15 @@ which have a private state, for instance the ``state`` variable in the following example: ```jldoctest - julia> let state = 0 - global counter() = (state += 1) - end; +julia> let state = 0 + global counter() = (state += 1) + end; - julia> counter() - 1 +julia> counter() +1 - julia> counter() - 2 +julia> counter() +2 ``` See also the closures in the examples in the next two sections. diff --git a/stdlib/Dates/docs/src/index.md b/stdlib/Dates/docs/src/index.md index 2b3adef744b08..3a434cc11b731 100644 --- a/stdlib/Dates/docs/src/index.md +++ b/stdlib/Dates/docs/src/index.md @@ -144,14 +144,14 @@ julia> dt2 = Date(2000,2,1) julia> dump(dt) Date - instant: Dates.UTInstant{Dates.Day} - periods: Dates.Day + instant: Dates.UTInstant{Day} + periods: Day value: Int64 734562 julia> dump(dt2) Date - instant: Dates.UTInstant{Dates.Day} - periods: Dates.Day + instant: Dates.UTInstant{Day} + periods: Day value: Int64 730151 julia> dt > dt2 @@ -170,7 +170,6 @@ ERROR: MethodError: no method matching *(::Date, ::Date) julia> dt / dt2 ERROR: MethodError: no method matching /(::Date, ::Date) -[...] julia> dt - dt2 4411 days @@ -240,12 +239,12 @@ One may also access the underlying `UTInstant` or integer value: ```jldoctest tdate julia> dump(t) Date - instant: Dates.UTInstant{Dates.Day} - periods: Dates.Day + instant: Dates.UTInstant{Day} + periods: Day value: Int64 735264 julia> t.instant -Dates.UTInstant{Dates.Day}(735264 days) +Dates.UTInstant{Day}(735264 days) julia> Dates.value(t) 735264 @@ -559,7 +558,7 @@ julia> round(DateTime(2016, 8, 6, 20, 15), Dates.Day) Unlike the numeric [`round`](@ref) method, which breaks ties toward the even number by default, the [`TimeType`](@ref)[`round`](@ref) method uses the `RoundNearestTiesUp` rounding mode. (It's difficult to guess what breaking ties to nearest "even" [`TimeType`](@ref) would entail.) Further -details on the available `RoundingMode` s can be found in the [API reference](@ref stdlib-dates). +details on the available `RoundingMode` s can be found in the [API reference](@ref stdlib-dates-api). Rounding should generally behave as expected, but there are a few cases in which the expected behaviour is not obvious. diff --git a/stdlib/Dates/src/rounding.jl b/stdlib/Dates/src/rounding.jl index f575f71e9760a..fdd2f7658f555 100644 --- a/stdlib/Dates/src/rounding.jl +++ b/stdlib/Dates/src/rounding.jl @@ -170,7 +170,7 @@ julia> ceil(Dates.Minute(44), Dates.Minute(15)) 45 minutes julia> ceil(Dates.Hour(36), Dates.Day) -3 days +2 days ``` Rounding to a `precision` of `Month`s or `Year`s is not supported, as these `Period`s are of @@ -250,7 +250,7 @@ julia> round(Dates.Minute(44), Dates.Minute(15)) 45 minutes julia> round(Dates.Hour(36), Dates.Day) -3 days +2 days ``` Valid rounding modes for `round(::Period, ::T, ::RoundingMode)` are `RoundNearestTiesUp` diff --git a/stdlib/InteractiveUtils/src/InteractiveUtils.jl b/stdlib/InteractiveUtils/src/InteractiveUtils.jl index 9d23cb9dabb8a..0c397ba534c8f 100644 --- a/stdlib/InteractiveUtils/src/InteractiveUtils.jl +++ b/stdlib/InteractiveUtils/src/InteractiveUtils.jl @@ -249,7 +249,7 @@ are included, including those not visible in the current module. # Examples ```jldoctest julia> subtypes(Integer) -3-element Array{Union{DataType, UnionAll},1}: +3-element Array{Any,1}: Bool Signed Unsigned diff --git a/stdlib/IterativeEigensolvers/docs/src/index.md b/stdlib/IterativeEigensolvers/docs/src/index.md index 62dadc72c74a1..185d2dcc14a56 100644 --- a/stdlib/IterativeEigensolvers/docs/src/index.md +++ b/stdlib/IterativeEigensolvers/docs/src/index.md @@ -1,7 +1,7 @@ # [Iterative Eigensolvers](@id lib-itereigen) ```@meta -DocTestSetup = :(using IterativeEigensolvers) +DocTestSetup = :(using IterativeEigensolvers, LinearAlgebra, SparseArrays) ``` Julia provides bindings to [ARPACK](http://www.caam.rice.edu/software/ARPACK/), which @@ -53,9 +53,7 @@ the following keyword arguments are supported: * `v0`: starting vector from which to start the iterations We can see the various keywords in action in the following examples: -```jldoctest -julia> using IterativeEigensolvers - +```jldoctest; filter = r"(1|2)-element Array{(Float64|Complex{Float64}),1}:\n (.|\s)*$" julia> A = Diagonal(1:4); julia> λ, ϕ = eigs(A, nev = 2, which=:SM); @@ -65,42 +63,37 @@ julia> λ 1.0000000000000002 2.0 -julia> B = Diagonal([1., 2., -3im, 4im]) -4×4 Diagonal{Complex{Float64},Array{Complex{Float64},1}}: - 1.0+0.0im ⋅ ⋅ ⋅ - ⋅ 2.0+0.0im ⋅ ⋅ - ⋅ ⋅ 0.0-3.0im ⋅ - ⋅ ⋅ ⋅ 0.0+4.0im +julia> B = Diagonal([1., 2., -3im, 4im]); julia> λ, ϕ = eigs(B, nev=1, which=:LI); julia> λ 1-element Array{Complex{Float64},1}: - -4.440892098500626e-16 + 3.999999999999998im + 1.3322676295501878e-15 + 4.0im julia> λ, ϕ = eigs(B, nev=1, which=:SI); julia> λ 1-element Array{Complex{Float64},1}: - 1.3877787807814457e-16 - 2.999999999999999im + -2.498001805406602e-16 - 3.0000000000000018im julia> λ, ϕ = eigs(B, nev=1, which=:LR); julia> λ 1-element Array{Complex{Float64},1}: - 2.0 + 4.242754940683747e-17im + 2.0000000000000004 + 4.0615212488780827e-17im julia> λ, ϕ = eigs(B, nev=1, which=:SR); julia> λ 1-element Array{Complex{Float64},1}: - 4.440892098500626e-16 + 4.0000000000000036im + -8.881784197001252e-16 + 3.999999999999997im julia> λ, ϕ = eigs(B, nev=1, sigma=1.5); julia> λ 1-element Array{Complex{Float64},1}: - 1.9999999999999996 + 2.4290457684137336e-17im + 1.0000000000000004 + 4.0417078924070745e-18im ``` !!! note @@ -168,31 +161,29 @@ iterations `niter` and the number of matrix vector multiplications `nmult`, as w final residual vector `resid`. We can see the various keywords in action in the following examples: -```jldoctest -julia> using IterativeEigensolvers - +```jldoctest; filter = r"(1|2)-element Array{(Float64|Complex{Float64}),1}:\n (.|\s)*$" julia> A = sparse(1.0I, 4, 4); B = Diagonal(1:4); julia> λ, ϕ = eigs(A, B, nev = 2); julia> λ 2-element Array{Float64,1}: - 1.0 - 0.4999999999999999 + 1.0000000000000002 + 0.5 -julia> A = sparse(1.0I, 4, 4); B = Diagonal([1, -2im, 3, 4im]); +julia> A = Diagonal([1, -2im, 3, 4im]); B = sparse(1.0I, 4, 4); julia> λ, ϕ = eigs(A, B, nev=1, which=:SI); julia> λ 1-element Array{Complex{Float64},1}: - 0.03291282838780993 - 2.0627621271174514im + -1.5720931501039814e-16 - 1.9999999999999984im julia> λ, ϕ = eigs(A, B, nev=1, which=:LI); julia> λ 1-element Array{Complex{Float64},1}: - -0.6428551411711136 + 2.1820633510068994im + 0.0 + 4.000000000000002im ``` !!! note diff --git a/stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl b/stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl index 3bad088d82d54..64f2c4393aaa3 100644 --- a/stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl +++ b/stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl @@ -278,7 +278,7 @@ iterations derived from [`eigs`](@ref). * `resid`: Final residual vector. # Examples -```jldoctest +```jldoctest; filter = r"2-element Array{Float64,1}:\\n.*\\n.*" julia> A = Diagonal(1:4); julia> s = svds(A, nsv = 2)[1]; diff --git a/stdlib/LinearAlgebra/docs/src/index.md b/stdlib/LinearAlgebra/docs/src/index.md index d931b8c3a1693..e46e75ee0fb68 100644 --- a/stdlib/LinearAlgebra/docs/src/index.md +++ b/stdlib/LinearAlgebra/docs/src/index.md @@ -60,9 +60,17 @@ julia> A = [1.5 2 -4; 3 -1 -6; -10 2.3 4] -10.0 2.3 4.0 julia> factorize(A) -LinearAlgebra.LU{Float64,Array{Float64,2}} with factors L and U: -[1.0 0.0 0.0; -0.15 1.0 0.0; -0.3 -0.132196 1.0] -[-10.0 2.3 4.0; 0.0 2.345 -3.4; 0.0 0.0 -5.24947] +LU{Float64,Array{Float64,2}} +L factor: +3×3 Array{Float64,2}: + 1.0 0.0 0.0 + -0.15 1.0 0.0 + -0.3 -0.132196 1.0 +U factor: +3×3 Array{Float64,2}: + -10.0 2.3 4.0 + 0.0 2.345 -3.4 + 0.0 0.0 -5.24947 ``` Since `A` is not Hermitian, symmetric, triangular, tridiagonal, or bidiagonal, an LU factorization may be the @@ -76,17 +84,17 @@ julia> B = [1.5 2 -4; 2 -1 -3; -4 -3 5] -4.0 -3.0 5.0 julia> factorize(B) -LinearAlgebra.BunchKaufman{Float64,Array{Float64,2}} +BunchKaufman{Float64,Array{Float64,2}} D factor: 3×3 Tridiagonal{Float64,Array{Float64,1}}: -1.64286 0.0 ⋅ 0.0 -2.8 0.0 ⋅ 0.0 5.0 U factor: -3×3 LinearAlgebra.UnitUpperTriangular{Float64,Array{Float64,2}}: +3×3 UnitUpperTriangular{Float64,Array{Float64,2}}: 1.0 0.142857 -0.8 - 0.0 1.0 -0.6 - 0.0 0.0 1.0 + ⋅ 1.0 -0.6 + ⋅ ⋅ 1.0 permutation: 3-element Array{Int64,1}: 1 @@ -252,9 +260,7 @@ julia> b = [1 2 3; 4 5 6] julia> b - U ERROR: DimensionMismatch("matrix is not square: dimensions are (2, 3)") Stacktrace: - [1] checksquare at ./linalg/linalg.jl:220 [inlined] - [2] -(::Array{Int64,2}, ::UniformScaling{Int64}) at ./linalg/uniformscaling.jl:156 - [3] top-level scope +[...] ``` ## [Matrix factorizations](@id man-linalg-factorizations) @@ -416,7 +422,7 @@ Base.transpose LinearAlgebra.transpose! Base.adjoint LinearAlgebra.adjoint! -LinearAlgebra.peakflops +Base.copy(::Union{Transpose,Adjoint}) LinearAlgebra.stride1 LinearAlgebra.checksquare ``` diff --git a/stdlib/LinearAlgebra/src/blas.jl b/stdlib/LinearAlgebra/src/blas.jl index 5d6d5198b79d9..5733fa8ad528b 100644 --- a/stdlib/LinearAlgebra/src/blas.jl +++ b/stdlib/LinearAlgebra/src/blas.jl @@ -246,7 +246,7 @@ conjugating the first vector. # Examples ```jldoctest -julia> Base.BLAS.dotc(10, fill(1.0im, 10), 1, fill(1.0+im, 20), 2) +julia> BLAS.dotc(10, fill(1.0im, 10), 1, fill(1.0+im, 20), 2) 10.0 - 10.0im ``` """ @@ -260,7 +260,7 @@ with stride `incx` and `n` elements of array `Y` with stride `incy`. # Examples ```jldoctest -julia> Base.BLAS.dotu(10, fill(1.0im, 10), 1, fill(1.0+im, 20), 2) +julia> BLAS.dotu(10, fill(1.0im, 10), 1, fill(1.0+im, 20), 2) -10.0 + 10.0im ``` """ @@ -350,10 +350,10 @@ end # Examples ```jldoctest -julia> Base.BLAS.nrm2(4, fill(1.0, 8), 2) +julia> BLAS.nrm2(4, fill(1.0, 8), 2) 2.0 -julia> Base.BLAS.nrm2(1, fill(1.0, 8), 2) +julia> BLAS.nrm2(1, fill(1.0, 8), 2) 1.0 ``` """ @@ -383,10 +383,10 @@ Sum of the absolute values of the first `n` elements of array `X` with stride `i # Examples ```jldoctest -julia> Base.BLAS.asum(5, fill(1.0im, 10), 2) +julia> BLAS.asum(5, fill(1.0im, 10), 2) 5.0 -julia> Base.BLAS.asum(2, fill(1.0im, 10), 5) +julia> BLAS.asum(2, fill(1.0im, 10), 5) 2.0 ``` """ @@ -420,7 +420,7 @@ julia> x = [1; 2; 3]; julia> y = [4; 5; 6]; -julia> Base.BLAS.axpy!(2, x, y) +julia> BLAS.axpy!(2, x, y) 3-element Array{Int64,1}: 6 9 @@ -483,7 +483,7 @@ julia> x = [1., 2, 3]; julia> y = [4., 5, 6]; -julia> Base.BLAS.axpby!(2., x, 3., y) +julia> BLAS.axpby!(2., x, 3., y) 3-element Array{Float64,1}: 14.0 19.0 diff --git a/stdlib/LinearAlgebra/src/bunchkaufman.jl b/stdlib/LinearAlgebra/src/bunchkaufman.jl index 80db51dcb802c..70f31800670e0 100644 --- a/stdlib/LinearAlgebra/src/bunchkaufman.jl +++ b/stdlib/LinearAlgebra/src/bunchkaufman.jl @@ -59,15 +59,15 @@ julia> A = [1 2; 2 3] 2 3 julia> bkfact(A) -LinearAlgebra.BunchKaufman{Float64,Array{Float64,2}} +BunchKaufman{Float64,Array{Float64,2}} D factor: 2×2 Tridiagonal{Float64,Array{Float64,1}}: -0.333333 0.0 0.0 3.0 U factor: -2×2 LinearAlgebra.UnitUpperTriangular{Float64,Array{Float64,2}}: +2×2 UnitUpperTriangular{Float64,Array{Float64,2}}: 1.0 0.666667 - 0.0 1.0 + ⋅ 1.0 permutation: 2-element Array{Int64,1}: 1 @@ -135,16 +135,16 @@ julia> A = [1 2 3; 2 1 2; 3 2 1] 3 2 1 julia> F = bkfact(Symmetric(A, :L)) -LinearAlgebra.BunchKaufman{Float64,Array{Float64,2}} +BunchKaufman{Float64,Array{Float64,2}} D factor: 3×3 Tridiagonal{Float64,Array{Float64,1}}: 1.0 3.0 ⋅ 3.0 1.0 0.0 ⋅ 0.0 -1.0 L factor: -3×3 LinearAlgebra.UnitLowerTriangular{Float64,Array{Float64,2}}: - 1.0 0.0 0.0 - 0.0 1.0 0.0 +3×3 UnitLowerTriangular{Float64,Array{Float64,2}}: + 1.0 ⋅ ⋅ + 0.0 1.0 ⋅ 0.5 0.5 1.0 permutation: 3-element Array{Int64,1}: diff --git a/stdlib/LinearAlgebra/src/cholesky.jl b/stdlib/LinearAlgebra/src/cholesky.jl index 1f390615da0e6..aba49d0676332 100644 --- a/stdlib/LinearAlgebra/src/cholesky.jl +++ b/stdlib/LinearAlgebra/src/cholesky.jl @@ -231,7 +231,9 @@ julia> A = [1 2; 2 50] 2 50 julia> cholfact!(A) -ERROR: InexactError: convert(Int64, 6.782329983125268) +ERROR: InexactError: Int64(Int64, 6.782329983125268) +Stacktrace: +[...] ``` """ function cholfact!(A::StridedMatrix, ::Val{false}=Val(false)) @@ -298,7 +300,7 @@ julia> A = [4. 12. -16.; 12. 37. -43.; -16. -43. 98.] -16.0 -43.0 98.0 julia> C = cholfact(A) -LinearAlgebra.Cholesky{Float64,Array{Float64,2}} +Cholesky{Float64,Array{Float64,2}} U factor: 3×3 UpperTriangular{Float64,Array{Float64,2}}: 2.0 6.0 -8.0 diff --git a/stdlib/LinearAlgebra/src/dense.jl b/stdlib/LinearAlgebra/src/dense.jl index a1e8997d68659..80ef0071081a1 100644 --- a/stdlib/LinearAlgebra/src/dense.jl +++ b/stdlib/LinearAlgebra/src/dense.jl @@ -621,8 +621,8 @@ julia> A = Matrix(2.7182818*I, 2, 2) julia> log(A) 2×2 Array{Float64,2}: - 1.0 0.0 - 0.0 1.0 + 1.0 0.0 + -0.0 1.0 ``` """ function log(A::StridedMatrix) @@ -935,8 +935,8 @@ this function, see [^AH16_1]. ```jldoctest julia> acos(cos([0.5 0.1; -0.2 0.3])) 2×2 Array{Complex{Float64},2}: - 0.5-8.32667e-17im 0.1-2.77556e-17im - -0.2+2.77556e-16im 0.3-3.46945e-16im + 0.5-5.55112e-17im 0.1-2.77556e-17im + -0.2+2.498e-16im 0.3-3.46945e-16im ``` """ function acos(A::AbstractMatrix) diff --git a/stdlib/LinearAlgebra/src/eigen.jl b/stdlib/LinearAlgebra/src/eigen.jl index 44b6721c604ba..56890060f13f2 100644 --- a/stdlib/LinearAlgebra/src/eigen.jl +++ b/stdlib/LinearAlgebra/src/eigen.jl @@ -75,7 +75,17 @@ make rows and columns more equal in norm. The default is `true` for both options # Examples ```jldoctest julia> F = eigfact([1.0 0.0 0.0; 0.0 3.0 0.0; 0.0 0.0 18.0]) -LinearAlgebra.Eigen{Float64,Float64,Array{Float64,2},Array{Float64,1}}([1.0, 3.0, 18.0], [1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0]) +Eigen{Float64,Float64,Array{Float64,2},Array{Float64,1}} +eigenvalues: +3-element Array{Float64,1}: + 1.0 + 3.0 + 18.0 +eigenvectors: +3×3 Array{Float64,2}: + 1.0 0.0 0.0 + 0.0 1.0 0.0 + 0.0 0.0 1.0 julia> F.values 3-element Array{Float64,1}: diff --git a/stdlib/LinearAlgebra/src/lu.jl b/stdlib/LinearAlgebra/src/lu.jl index 17cab622dad5b..3dc604869305a 100644 --- a/stdlib/LinearAlgebra/src/lu.jl +++ b/stdlib/LinearAlgebra/src/lu.jl @@ -39,11 +39,11 @@ element type of `A`, e.g. for integer types. ```jldoctest julia> A = [4. 3.; 6. 3.] 2×2 Array{Float64,2}: - 6.0 3.0 4.0 3.0 + 6.0 3.0 julia> F = lufact!(A) -LinearAlgebra.LU{Float64,Array{Float64,2}} +LU{Float64,Array{Float64,2}} L factor: 2×2 Array{Float64,2}: 1.0 0.0 @@ -59,7 +59,7 @@ julia> iA = [4 3; 6 3] 6 3 julia> lufact!(iA) -ERROR: InexactError: convert(Int64, 0.6666666666666666) +ERROR: InexactError: Int64(Int64, 0.6666666666666666) Stacktrace: [...] ``` @@ -162,7 +162,7 @@ julia> A = [4 3; 6 3] 6 3 julia> F = lufact(A) -LinearAlgebra.LU{Float64,Array{Float64,2}} +LU{Float64,Array{Float64,2}} L factor: 2×2 Array{Float64,2}: 1.0 0.0 diff --git a/stdlib/LinearAlgebra/src/qr.jl b/stdlib/LinearAlgebra/src/qr.jl index 25a1a69e2527d..543f6600e5ccd 100644 --- a/stdlib/LinearAlgebra/src/qr.jl +++ b/stdlib/LinearAlgebra/src/qr.jl @@ -216,9 +216,15 @@ julia> a = [1. 2.; 3. 4.] 3.0 4.0 julia> qrfact!(a) -LinearAlgebra.QRCompactWY{Float64,Array{Float64,2}} with factors Q and R: -[-0.316228 -0.948683; -0.948683 0.316228] -[-3.16228 -4.42719; 0.0 -0.632456] +LinearAlgebra.QRCompactWY{Float64,Array{Float64,2}} +Q factor: +2×2 LinearAlgebra.QRCompactWYQ{Float64,Array{Float64,2}}: + -0.316228 -0.948683 + -0.948683 0.316228 +R factor: +2×2 Array{Float64,2}: + -3.16228 -4.42719 + 0.0 -0.632456 julia> a = [1 2; 3 4] 2×2 Array{Int64,2}: @@ -226,7 +232,7 @@ julia> a = [1 2; 3 4] 3 4 julia> qrfact!(a) -ERROR: InexactError: convert(Int64, -3.1622776601683795) +ERROR: InexactError: Int64(Int64, -3.1622776601683795) Stacktrace: [...] ``` @@ -280,9 +286,16 @@ julia> A = [3.0 -6.0; 4.0 -8.0; 0.0 1.0] 0.0 1.0 julia> F = qrfact(A) -LinearAlgebra.QRCompactWY{Float64,Array{Float64,2}} with factors Q and R: -[-0.6 0.0 0.8; -0.8 0.0 -0.6; 0.0 -1.0 0.0] -[-5.0 10.0; 0.0 -1.0] +LinearAlgebra.QRCompactWY{Float64,Array{Float64,2}} +Q factor: +3×3 LinearAlgebra.QRCompactWYQ{Float64,Array{Float64,2}}: + -0.6 0.0 0.8 + -0.8 0.0 -0.6 + 0.0 -1.0 0.0 +R factor: +2×2 Array{Float64,2}: + -5.0 10.0 + 0.0 -1.0 julia> F.Q * F.R == A true diff --git a/stdlib/LinearAlgebra/src/schur.jl b/stdlib/LinearAlgebra/src/schur.jl index 410cce702409c..ec4595351bfe2 100644 --- a/stdlib/LinearAlgebra/src/schur.jl +++ b/stdlib/LinearAlgebra/src/schur.jl @@ -22,11 +22,19 @@ julia> A = [5. 7.; -2. -4.] -2.0 -4.0 julia> F = schurfact!(A) -LinearAlgebra.Schur{Float64,Array{Float64,2}} with factors T and Z: -[3.0 9.0; 0.0 -2.0] -[0.961524 0.274721; -0.274721 0.961524] -and values: -[3.0, -2.0] +Schur{Float64,Array{Float64,2}} +T factor: +2×2 Array{Float64,2}: + 3.0 9.0 + 0.0 -2.0 +Z factor: +2×2 Array{Float64,2}: + 0.961524 0.274721 + -0.274721 0.961524 +eigenvalues: +2-element Array{Float64,1}: + 3.0 + -2.0 julia> A 2×2 Array{Float64,2}: @@ -52,11 +60,19 @@ julia> A = [5. 7.; -2. -4.] -2.0 -4.0 julia> F = schurfact(A) -LinearAlgebra.Schur{Float64,Array{Float64,2}} with factors T and Z: -[3.0 9.0; 0.0 -2.0] -[0.961524 0.274721; -0.274721 0.961524] -and values: -[3.0, -2.0] +Schur{Float64,Array{Float64,2}} +T factor: +2×2 Array{Float64,2}: + 3.0 9.0 + 0.0 -2.0 +Z factor: +2×2 Array{Float64,2}: + 0.961524 0.274721 + -0.274721 0.961524 +eigenvalues: +2-element Array{Float64,1}: + 3.0 + -2.0 julia> F.vectors * F.Schur * F.vectors' 2×2 Array{Float64,2}: diff --git a/stdlib/LinearAlgebra/src/transpose.jl b/stdlib/LinearAlgebra/src/transpose.jl index 5b67703c57ee7..747be1c155efc 100644 --- a/stdlib/LinearAlgebra/src/transpose.jl +++ b/stdlib/LinearAlgebra/src/transpose.jl @@ -146,29 +146,35 @@ function ccopy!(B, A) end """ - transpose(A::AbstractMatrix) + copy(A::Transpose) + copy(A::Adjoint) -Eager matrix transpose. Note that the transposition is applied recursively to -elements. +Eagerly evaluate the lazy matrix transpose/adjoint. +Note that the transposition is applied recursively to elements. This operation is intended for linear algebra usage - for general data manipulation see [`permutedims`](@ref), which is non-recursive. # Examples ```jldoctest -julia> A = [1 2 3; 4 5 6; 7 8 9] -3×3 Array{Int64,2}: - 1 2 3 - 4 5 6 - 7 8 9 - -julia> transpose(A) -3×3 Array{Int64,2}: - 1 4 7 - 2 5 8 - 3 6 9 +julia> A = [1 2im; -3im 4] +2×2 Array{Complex{Int64},2}: + 1+0im 0+2im + 0-3im 4+0im + +julia> T = transpose(A) +2×2 Transpose{Complex{Int64},Array{Complex{Int64},2}}: + 1+0im 0-3im + 0+2im 4+0im + +julia> copy(T) +2×2 Array{Complex{Int64},2}: + 1+0im 0-3im + 0+2im 4+0im ``` """ +copy(::Union{Transpose,Adjoint}) + Base.copy(A::Transpose{<:Any,<:AbstractMatrix}) = transpose!(similar(A.parent, reverse(axes(A.parent))), A.parent) Base.copy(A::Adjoint{<:Any,<:AbstractMatrix}) = adjoint!(similar(A.parent, reverse(axes(A.parent))), A.parent) diff --git a/stdlib/Random/src/misc.jl b/stdlib/Random/src/misc.jl index 4978510245dca..5aaf8f0335795 100644 --- a/stdlib/Random/src/misc.jl +++ b/stdlib/Random/src/misc.jl @@ -21,14 +21,14 @@ julia> rng = MersenneTwister(1234); julia> bitrand(rng, 10) 10-element BitArray{1}: + false true true true - false true - false false true + false false true ``` @@ -53,10 +53,10 @@ number generator, see [Random Numbers](@ref). # Examples ```jldoctest julia> srand(0); randstring() -"c03rgKi1" +"Qgt7sUOP" julia> randstring(MersenneTwister(0), 'a':'z', 6) -"wijzek" +"oevnou" julia> randstring("ACGT") "TATCGGTC" diff --git a/stdlib/Sockets/docs/src/index.md b/stdlib/Sockets/docs/src/index.md index d457da9dfbeb9..2b258710f1445 100644 --- a/stdlib/Sockets/docs/src/index.md +++ b/stdlib/Sockets/docs/src/index.md @@ -1,5 +1,9 @@ ## Sockets +```@meta +DocTestSetup = :(using Sockets) +``` + ```@docs Sockets.connect(::TCPSocket, ::Integer) Sockets.connect(::AbstractString) @@ -23,3 +27,7 @@ Sockets.recv Sockets.recvfrom Sockets.setopt ``` + +```@meta +DocTestSetup = nothing +``` diff --git a/stdlib/SparseArrays/docs/src/index.md b/stdlib/SparseArrays/docs/src/index.md index 34dd58c361a52..afde15ce99740 100644 --- a/stdlib/SparseArrays/docs/src/index.md +++ b/stdlib/SparseArrays/docs/src/index.md @@ -1,7 +1,7 @@ # Sparse Arrays ```@meta -DocTestSetup = :(using SparseArrays) +DocTestSetup = :(using SparseArrays, LinearAlgebra) ``` Julia has support for sparse vectors and [sparse matrices](https://en.wikipedia.org/wiki/Sparse_matrix) diff --git a/stdlib/SparseArrays/src/sparsematrix.jl b/stdlib/SparseArrays/src/sparsematrix.jl index f4b8a8a549e34..ec1cec1f69a90 100644 --- a/stdlib/SparseArrays/src/sparsematrix.jl +++ b/stdlib/SparseArrays/src/sparsematrix.jl @@ -1393,15 +1393,13 @@ distribution is used in case `rfn` is not specified. The optional `rng` argument specifies a random number generator, see [Random Numbers](@ref). # Examples -```jldoctest -julia> rng = MersenneTwister(1234); - -julia> sprand(rng, Bool, 2, 2, 0.5) +```jldoctest; setup = :(using Random; srand(1234)) +julia> sprand(Bool, 2, 2, 0.5) 2×2 SparseMatrixCSC{Bool,Int64} with 2 stored entries: [1, 1] = true [2, 1] = true -julia> sprand(rng, Float64, 3, 0.75) +julia> sprand(Float64, 3, 0.75) 3-element SparseVector{Float64,Int64} with 1 stored entry: [3] = 0.298614 ``` @@ -1444,14 +1442,11 @@ where nonzero values are sampled from the normal distribution. The optional `rng argument specifies a random number generator, see [Random Numbers](@ref). # Examples -```jldoctest -julia> rng = MersenneTwister(1234); - -julia> sprandn(rng, 2, 2, 0.75) -2×2 SparseMatrixCSC{Float64,Int64} with 3 stored entries: - [1, 1] = 0.532813 - [2, 1] = -0.271735 - [2, 2] = 0.502334 +```jldoctest; setup = :(using Random; srand(0)) +julia> sprandn(2, 2, 0.75) +2×2 SparseMatrixCSC{Float64,Int64} with 2 stored entries: + [1, 1] = 0.586617 + [1, 2] = 0.297336 ``` """ sprandn(r::AbstractRNG, m::Integer, n::Integer, density::AbstractFloat) = sprand(r,m,n,density,randn,Float64) diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index eb546b614b88b..bdffcc68808a3 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -1209,7 +1209,7 @@ inferred by the compiler. It is useful to check for type stability. Returns the result of `f(x)` if the types match, and an `Error` `Result` if it finds different types. -```jldoctest +```jldoctest; setup = :(using InteractiveUtils), filter = r"begin\\n(.|\\n)*end" julia> f(a,b,c) = b > 1 ? 1 : 1.0 f (generic function with 1 method) @@ -1224,14 +1224,19 @@ Variables: Body: begin - unless (Base.slt_int)(1, b::Int64)::Bool goto 3 + # meta: location operators.jl > 279 + # meta: location int.jl < 49 + Core.SSAValue(2) = (Base.slt_int)(1, b::Int64)::Bool + # meta: pop locations (2) + unless Core.SSAValue(2) goto 7 return 1 - 3: + 7: return 1.0 end::UNION{FLOAT64, INT64} julia> @inferred f(1,2,3) ERROR: return type Int64 does not match inferred return type Union{Float64, Int64} +Stacktrace: [...] julia> @inferred max(1,2) diff --git a/stdlib/UUIDs/docs/src/index.md b/stdlib/UUIDs/docs/src/index.md index ddc490f4e46c9..3b936e7c82178 100644 --- a/stdlib/UUIDs/docs/src/index.md +++ b/stdlib/UUIDs/docs/src/index.md @@ -1,7 +1,7 @@ # UUIDs ```@meta -DocTestSetup = :(using UUIDs) +DocTestSetup = :(using UUIDs, Random) ``` ```@docs diff --git a/stdlib/UUIDs/src/UUIDs.jl b/stdlib/UUIDs/src/UUIDs.jl index 0f9ddc46027c7..cf59d0fb9f71b 100644 --- a/stdlib/UUIDs/src/UUIDs.jl +++ b/stdlib/UUIDs/src/UUIDs.jl @@ -32,11 +32,11 @@ by RFC 4122. Note that the Node ID is randomly generated (does not identify the according to section 4.5 of the RFC. # Examples -```jldoctest +```jldoctest; filter = r"[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}" julia> rng = MersenneTwister(1234); julia> uuid1(rng) -2cc938da-5937-11e7-196e-0f4ef71aa64b +fcbd9b64-1bc2-11e8-1f13-43a2532b2fa8 ``` """ function uuid1(rng::AbstractRNG=Random.GLOBAL_RNG) @@ -73,7 +73,7 @@ as specified by RFC 4122. julia> rng = MersenneTwister(1234); julia> uuid4(rng) -82015f10-44cc-4827-996e-0f4ef71aa64b +196f2941-2d58-45ba-9f13-43a2532b2fa8 ``` """ function uuid4(rng::AbstractRNG=Random.GLOBAL_RNG)