Skip to content

Commit

Permalink
show: print types using exported type-aliases
Browse files Browse the repository at this point in the history
For example, this prints Array{T,1} as Vector{T} and Array{T,2} as
Matrix{T} and Base.GenericIOBuffer{Array{UInt8,1}} as IOBuffer,
and generalizes some existing code.

Co-authored-by: Kristoffer Carlsson <kristoffer.carlsson@chalmers.se>
  • Loading branch information
vtjnash and KristofferC committed Jun 18, 2020
1 parent 1f8b442 commit e3b640e
Show file tree
Hide file tree
Showing 141 changed files with 1,422 additions and 1,196 deletions.
54 changes: 27 additions & 27 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ 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}:
2-element BitVector:
0
0
```
Expand Down Expand Up @@ -825,7 +825,7 @@ julia> y = zeros(7);
julia> copyto!(y, x);
julia> y
7-element Array{Float64,1}:
7-element Vector{Float64}:
1.0
0.0
3.0
Expand Down Expand Up @@ -955,7 +955,7 @@ julia> tup = (1, 2, 3)
(1, 2, 3)
julia> Base.copymutable(tup)
3-element Array{Int64,1}:
3-element Vector{Int64}:
1
2
3
Expand Down Expand Up @@ -1023,20 +1023,20 @@ Return a subset of array `A` as specified by `inds`, where each `ind` may be an
# Examples
```jldoctest
julia> A = [1 2; 3 4]
2×2 Array{Int64,2}:
2×2 Matrix{Int64}:
1 2
3 4
julia> getindex(A, 1)
1
julia> getindex(A, [2, 1])
2-element Array{Int64,1}:
2-element Vector{Int64}:
3
1
julia> getindex(A, 2:4)
3-element Array{Int64,1}:
3-element Vector{Int64}:
3
2
4
Expand Down Expand Up @@ -1131,7 +1131,7 @@ julia> setindex!(A, [10, 20], [1, 2]);
julia> A[[3, 4]] = [30, 40];
julia> A
2×2 Array{Float64,2}:
2×2 Matrix{Float64}:
10.0 30.0
20.0 40.0
```
Expand Down Expand Up @@ -1188,17 +1188,17 @@ during object creation. If the input is not a wrapped object, return the input i
# Examples
```jldoctest
julia> A = [1 2; 3 4]
2×2 Array{Int64,2}:
2×2 Matrix{Int64}:
1 2
3 4
julia> V = view(A, 1:2, :)
2×2 view(::Array{Int64,2}, 1:2, :) with eltype Int64:
2×2 view(::Matrix{Int64}, 1:2, :) with eltype Int64:
1 2
3 4
julia> parent(V)
2×2 Array{Int64,2}:
2×2 Matrix{Int64}:
1 2
3 4
```
Expand Down Expand Up @@ -1546,16 +1546,16 @@ Concatenate along dimension 1.
# Examples
```jldoctest
julia> a = [1 2 3 4 5]
1×5 Array{Int64,2}:
1×5 Matrix{Int64}:
1 2 3 4 5
julia> b = [6 7 8 9 10; 11 12 13 14 15]
2×5 Array{Int64,2}:
2×5 Matrix{Int64}:
6 7 8 9 10
11 12 13 14 15
julia> vcat(a,b)
3×5 Array{Int64,2}:
3×5 Matrix{Int64}:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
Expand All @@ -1564,7 +1564,7 @@ julia> c = ([1 2 3], [4 5 6])
([1 2 3], [4 5 6])
julia> vcat(c...)
2×3 Array{Int64,2}:
2×3 Matrix{Int64}:
1 2 3
4 5 6
```
Expand All @@ -1578,23 +1578,23 @@ Concatenate along dimension 2.
# Examples
```jldoctest
julia> a = [1; 2; 3; 4; 5]
5-element Array{Int64,1}:
5-element Vector{Int64}:
1
2
3
4
5
julia> b = [6 7; 8 9; 10 11; 12 13; 14 15]
5×2 Array{Int64,2}:
5×2 Matrix{Int64}:
6 7
8 9
10 11
12 13
14 15
julia> hcat(a,b)
5×3 Array{Int64,2}:
5×3 Matrix{Int64}:
1 6 7
2 8 9
3 10 11
Expand All @@ -1605,16 +1605,16 @@ julia> c = ([1; 2; 3], [4; 5; 6])
([1, 2, 3], [4, 5, 6])
julia> hcat(c...)
3×2 Array{Int64,2}:
3×2 Matrix{Int64}:
1 4
2 5
3 6
julia> x = Matrix(undef, 3, 0) # x = [] would have created an Array{Any, 1}, but need an Array{Any, 2}
3×0 Array{Any,2}
3×0 Matrix{Any}
julia> hcat(x, [1; 2; 3])
3×1 Array{Any,2}:
3×1 Matrix{Any}:
1
2
3
Expand Down Expand Up @@ -1683,23 +1683,23 @@ julia> a, b, c, d, e, f = 1, 2, 3, 4, 5, 6
(1, 2, 3, 4, 5, 6)
julia> [a b c; d e f]
2×3 Array{Int64,2}:
2×3 Matrix{Int64}:
1 2 3
4 5 6
julia> hvcat((3,3), a,b,c,d,e,f)
2×3 Array{Int64,2}:
2×3 Matrix{Int64}:
1 2 3
4 5 6
julia> [a b;c d; e f]
3×2 Array{Int64,2}:
3×2 Matrix{Int64}:
1 2
3 4
5 6
julia> hvcat((2,2,2), a,b,c,d,e,f)
3×2 Array{Int64,2}:
3×2 Matrix{Int64}:
1 2
3 4
5 6
Expand Down Expand Up @@ -2164,13 +2164,13 @@ See also: [`mapslices`](@ref)
# Examples
```jldoctest
julia> map(x -> x * 2, [1, 2, 3])
3-element Array{Int64,1}:
3-element Vector{Int64}:
2
4
6
julia> map(+, [1, 2, 3], [10, 20, 30])
3-element Array{Int64,1}:
3-element Vector{Int64}:
11
22
33
Expand Down Expand Up @@ -2223,7 +2223,7 @@ julia> a = zeros(3);
julia> map!(x -> x * 2, a, [1, 2, 3]);
julia> a
3-element Array{Float64,1}:
3-element Vector{Float64}:
2.0
4.0
6.0
Expand Down
46 changes: 23 additions & 23 deletions base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ mutable, in which case modifying one will also modify the other.
# Examples
```jldoctest
julia> a = [1 2 3; 4 5 6]
2×3 Array{Int64,2}:
2×3 Matrix{Int64}:
1 2 3
4 5 6
julia> vec(a)
6-element Array{Int64,1}:
6-element Vector{Int64}:
1
4
2
Expand Down Expand Up @@ -109,12 +109,12 @@ Equivalent to `view(A,:,:,...,i,:,:,...)` where `i` is in position `d`.
# Examples
```jldoctest
julia> A = [1 2 3 4; 5 6 7 8]
2×4 Array{Int64,2}:
2×4 Matrix{Int64}:
1 2 3 4
5 6 7 8
julia> selectdim(A, 2, 3)
2-element view(::Array{Int64,2}, :, 3) with eltype Int64:
2-element view(::Matrix{Int64}, :, 3) with eltype Int64:
3
7
```
Expand All @@ -135,12 +135,12 @@ Reverse `A` in dimension `dims`.
# Examples
```jldoctest
julia> b = [1 2; 3 4]
2×2 Array{Int64,2}:
2×2 Matrix{Int64}:
1 2
3 4
julia> reverse(b, dims=2)
2×2 Array{Int64,2}:
2×2 Matrix{Int64}:
2 1
4 3
```
Expand Down Expand Up @@ -191,44 +191,44 @@ first dimension.
# Examples
```jldoctest
julia> b = reshape(Vector(1:16), (4,4))
4×4 Array{Int64,2}:
4×4 Matrix{Int64}:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
julia> circshift(b, (0,2))
4×4 Array{Int64,2}:
4×4 Matrix{Int64}:
9 13 1 5
10 14 2 6
11 15 3 7
12 16 4 8
julia> circshift(b, (-1,0))
4×4 Array{Int64,2}:
4×4 Matrix{Int64}:
2 6 10 14
3 7 11 15
4 8 12 16
1 5 9 13
julia> a = BitArray([true, true, false, false, true])
5-element BitArray{1}:
5-element BitVector:
1
1
0
0
1
julia> circshift(a, 1)
5-element BitArray{1}:
5-element BitVector:
1
1
1
0
0
julia> circshift(a, -1)
5-element BitArray{1}:
5-element BitVector:
1
0
0
Expand All @@ -252,7 +252,7 @@ Construct an array by repeating array `A` a given number of times in each dimens
# Examples
```jldoctest
julia> repeat([1, 2, 3], 2)
6-element Array{Int64,1}:
6-element Vector{Int64}:
1
2
3
Expand All @@ -261,7 +261,7 @@ julia> repeat([1, 2, 3], 2)
3
julia> repeat([1, 2, 3], 2, 3)
6×3 Array{Int64,2}:
6×3 Matrix{Int64}:
1 1 1
2 2 2
3 3 3
Expand All @@ -286,21 +286,21 @@ is performed.
# Examples
```jldoctest
julia> repeat(1:2, inner=2)
4-element Array{Int64,1}:
4-element Vector{Int64}:
1
1
2
2
julia> repeat(1:2, outer=2)
4-element Array{Int64,1}:
4-element Vector{Int64}:
1
2
1
2
julia> repeat([1 2; 3 4], inner=(2, 1), outer=(1, 3))
4×6 Array{Int64,2}:
4×6 Matrix{Int64}:
1 2 1 2 1 2
1 2 1 2 1 2
3 4 3 4 3 4
Expand Down Expand Up @@ -451,17 +451,17 @@ See also [`eachcol`](@ref) and [`eachslice`](@ref).
```jldoctest
julia> a = [1 2; 3 4]
2×2 Array{Int64,2}:
2×2 Matrix{Int64}:
1 2
3 4
julia> first(eachrow(a))
2-element view(::Array{Int64,2}, 1, :) with eltype Int64:
2-element view(::Matrix{Int64}, 1, :) with eltype Int64:
1
2
julia> collect(eachrow(a))
2-element Array{SubArray{Int64,1,Array{Int64,2},Tuple{Int64,Base.Slice{Base.OneTo{Int64}}},true},1}:
2-element Vector{SubArray{Int64,1,Matrix{Int64},Tuple{Int64,Base.Slice{Base.OneTo{Int64}}},true}}:
[1, 2]
[3, 4]
```
Expand All @@ -484,17 +484,17 @@ See also [`eachrow`](@ref) and [`eachslice`](@ref).
```jldoctest
julia> a = [1 2; 3 4]
2×2 Array{Int64,2}:
2×2 Matrix{Int64}:
1 2
3 4
julia> first(eachcol(a))
2-element view(::Array{Int64,2}, :, 1) with eltype Int64:
2-element view(::Matrix{Int64}, :, 1) with eltype Int64:
1
3
julia> collect(eachcol(a))
2-element Array{SubArray{Int64,1,Array{Int64,2},Tuple{Base.Slice{Base.OneTo{Int64}},Int64},true},1}:
2-element Vector{SubArray{Int64,1,Matrix{Int64},Tuple{Base.Slice{Base.OneTo{Int64}},Int64},true}}:
[1, 3]
[2, 4]
```
Expand Down
Loading

0 comments on commit e3b640e

Please sign in to comment.