Skip to content

Commit 5a0ed4a

Browse files
committed
Merge pull request #14254 from danielarndt/documentation-eachindex
Fix invalid documentation about eachindex
2 parents 2b56de1 + 8267848 commit 5a0ed4a

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

base/docs/helpdb.jl

+24-23
Original file line numberDiff line numberDiff line change
@@ -3320,29 +3320,30 @@ Creates an iterable object for visiting each index of an AbstractArray `A` in an
33203320
33213321
Example for a sparse 2-d array:
33223322
3323-
julia> A = sprand(2, 3, 0.5)
3324-
2x3 sparse matrix with 4 Float64 entries:
3325-
[1, 1] = 0.598888
3326-
[1, 2] = 0.0230247
3327-
[1, 3] = 0.486499
3328-
[2, 3] = 0.809041
3329-
3330-
julia> for iter in eachindex(A)
3331-
@show iter.I_1, iter.I_2
3332-
@show A[iter]
3333-
end
3334-
(iter.I_1,iter.I_2) = (1,1)
3335-
A[iter] = 0.5988881393454597
3336-
(iter.I_1,iter.I_2) = (2,1)
3337-
A[iter] = 0.0
3338-
(iter.I_1,iter.I_2) = (1,2)
3339-
A[iter] = 0.02302469881746183
3340-
(iter.I_1,iter.I_2) = (2,2)
3341-
A[iter] = 0.0
3342-
(iter.I_1,iter.I_2) = (1,3)
3343-
A[iter] = 0.4864987874354343
3344-
(iter.I_1,iter.I_2) = (2,3)
3345-
A[iter] = 0.8090413606455655
3323+
```jldoctest
3324+
julia> A = sparse([1, 1, 2], [1, 3, 1], [1, 2, -5])
3325+
2x3 sparse matrix with 3 Int64 entries:
3326+
[1, 1] = 1
3327+
[2, 1] = -5
3328+
[1, 3] = 2
3329+
3330+
julia> for iter in eachindex(A)
3331+
@show iter.I[1], iter.I[2]
3332+
@show A[iter]
3333+
end
3334+
(iter.I[1],iter.I[2]) = (1,1)
3335+
A[iter] = 1
3336+
(iter.I[1],iter.I[2]) = (2,1)
3337+
A[iter] = -5
3338+
(iter.I[1],iter.I[2]) = (1,2)
3339+
A[iter] = 0
3340+
(iter.I[1],iter.I[2]) = (2,2)
3341+
A[iter] = 0
3342+
(iter.I[1],iter.I[2]) = (1,3)
3343+
A[iter] = 2
3344+
(iter.I[1],iter.I[2]) = (2,3)
3345+
A[iter] = 0
3346+
```
33463347
33473348
If you supply more than one ``AbstractArray`` argument, ``eachindex``
33483349
will create an iterable object that is fast for all arguments (a

doc/stdlib/arrays.rst

+19-20
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,30 @@ Basic functions
5151

5252
Example for a sparse 2-d array:
5353

54-
.. code-block:: julia
54+
.. doctest::
5555

56-
julia> A = sprand(2, 3, 0.5)
57-
2x3 sparse matrix with 4 Float64 entries:
58-
[1, 1] = 0.598888
59-
[1, 2] = 0.0230247
60-
[1, 3] = 0.486499
61-
[2, 3] = 0.809041
56+
julia> A = sparse([1, 1, 2], [1, 3, 1], [1, 2, -5])
57+
2x3 sparse matrix with 3 Int64 entries:
58+
[1, 1] = 1
59+
[2, 1] = -5
60+
[1, 3] = 2
6261

6362
julia> for iter in eachindex(A)
64-
@show iter.I_1, iter.I_2
63+
@show iter.I[1], iter.I[2]
6564
@show A[iter]
6665
end
67-
(iter.I_1,iter.I_2) = (1,1)
68-
A[iter] = 0.5988881393454597
69-
(iter.I_1,iter.I_2) = (2,1)
70-
A[iter] = 0.0
71-
(iter.I_1,iter.I_2) = (1,2)
72-
A[iter] = 0.02302469881746183
73-
(iter.I_1,iter.I_2) = (2,2)
74-
A[iter] = 0.0
75-
(iter.I_1,iter.I_2) = (1,3)
76-
A[iter] = 0.4864987874354343
77-
(iter.I_1,iter.I_2) = (2,3)
78-
A[iter] = 0.8090413606455655
66+
(iter.I[1],iter.I[2]) = (1,1)
67+
A[iter] = 1
68+
(iter.I[1],iter.I[2]) = (2,1)
69+
A[iter] = -5
70+
(iter.I[1],iter.I[2]) = (1,2)
71+
A[iter] = 0
72+
(iter.I[1],iter.I[2]) = (2,2)
73+
A[iter] = 0
74+
(iter.I[1],iter.I[2]) = (1,3)
75+
A[iter] = 2
76+
(iter.I[1],iter.I[2]) = (2,3)
77+
A[iter] = 0
7978

8079
If you supply more than one ``AbstractArray`` argument, ``eachindex`` will create an iterable object that is fast for all arguments (a ``UnitRange`` if all inputs have fast linear indexing, a CartesianRange otherwise). If the arrays have different sizes and/or dimensionalities, ``eachindex`` returns an iterable that spans the largest range along each dimension.
8180

doc/stdlib/base.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,8 @@ System
861861
* ``detach::Bool``\ : If ``true`` (defaults to ``false``\ ), then the ``Cmd`` will be run in a new process group, allowing it to outlive the ``julia`` process and not have Ctrl-C passed to it.
862862
* ``windows_verbatim::Bool``\ : If ``true`` (defaults to ``false``\ ), then on Windows the ``Cmd`` will send a command-line string to the process with no quoting or escaping of arguments, even arguments containing spaces. (On Windows, arguments are sent to a program as a single "command-line" string, and programs are responsible for parsing it into arguments. By default, empty arguments and arguments with spaces or tabs are quoted with double quotes ``"`` in the command line, and ``\`` or ``"`` are preceded by backslashes. ``windows_verbatim=true`` is useful for launching programs that parse their command line in nonstandard ways.) Has no effect on non-Windows systems.
863863
* ``windows_hide::Bool``\ : If ``true`` (defaults to ``false``\ ), then on Windows no new console window is displayed when the ``Cmd`` is executed. This has no effect if a console is already open or on non-Windows systems.
864-
* ``env``\ : Set environment variables to use when running the ``Cmd``\ . ``env`` is either a dictionary mapping strings to strings, an array of strings of the form ``"var=val"``\ , an array or tuple of ``"var"=>val`` pairs, or ``nothing``\ . In order to modify (rather than replace) the existing environment, create ``env`` by ``copy(ENV)`` and then set ``env["var"]=val`` as desired.
865-
* ``dir::AbstractString``\ : Specify a working directory for the command (instead of the current directory).
864+
* ``env``\ : Set environment variables to use when running the ``Cmd``\ . ``env`` is either a dictionary mapping strings to strings, an array of strings of the form ``"var=val"``\ , an array or tuple of ``"var"=>val`` pairs, or ``nothing``\ . In order to modify (rather than replace) the existing environment, create ``env`` by ``copy(ENV)`` and then set ``env["var"]=val`` as desired.
865+
* ``dir::AbstractString``\ : Specify a working directory for the command (instead of the current directory).
866866

867867
For any keywords that are not specified, the current settings from ``cmd`` are used. Normally, to create a ``Cmd`` object in the first place, one uses backticks, e.g.
868868

doc/stdlib/pkg.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Functions for package development (e.g. ``tag``, ``publish``, etc.) have been mo
109109

110110
.. Docstring generated from Julia source
111111
112-
Checkout the ``Pkg.dir(pkg)`` repo to the branch ``branch``\ . Defaults to checking out the "master" branch. To go back to using the newest compatible released version, use ``Pkg.free(pkg)``\ . Changes are merged (fast-forward only) if the keyword argument ``merge == true``, and the latest version is pulled from the upsream repo if ``pull == true``\ .
112+
Checkout the ``Pkg.dir(pkg)`` repo to the branch ``branch``\ . Defaults to checking out the "master" branch. To go back to using the newest compatible released version, use ``Pkg.free(pkg)``\ . Changes are merged (fast-forward only) if the keyword argument ``merge == true``\ , and the latest version is pulled from the upsream repo if ``pull == true``\ .
113113

114114
.. function:: pin(pkg)
115115

0 commit comments

Comments
 (0)