Skip to content

Commit 2d24eda

Browse files
authored
Move math docs out of HelpDB, more examples, fix typos (#17791)
* Move math docs out of HelpDB, more examples, fix typos Found a series of typos in `cov` and friends. Added more notes about `NaN` and Julia. Made the function signatures reflect what's actually in the code. More examples for quite a few functions. * Move quadgk docs out, update formatting * Moved special functions out of HelpDB, insert some links * Updated docs for some array ops as well * Updated in response to feedback Removed calls to `rand` in doctests. Made examples better. Cleaned up function signatures.
1 parent 6d3e337 commit 2d24eda

19 files changed

+751
-400
lines changed

base/abstractarray.jl

+111-2
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,80 @@ function cat_t(catdims, typeC::Type, X...)
10171017
return C
10181018
end
10191019

1020+
"""
1021+
vcat(A...)
1022+
1023+
Concatenate along dimension 1.
1024+
1025+
```jldoctest
1026+
julia> a = [1 2 3 4 5]
1027+
1×5 Array{Int64,2}:
1028+
1 2 3 4 5
1029+
1030+
julia> b = [6 7 8 9 10; 11 12 13 14 15]
1031+
2×5 Array{Int64,2}:
1032+
6 7 8 9 10
1033+
11 12 13 14 15
1034+
1035+
julia> vcat(a,b)
1036+
3×5 Array{Int64,2}:
1037+
1 2 3 4 5
1038+
6 7 8 9 10
1039+
11 12 13 14 15
1040+
1041+
julia> c = ([1 2 3], [4 5 6])
1042+
(
1043+
[1 2 3],
1044+
<BLANKLINE>
1045+
[4 5 6])
1046+
1047+
julia> vcat(c...)
1048+
2×3 Array{Int64,2}:
1049+
1 2 3
1050+
4 5 6
1051+
```
1052+
"""
10201053
vcat(X...) = cat(1, X...)
1054+
"""
1055+
hcat(A...)
1056+
1057+
Concatenate along dimension 2.
1058+
1059+
```jldoctest
1060+
julia> a = [1; 2; 3; 4; 5]
1061+
5-element Array{Int64,1}:
1062+
1
1063+
2
1064+
3
1065+
4
1066+
5
1067+
1068+
julia> b = [6 7; 8 9; 10 11; 12 13; 14 15]
1069+
5×2 Array{Int64,2}:
1070+
6 7
1071+
8 9
1072+
10 11
1073+
12 13
1074+
14 15
1075+
1076+
julia> hcat(a,b)
1077+
5×3 Array{Int64,2}:
1078+
1 6 7
1079+
2 8 9
1080+
3 10 11
1081+
4 12 13
1082+
5 14 15
1083+
1084+
julia> c = ([1; 2; 3], [4; 5; 6])
1085+
([1,2,3],[4,5,6])
1086+
1087+
julia> hcat(c...)
1088+
3×2 Array{Int64,2}:
1089+
1 4
1090+
2 5
1091+
3 6
1092+
```
1093+
"""
10211094
hcat(X...) = cat(2, X...)
10221095

10231096
typed_vcat(T::Type, X...) = cat_t(1, T, X...)
@@ -1054,6 +1127,43 @@ function hvcat(nbc::Integer, as...)
10541127
hvcat(ntuple(i->nbc, nbr), as...)
10551128
end
10561129

1130+
"""
1131+
hvcat(rows::Tuple{Vararg{Int}}, values...)
1132+
1133+
Horizontal and vertical concatenation in one call. This function is called for block matrix
1134+
syntax. The first argument specifies the number of arguments to concatenate in each block
1135+
row.
1136+
1137+
```jldoctest
1138+
julia> a, b, c, d, e, f = 1, 2, 3, 4, 5, 6
1139+
(1,2,3,4,5,6)
1140+
1141+
julia> [a b c; d e f]
1142+
2×3 Array{Int64,2}:
1143+
1 2 3
1144+
4 5 6
1145+
1146+
julia> hvcat((3,3), a,b,c,d,e,f)
1147+
2×3 Array{Int64,2}:
1148+
1 2 3
1149+
4 5 6
1150+
1151+
julia> [a b;c d; e f]
1152+
3×2 Array{Int64,2}:
1153+
1 2
1154+
3 4
1155+
5 6
1156+
1157+
julia> hvcat((2,2,2), a,b,c,d,e,f)
1158+
3×2 Array{Int64,2}:
1159+
1 2
1160+
3 4
1161+
5 6
1162+
```
1163+
1164+
If the first argument is a single integer `n`, then all block rows are assumed to have `n`
1165+
block columns.
1166+
"""
10571167
hvcat(rows::Tuple{Vararg{Int}}, xs::AbstractMatrix...) = typed_hvcat(promote_eltype(xs...), rows, xs...)
10581168
hvcat{T}(rows::Tuple{Vararg{Int}}, xs::AbstractMatrix{T}...) = typed_hvcat(T, rows, xs...)
10591169

@@ -1340,8 +1450,7 @@ For multiple iterable arguments, `f` is called elementwise.
13401450
needed, for example in `foreach(println, array)`.
13411451
13421452
```jldoctest
1343-
julia> a
1344-
1:3:7
1453+
julia> a = 1:3:7;
13451454
13461455
julia> foreach(x->println(x^2),a)
13471456
1

base/abstractarraymath.jl

+89
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,55 @@ transpose(a::AbstractArray) = error("transpose not implemented for $(typeof(a)).
1111

1212
## Constructors ##
1313

14+
"""
15+
vec(a::AbstractArray) -> Vector
16+
17+
Reshape array `a` as a one-dimensional column vector.
18+
19+
```jldoctest
20+
julia> a = [1 2 3; 4 5 6]
21+
2×3 Array{Int64,2}:
22+
1 2 3
23+
4 5 6
24+
25+
julia> vec(a)
26+
6-element Array{Int64,1}:
27+
1
28+
4
29+
2
30+
5
31+
3
32+
6
33+
```
34+
"""
1435
vec(a::AbstractArray) = reshape(a,_length(a))
1536
vec(a::AbstractVector) = a
1637

1738
_sub(::Tuple{}, ::Tuple{}) = ()
1839
_sub(t::Tuple, ::Tuple{}) = t
1940
_sub(t::Tuple, s::Tuple) = _sub(tail(t), tail(s))
2041

42+
"""
43+
squeeze(A, dims)
44+
45+
Remove the dimensions specified by `dims` from array `A`.
46+
Elements of `dims` must be unique and within the range `1:ndims(A)`.
47+
`size(A,i)` must equal 1 for all `i` in `dims`.
48+
49+
```jldoctest
50+
julia> a = reshape(collect(1:4),(2,2,1,1))
51+
2×2×1×1 Array{Int64,4}:
52+
[:, :, 1, 1] =
53+
1 3
54+
2 4
55+
56+
julia> squeeze(a,3)
57+
2×2×1 Array{Int64,3}:
58+
[:, :, 1] =
59+
1 3
60+
2 4
61+
```
62+
"""
2163
function squeeze(A::AbstractArray, dims::Dims)
2264
for i in 1:length(dims)
2365
1 <= dims[i] <= ndims(A) || throw(ArgumentError("squeezed dims must be in range 1:ndims(A)"))
@@ -71,6 +113,23 @@ function flipdim(A::AbstractVector, d::Integer)
71113
reverse(A)
72114
end
73115

116+
"""
117+
flipdim(A, d)
118+
119+
Reverse `A` in dimension `d`.
120+
121+
```jldoctest
122+
julia> b = [1 2; 3 4]
123+
2×2 Array{Int64,2}:
124+
1 2
125+
3 4
126+
127+
julia> flipdim(b,2)
128+
2×2 Array{Int64,2}:
129+
2 1
130+
4 3
131+
```
132+
"""
74133
function flipdim(A::AbstractArray, d::Integer)
75134
nd = ndims(A)
76135
1 d nd || throw(ArgumentError("dimension $d is not 1 ≤ $d$nd"))
@@ -100,6 +159,36 @@ function flipdim(A::AbstractArray, d::Integer)
100159
end
101160

102161
circshift(a::AbstractArray, shiftamt::Real) = circshift(a, [Integer(shiftamt)])
162+
163+
"""
164+
circshift(A, shifts)
165+
166+
Circularly shift the data in an array. The second argument is a vector giving the amount to
167+
shift in each dimension.
168+
169+
```jldoctest
170+
julia> b = reshape(collect(1:16), (4,4))
171+
4×4 Array{Int64,2}:
172+
1 5 9 13
173+
2 6 10 14
174+
3 7 11 15
175+
4 8 12 16
176+
177+
julia> circshift(b, [0,2])
178+
4×4 Array{Int64,2}:
179+
9 13 1 5
180+
10 14 2 6
181+
11 15 3 7
182+
12 16 4 8
183+
184+
julia> circshift(b, [-1,0])
185+
4×4 Array{Int64,2}:
186+
2 6 10 14
187+
3 7 11 15
188+
4 8 12 16
189+
1 5 9 13
190+
```
191+
"""
103192
function circshift{T,N}(a::AbstractArray{T,N}, shiftamts)
104193
I = ()
105194
for i=1:N

base/array.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ function hcat{T}(V::Vector{T}...)
667667
end
668668
return [ V[j][i]::T for i=1:length(V[1]), j=1:length(V) ]
669669
end
670+
670671
function vcat{T}(arrays::Vector{T}...)
671672
n = 0
672673
for a in arrays
@@ -860,7 +861,7 @@ Returns the minimum element and its index.
860861
The collection must not be empty.
861862
862863
```jldoctest
863-
julia> findmax([8,0.1,-9,pi])
864+
julia> findmin([8,0.1,-9,pi])
864865
(-9.0,3)
865866
```
866867
"""
@@ -915,7 +916,7 @@ vector contains 0 wherever `a` is not a member of `b`.
915916
```jldoctest
916917
julia> a = ['a', 'b', 'c', 'b', 'd', 'a'];
917918
918-
julia> b = ['a','b','c']
919+
julia> b = ['a','b','c'];
919920
920921
julia> indexin(a,b)
921922
6-element Array{Int64,1}:

0 commit comments

Comments
 (0)