Skip to content

Commit

Permalink
Minor documentation updates (#56883)
Browse files Browse the repository at this point in the history
- Array/Vector/Matrix output showing
- Syntax highlighting for fenced code block examples

---------

Co-authored-by: Chengyu Han <[email protected]>
Co-authored-by: Lilith Orion Hafner <[email protected]>
  • Loading branch information
3 people authored Dec 23, 2024
1 parent 34c30dc commit ccfeb93
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 97 deletions.
12 changes: 6 additions & 6 deletions base/asyncmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ The following examples highlight execution in different tasks by returning
the `objectid` of the tasks in which the mapping function is executed.
First, with `ntasks` undefined, each element is processed in a different task.
```
```julia-repl
julia> tskoid() = objectid(current_task());
julia> asyncmap(x->tskoid(), 1:5)
5-element Array{UInt64,1}:
5-element Vector{UInt64}:
0x6e15e66c75c75853
0x440f8819a1baa682
0x9fb3eeadd0c83985
Expand All @@ -44,9 +44,9 @@ julia> length(unique(asyncmap(x->tskoid(), 1:5)))
```
With `ntasks=2` all elements are processed in 2 tasks.
```
```julia-repl
julia> asyncmap(x->tskoid(), 1:5; ntasks=2)
5-element Array{UInt64,1}:
5-element Vector{UInt64}:
0x027ab1680df7ae94
0xa23d2f80cd7cf157
0x027ab1680df7ae94
Expand All @@ -60,12 +60,12 @@ julia> length(unique(asyncmap(x->tskoid(), 1:5; ntasks=2)))
With `batch_size` defined, the mapping function needs to be changed to accept an array
of argument tuples and return an array of results. `map` is used in the modified mapping
function to achieve this.
```
```julia-repl
julia> batch_func(input) = map(x->string("args_tuple: ", x, ", element_val: ", x[1], ", task: ", tskoid()), input)
batch_func (generic function with 1 method)
julia> asyncmap(batch_func, 1:5; ntasks=2, batch_size=2)
5-element Array{String,1}:
5-element Vector{String}:
"args_tuple: (1,), element_val: 1, task: 9118321258196414413"
"args_tuple: (2,), element_val: 2, task: 4904288162898683522"
"args_tuple: (3,), element_val: 3, task: 9118321258196414413"
Expand Down
32 changes: 16 additions & 16 deletions base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ Assigning `a` to `b` does not create a copy of `b`; instead use [`copy`](@ref) o
```jldoctest
julia> b = [1]; a = b; b[1] = 2; a
1-element Array{Int64, 1}:
1-element Vector{Int64}:
2
julia> b = [1]; a = copy(b); b[1] = 2; a
1-element Array{Int64, 1}:
1-element Vector{Int64}:
1
```
Expand All @@ -420,7 +420,7 @@ julia> function f!(x); x[:] .+= 1; end
f! (generic function with 1 method)
julia> a = [1]; f!(a); a
1-element Array{Int64, 1}:
1-element Vector{Int64}:
2
```
Expand All @@ -439,7 +439,7 @@ julia> a, b
Assignment can operate on multiple variables in series, and will return the value of the right-hand-most expression:
```jldoctest
julia> a = [1]; b = [2]; c = [3]; a = b = c
1-element Array{Int64, 1}:
1-element Vector{Int64}:
3
julia> b[1] = 2; a, b, c
Expand All @@ -449,11 +449,11 @@ julia> b[1] = 2; a, b, c
Assignment at out-of-bounds indices does not grow a collection. If the collection is a [`Vector`](@ref) it can instead be grown with [`push!`](@ref) or [`append!`](@ref).
```jldoctest
julia> a = [1, 1]; a[3] = 2
ERROR: BoundsError: attempt to access 2-element Array{Int64, 1} at index [3]
ERROR: BoundsError: attempt to access 2-element Vector{Int64} at index [3]
[...]
julia> push!(a, 2, 3)
4-element Array{Int64, 1}:
4-element Vector{Int64}:
1
1
2
Expand All @@ -467,7 +467,7 @@ ERROR: DimensionMismatch: tried to assign 0 elements to 1 destinations
[...]
julia> filter!(x -> x > 1, a) # in-place & thus more efficient than a = a[a .> 1]
2-element Array{Int64, 1}:
2-element Vector{Int64}:
2
3
Expand All @@ -490,14 +490,14 @@ assignment expression is converted into a single loop.
julia> A = zeros(4, 4); B = [1, 2, 3, 4];
julia> A .= B
4×4 Array{Float64, 2}:
4×4 Matrix{Float64}:
1.0 1.0 1.0 1.0
2.0 2.0 2.0 2.0
3.0 3.0 3.0 3.0
4.0 4.0 4.0 4.0
julia> A
4×4 Array{Float64, 2}:
4×4 Matrix{Float64}:
1.0 1.0 1.0 1.0
2.0 2.0 2.0 2.0
3.0 3.0 3.0 3.0
Expand Down Expand Up @@ -1018,12 +1018,12 @@ collection or the last index of a dimension of an array.
# Examples
```jldoctest
julia> A = [1 2; 3 4]
2×2 Array{Int64, 2}:
2×2 Matrix{Int64}:
1 2
3 4
julia> A[end, :]
2-element Array{Int64, 1}:
2-element Vector{Int64}:
3
4
```
Expand Down Expand Up @@ -1429,12 +1429,12 @@ collection or the first index of a dimension of an array. For example,
# Examples
```jldoctest
julia> A = [1 2; 3 4]
2×2 Array{Int64,2}:
2×2 Matrix{Int64}:
1 2
3 4
julia> A[begin, :]
2-element Array{Int64,1}:
2-element Matrix{Int64}:
1
2
```
Expand Down Expand Up @@ -2826,7 +2826,7 @@ Construct an uninitialized [`Vector{T}`](@ref) of length `n`.
# Examples
```julia-repl
julia> Vector{Float64}(undef, 3)
3-element Array{Float64, 1}:
3-element Vector{Float64}:
6.90966e-310
6.90966e-310
6.90966e-310
Expand Down Expand Up @@ -2876,7 +2876,7 @@ Construct an uninitialized [`Matrix{T}`](@ref) of size `m`×`n`.
# Examples
```julia-repl
julia> Matrix{Float64}(undef, 2, 3)
2×3 Array{Float64, 2}:
2×3 Matrix{Float64}:
2.36365e-314 2.28473e-314 5.0e-324
2.26704e-314 2.26711e-314 NaN
Expand Down Expand Up @@ -3014,7 +3014,7 @@ an alias for `UndefInitializer()`.
# Examples
```julia-repl
julia> Array{Float64, 1}(UndefInitializer(), 3)
3-element Array{Float64, 1}:
3-element Vector{Float64}:
2.2752528595e-314
2.202942107e-314
2.275252907e-314
Expand Down
4 changes: 2 additions & 2 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ f(y) = [x for x in y]
# Examples
```julia
```julia-repl
julia> f(A::AbstractArray) = g(A)
f (generic function with 1 method)
Expand Down Expand Up @@ -1270,7 +1270,7 @@ The `@world` macro is primarily used in the printing of bindings that are no lon
available in the current world.
## Example
```
```julia-repl
julia> struct Foo; a::Int; end
Foo
Expand Down
18 changes: 9 additions & 9 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ julia> pwd()
"/home/JuliaUser"
julia> cd(readdir, "/home/JuliaUser/Projects/julia")
34-element Array{String,1}:
34-element Vector{String}:
".circleci"
".freebsdci.sh"
".git"
Expand Down Expand Up @@ -211,17 +211,17 @@ julia> mkpath("my/test/dir") # creates three directories
"my/test/dir"
julia> readdir()
1-element Array{String,1}:
1-element Vector{String}:
"my"
julia> cd("my")
julia> readdir()
1-element Array{String,1}:
1-element Vector{String}:
"test"
julia> readdir("test")
1-element Array{String,1}:
1-element Vector{String}:
"dir"
julia> mkpath("intermediate_dir/actually_a_directory.txt") # creates two directories
Expand Down Expand Up @@ -943,7 +943,7 @@ See also: [`walkdir`](@ref).
julia> cd("/home/JuliaUser/dev/julia")
julia> readdir()
30-element Array{String,1}:
30-element Vector{String}:
".appveyor.yml"
".git"
".gitattributes"
Expand All @@ -953,7 +953,7 @@ julia> readdir()
"usr-staging"
julia> readdir(join=true)
30-element Array{String,1}:
30-element Vector{String}:
"/home/JuliaUser/dev/julia/.appveyor.yml"
"/home/JuliaUser/dev/julia/.git"
"/home/JuliaUser/dev/julia/.gitattributes"
Expand All @@ -963,7 +963,7 @@ julia> readdir(join=true)
"/home/JuliaUser/dev/julia/usr-staging"
julia> readdir("base")
145-element Array{String,1}:
145-element Vector{String}:
".gitignore"
"Base.jl"
"Enums.jl"
Expand All @@ -973,7 +973,7 @@ julia> readdir("base")
"weakkeydict.jl"
julia> readdir("base", join=true)
145-element Array{String,1}:
145-element Vector{String}:
"base/.gitignore"
"base/Base.jl"
"base/Enums.jl"
Expand All @@ -983,7 +983,7 @@ julia> readdir("base", join=true)
"base/weakkeydict.jl"
julia> readdir(abspath("base"), join=true)
145-element Array{String,1}:
145-element Vector{String}:
"/home/JuliaUser/dev/julia/base/.gitignore"
"/home/JuliaUser/dev/julia/base/Base.jl"
"/home/JuliaUser/dev/julia/base/Enums.jl"
Expand Down
2 changes: 1 addition & 1 deletion base/genericmemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Fixed-size [`DenseVector{T}`](@ref DenseVector).
`kind` can currently be either `:not_atomic` or `:atomic`. For details on what `:atomic` implies, see [`AtomicMemory`](@ref)
`addrspace` can currently only be set to `Core.CPU`. It is designed to permit extension by other systems such as GPUs, which might define values such as:
```
```julia
module CUDA
const Generic = bitcast(Core.AddrSpace{CUDA}, 0)
const Global = bitcast(Core.AddrSpace{CUDA}, 1)
Expand Down
6 changes: 3 additions & 3 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1313,16 +1313,16 @@ See also: [`circshift`](@ref).
# Examples
```julia-repl
julia> src = 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> dest = OffsetArray{Int}(undef, (0:3,2:5))
julia> dest = OffsetArray{Int}(undef, (0:3,2:5));
julia> circcopy!(dest, src)
OffsetArrays.OffsetArray{Int64,2,Array{Int64,2}} with indices 0:3×2:5:
4×4 OffsetArray(::Matrix{Int64}, 0:3, 2:5) with eltype Int64 with indices 0:3×2:5:
8 12 16 4
5 9 13 1
6 10 14 2
Expand Down
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3150,7 +3150,7 @@ Print to a stream `io`, or return a string `str`, giving a brief description of
a value. By default returns `string(typeof(x))`, e.g. [`Int64`](@ref).
For arrays, returns a string of size and type info,
e.g. `10-element Array{Int64,1}`.
e.g. `10-element Vector{Int64}` or `9×4×5 Array{Float64, 3}`.
# Examples
```jldoctest
Expand Down
4 changes: 2 additions & 2 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function getproperty(stream::LibuvStream, name::Symbol)
end

# IO
# +- GenericIOBuffer{T<:AbstractArray{UInt8,1}} (not exported)
# +- GenericIOBuffer{T<:AbstractVector{UInt8}} (not exported)
# +- AbstractPipe (not exported)
# . +- Pipe
# . +- Process (not exported)
Expand All @@ -89,7 +89,7 @@ end
# . +- TTY (not exported)
# . +- UDPSocket
# . +- BufferStream (FIXME: 2.0)
# +- IOBuffer = Base.GenericIOBuffer{Array{UInt8,1}}
# +- IOBuffer = Base.GenericIOBuffer{Vector{UInt8}}
# +- IOStream

# IOServer
Expand Down
12 changes: 6 additions & 6 deletions doc/src/base/sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ indices that puts the array into sorted order:

```julia-repl
julia> v = randn(5)
5-element Array{Float64,1}:
5-element Vector{Float64}:
0.297288
0.382396
-0.597634
-0.0104452
-0.839027
julia> p = sortperm(v)
5-element Array{Int64,1}:
5-element Vector{Int64}:
5
3
4
1
2
julia> v[p]
5-element Array{Float64,1}:
5-element Vector{Float64}:
-0.839027
-0.597634
-0.0104452
Expand All @@ -69,7 +69,7 @@ Arrays can be sorted according to an arbitrary transformation of their values:

```julia-repl
julia> sort(v, by=abs)
5-element Array{Float64,1}:
5-element Vector{Float64}:
-0.0104452
0.297288
0.382396
Expand All @@ -81,7 +81,7 @@ Or in reverse order by a transformation:

```julia-repl
julia> sort(v, by=abs, rev=true)
5-element Array{Float64,1}:
5-element Vector{Float64}:
-0.839027
-0.597634
0.382396
Expand All @@ -93,7 +93,7 @@ If needed, the sorting algorithm can be chosen:

```julia-repl
julia> sort(v, alg=InsertionSort)
5-element Array{Float64,1}:
5-element Vector{Float64}:
-0.839027
-0.597634
-0.0104452
Expand Down
Loading

0 comments on commit ccfeb93

Please sign in to comment.