diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 6b8f6b92b0bd6..14608ec3e92ab 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -553,8 +553,8 @@ elements since `BitArray`s are both mutable and can support 1-dimensional arrays ```julia-repl julia> similar(trues(10,10), 2) 2-element BitArray{1}: - false - false + 0 + 0 ``` Since `BitArray`s can only store elements of type [`Bool`](@ref), however, if you request a diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index eb435b786a831..ce4096f6e4940 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -214,27 +214,27 @@ julia> circshift(b, (-1,0)) julia> a = BitArray([true, true, false, false, true]) 5-element BitArray{1}: - true - true - false - false - true + 1 + 1 + 0 + 0 + 1 julia> circshift(a, 1) 5-element BitArray{1}: - true - true - true - false - false + 1 + 1 + 1 + 0 + 0 julia> circshift(a, -1) 5-element BitArray{1}: - true - false - false - true - true + 1 + 0 + 0 + 1 + 1 ``` See also [`circshift!`](@ref). diff --git a/base/array.jl b/base/array.jl index d573a1aa39d4d..33aebc33b6599 100644 --- a/base/array.jl +++ b/base/array.jl @@ -1581,10 +1581,10 @@ and [`pairs(A)`](@ref). ```jldoctest julia> A = [false, false, true, false] 4-element Array{Bool,1}: - false - false - true - false + 0 + 0 + 1 + 0 julia> findnext(A, 1) 3 @@ -1593,8 +1593,8 @@ julia> findnext(A, 4) # returns nothing, but not printed in the REPL julia> A = [false false; true false] 2×2 Array{Bool,2}: - false false - true false + 0 0 + 1 0 julia> findnext(A, CartesianIndex(1, 1)) CartesianIndex(2, 1) @@ -1626,10 +1626,10 @@ and [`pairs(A)`](@ref). ```jldoctest julia> A = [false, false, true, false] 4-element Array{Bool,1}: - false - false - true - false + 0 + 0 + 1 + 0 julia> findfirst(A) 3 @@ -1638,8 +1638,8 @@ julia> findfirst(falses(3)) # returns nothing, but not printed in the REPL julia> A = [false false; true false] 2×2 Array{Bool,2}: - false false - true false + 0 0 + 1 0 julia> findfirst(A) CartesianIndex(2, 1) @@ -1752,10 +1752,10 @@ and [`pairs(A)`](@ref). ```jldoctest julia> A = [false, false, true, true] 4-element Array{Bool,1}: - false - false - true - true + 0 + 0 + 1 + 1 julia> findprev(A, 3) 3 @@ -1764,8 +1764,8 @@ julia> findprev(A, 1) # returns nothing, but not printed in the REPL julia> A = [false false; true true] 2×2 Array{Bool,2}: - false false - true true + 0 0 + 1 1 julia> findprev(A, CartesianIndex(2, 1)) CartesianIndex(2, 1) @@ -1793,10 +1793,10 @@ and [`pairs(A)`](@ref). ```jldoctest julia> A = [true, false, true, false] 4-element Array{Bool,1}: - true - false - true - false + 1 + 0 + 1 + 0 julia> findlast(A) 3 @@ -1807,8 +1807,8 @@ julia> findlast(A) # returns nothing, but not printed in the REPL julia> A = [true false; true false] 2×2 Array{Bool,2}: - true false - true false + 1 0 + 1 0 julia> findlast(A) CartesianIndex(2, 1) @@ -1977,10 +1977,10 @@ and [`pairs(A)`](@ref). ```jldoctest julia> A = [true, false, false, true] 4-element Array{Bool,1}: - true - false - false - true + 1 + 0 + 0 + 1 julia> findall(A) 2-element Array{Int64,1}: @@ -1989,8 +1989,8 @@ julia> findall(A) julia> A = [true false; false true] 2×2 Array{Bool,2}: - true false - false true + 1 0 + 0 1 julia> findall(A) 2-element Array{CartesianIndex{2},1}: diff --git a/base/bitarray.jl b/base/bitarray.jl index a93909a4bbbbd..aaefad792c8aa 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -369,8 +369,8 @@ Create a `BitArray` with all values set to `false`. ```jldoctest julia> falses(2,3) 2×3 BitArray{2}: - false false false - false false false + 0 0 0 + 0 0 0 ``` """ falses(dims::DimOrInd...) = falses(dims) @@ -387,8 +387,8 @@ Create a `BitArray` with all values set to `true`. ```jldoctest julia> trues(2,3) 2×3 BitArray{2}: - true true true - true true true + 1 1 1 + 1 1 1 ``` """ trues(dims::DimOrInd...) = trues(dims) @@ -524,22 +524,22 @@ The shape is inferred from the `itr` object. ```jldoctest julia> BitArray([1 0; 0 1]) 2×2 BitArray{2}: - true false - false true + 1 0 + 0 1 julia> BitArray(x+y == 3 for x = 1:2, y = 1:3) 2×3 BitArray{2}: - false true false - true false false + 0 1 0 + 1 0 0 julia> BitArray(x+y == 3 for x = 1:2 for y = 1:3) 6-element BitArray{1}: - false - true - false - true - false - false + 0 + 1 + 0 + 1 + 0 + 0 ``` """ BitArray(itr) = gen_bitarray(IteratorSize(itr), itr) @@ -1260,27 +1260,27 @@ values. If `n < 0`, elements are shifted backwards. Equivalent to ```jldoctest julia> B = BitVector([true, false, true, false, false]) 5-element BitArray{1}: - true - false - true - false - false + 1 + 0 + 1 + 0 + 0 julia> B >> 1 5-element BitArray{1}: - false - true - false - true - false + 0 + 1 + 0 + 1 + 0 julia> B >> -1 5-element BitArray{1}: - false - true - false - false - false + 0 + 1 + 0 + 0 + 0 ``` """ (>>)(B::BitVector, i::Union{Int, UInt}) = B >>> i @@ -1298,27 +1298,27 @@ values. If `n < 0`, elements are shifted forwards. Equivalent to ```jldoctest julia> B = BitVector([true, false, true, false, false]) 5-element BitArray{1}: - true - false - true - false - false + 1 + 0 + 1 + 0 + 0 julia> B << 1 5-element BitArray{1}: - false - true - false - false - false + 0 + 1 + 0 + 0 + 0 julia> B << -1 5-element BitArray{1}: - false - true - false - true - false + 0 + 1 + 0 + 1 + 0 ``` """ (<<)(B::BitVector, i::Int) = (i >=0 ? B << unsigned(i) : B >> unsigned(-i)) diff --git a/base/bool.jl b/base/bool.jl index 950540a039546..0243f50e98763 100644 --- a/base/bool.jl +++ b/base/bool.jl @@ -27,7 +27,7 @@ missing julia> .![true false true] 1×3 BitArray{2}: - false true false + 0 1 0 ``` """ function !(x::Bool) @@ -67,9 +67,9 @@ false julia> [true; true; false] .⊻ [true; false; false] 3-element BitArray{1}: - false - true - false + 0 + 1 + 0 ``` """ xor(x::Bool, y::Bool) = (x != y) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index f4589ca2c6d96..06bca9cd02d62 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -1371,33 +1371,33 @@ Return unique regions of `A` along dimension `dims`. julia> A = map(isodd, reshape(Vector(1:8), (2,2,2))) 2×2×2 Array{Bool,3}: [:, :, 1] = - true true - false false + 1 1 + 0 0 [:, :, 2] = - true true - false false + 1 1 + 0 0 julia> unique(A) 2-element Array{Bool,1}: - true - false + 1 + 0 julia> unique(A, dims=2) 2×1×2 Array{Bool,3}: [:, :, 1] = - true - false + 1 + 0 [:, :, 2] = - true - false + 1 + 0 julia> unique(A, dims=3) 2×2×1 Array{Bool,3}: [:, :, 1] = - true true - false false + 1 1 + 0 0 ``` """ unique(A::AbstractArray; dims::Union{Colon,Integer} = :) = _unique_dims(A, dims) diff --git a/base/reduce.jl b/base/reduce.jl index 6cbc6b1b5b83e..63694299d7da3 100644 --- a/base/reduce.jl +++ b/base/reduce.jl @@ -565,10 +565,10 @@ values are `false` (or equivalently, if the input contains no `true` value), fol ```jldoctest julia> a = [true,false,false,true] 4-element Array{Bool,1}: - true - false - false - true + 1 + 0 + 0 + 1 julia> any(a) true @@ -600,10 +600,10 @@ values are `true` (or equivalently, if the input contains no `false` value), fol ```jldoctest julia> a = [true,false,false,true] 4-element Array{Bool,1}: - true - false - false - true + 1 + 0 + 0 + 1 julia> all(a) false diff --git a/base/reducedim.jl b/base/reducedim.jl index 3a3f9f14469c8..7b005aeff4f10 100644 --- a/base/reducedim.jl +++ b/base/reducedim.jl @@ -294,11 +294,11 @@ julia> a = reshape(Vector(1:16), (4,4)) julia> mapreduce(isodd, *, a, dims=1) 1×4 Array{Bool,2}: - false false false false + 0 0 0 0 julia> mapreduce(isodd, |, a, dims=1) 1×4 Array{Bool,2}: - true true true true + 1 1 1 1 ``` """ mapreduce(f, op, A::AbstractArray; dims=:, kw...) = _mapreduce_dim(f, op, kw.data, A, dims) @@ -553,17 +553,17 @@ Test whether all values along the given dimensions of an array are `true`. ```jldoctest julia> A = [true false; true true] 2×2 Array{Bool,2}: - true false - true true + 1 0 + 1 1 julia> all(A, dims=1) 1×2 Array{Bool,2}: - true false + 1 0 julia> all(A, dims=2) 2×1 Array{Bool,2}: - false - true + 0 + 1 ``` """ all(A::AbstractArray; dims) @@ -577,8 +577,8 @@ Test whether all values in `A` along the singleton dimensions of `r` are `true`, ```jldoctest julia> A = [true false; true false] 2×2 Array{Bool,2}: - true false - true false + 1 0 + 1 0 julia> all!([1; 1], A) 2-element Array{Int64,1}: @@ -601,17 +601,17 @@ Test whether any values along the given dimensions of an array are `true`. ```jldoctest julia> A = [true false; true false] 2×2 Array{Bool,2}: - true false - true false + 1 0 + 1 0 julia> any(A, dims=1) 1×2 Array{Bool,2}: - true false + 1 0 julia> any(A, dims=2) 2×1 Array{Bool,2}: - true - true + 1 + 1 ``` """ any(::AbstractArray; dims) @@ -626,8 +626,8 @@ results to `r`. ```jldoctest julia> A = [true false; true false] 2×2 Array{Bool,2}: - true false - true false + 1 0 + 1 0 julia> any!([1; 1], A) 2-element Array{Int64,1}: diff --git a/base/show.jl b/base/show.jl index 6dbc48423a609..b31d3a3438bc1 100644 --- a/base/show.jl +++ b/base/show.jl @@ -564,7 +564,7 @@ end show(io::IO, ::Nothing) = print(io, "nothing") print(io::IO, ::Nothing) = throw(ArgumentError("`nothing` should not be printed; use `show`, `repr`, or custom output instead.")) -show(io::IO, b::Bool) = print(io, b ? "true" : "false") +show(io::IO, b::Bool) = print(io, get(io, :typeinfo, Any) === Bool ? (b ? "1" : "0") : (b ? "true" : "false")) show(io::IO, n::Signed) = (write(io, string(n)); nothing) show(io::IO, n::Unsigned) = print(io, "0x", string(n, pad = sizeof(n)<<1, base = 16)) print(io::IO, n::Unsigned) = print(io, string(n)) diff --git a/doc/src/manual/arrays.md b/doc/src/manual/arrays.md index 4667fb4fd6e05..c1c4682228c73 100644 --- a/doc/src/manual/arrays.md +++ b/doc/src/manual/arrays.md @@ -634,10 +634,10 @@ julia> x[[false, true, true, false], :] julia> mask = map(ispow2, x) 4×4 Array{Bool,2}: - true false false false - true false false false - false false false false - true true false true + 1 0 0 0 + 1 0 0 0 + 0 0 0 0 + 1 1 0 1 julia> x[mask] 5-element Array{Int64,1}: diff --git a/doc/src/manual/strings.md b/doc/src/manual/strings.md index fac4988ac12c6..7832bbaed439a 100644 --- a/doc/src/manual/strings.md +++ b/doc/src/manual/strings.md @@ -376,10 +376,10 @@ julia> foreach(display, s) julia> isvalid.(collect(s)) 4-element BitArray{1}: - false - false - false - true + 0 + 0 + 0 + 1 julia> s2 = "\xf7\xbf\xbf\xbf" "\U1fffff" diff --git a/stdlib/Random/src/misc.jl b/stdlib/Random/src/misc.jl index 1922c5c066b62..1ba53a5232f48 100644 --- a/stdlib/Random/src/misc.jl +++ b/stdlib/Random/src/misc.jl @@ -21,16 +21,16 @@ julia> rng = MersenneTwister(1234); julia> bitrand(rng, 10) 10-element BitArray{1}: - false - true - true - true - true - false - true - false - false - true + 0 + 1 + 1 + 1 + 1 + 0 + 1 + 0 + 0 + 1 ``` """ bitrand(r::AbstractRNG, dims::Dims) = rand!(r, BitArray(undef, dims)) diff --git a/test/show.jl b/test/show.jl index 562e8f9c3c564..be47c0cdd3103 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1433,5 +1433,13 @@ replstrcolor(x) = sprint((io, x) -> show(IOContext(io, :limit => true, :color => # issue #30303 @test repr(Symbol("a\$")) == "Symbol(\"a\\\$\")" +# printing of bools and bool arrays +@testset "Bool" begin + @test repr(true) == "true" + @test repr(Number[true, false]) == "Number[true, false]" + @test repr([true, false]) == "Bool[1, 0]" == repr(BitVector([true, false])) + @test_repr "Bool[1, 0]" +end + # issue #30505 @test repr(Union{Tuple{Char}, Tuple{Char, Char}}[('a','b')]) == "Union{Tuple{Char}, Tuple{Char,Char}}[('a', 'b')]"