Skip to content

Commit 2f04155

Browse files
committed
More doctest examples for BLAS, some cleanup
1 parent cd02f66 commit 2f04155

File tree

1 file changed

+126
-49
lines changed

1 file changed

+126
-49
lines changed

base/linalg/blas.jl

Lines changed: 126 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,41 @@ scal(n, DA, DX, incx) = scal!(n, DA, copy(DX), incx)
217217
218218
Dot product of two vectors consisting of `n` elements of array `X` with stride `incx` and
219219
`n` elements of array `Y` with stride `incy`.
220+
221+
# Example:
222+
```jldoctest
223+
julia> dot(10, ones(10), 1, ones(20), 2)
224+
10.0
225+
```
220226
"""
221227
function dot end
222228

223229
"""
224230
dotc(n, X, incx, U, incy)
225231
226-
Dot function for two complex vectors conjugating the first vector.
232+
Dot function for two complex vectors, consisting of `n` elements of array `X`
233+
with stride `incx` and `n` elements of array `U` with stride `incy`,
234+
conjugating the first vector.
235+
236+
# Example:
237+
```jldoctest
238+
julia> Base.BLAS.dotc(10, im*ones(10), 1, complex(ones(20), ones(20)), 2)
239+
10.0 - 10.0im
240+
```
227241
"""
228242
function dotc end
229243

230244
"""
231245
dotu(n, X, incx, Y, incy)
232246
233-
Dot function for two complex vectors.
247+
Dot function for two complex vectors consisting of `n` elements of array `X`
248+
with stride `incx` and `n` elements of array `Y` with stride `incy`.
249+
250+
# Example:
251+
```jldoctest
252+
julia> Base.BLAS.dotu(10, im*ones(10), 1, complex(ones(20), ones(20)), 2)
253+
-10.0 + 10.0im
254+
```
234255
"""
235256
function dotu end
236257

@@ -314,6 +335,15 @@ end
314335
nrm2(n, X, incx)
315336
316337
2-norm of a vector consisting of `n` elements of array `X` with stride `incx`.
338+
339+
# Example:
340+
```jldoctest
341+
julia> Base.BLAS.nrm2(4, ones(8), 2)
342+
2.0
343+
344+
julia> Base.BLAS.nrm2(1, ones(8), 2)
345+
1.0
346+
```
317347
"""
318348
function nrm2 end
319349

@@ -339,6 +369,15 @@ nrm2(x::Array) = nrm2(length(x), pointer(x), 1)
339369
asum(n, X, incx)
340370
341371
Sum of the absolute values of the first `n` elements of array `X` with stride `incx`.
372+
373+
# Example:
374+
```jldoctest
375+
julia> Base.BLAS.asum(5, im*ones(10), 2)
376+
5.0
377+
378+
julia> Base.BLAS.asum(2, im*ones(10), 5)
379+
2.0
380+
```
342381
"""
343382
function asum end
344383

@@ -363,7 +402,20 @@ asum(x::Array) = asum(length(x), pointer(x), 1)
363402
"""
364403
axpy!(a, X, Y)
365404
366-
Overwrite `Y` with `a*X + Y`. Returns `Y`.
405+
Overwrite `Y` with `a*X + Y`, where `a` is a scalar. Returns `Y`.
406+
407+
# Example:
408+
```jldoctest
409+
julia> x = [1; 2; 3];
410+
411+
julia> y = [4; 5; 6];
412+
413+
julia> Base.BLAS.axpy!(2, x, y)
414+
3-element Array{Int64,1}:
415+
6
416+
9
417+
12
418+
```
367419
"""
368420
function axpy! end
369421

@@ -473,14 +525,15 @@ end
473525
gemv!(tA, alpha, A, x, beta, y)
474526
475527
Update the vector `y` as `alpha*A*x + beta*y` or `alpha*A'x + beta*y` according to `tA`
476-
(transpose `A`). Returns the updated `y`.
528+
(transpose `A`). `alpha` and `beta` are scalars. Returns the updated `y`.
477529
"""
478530
gemv!
479531

480532
"""
481533
gemv(tA, alpha, A, x)
482534
483535
Returns `alpha*A*x` or `alpha*A'x` according to `tA` (transpose `A`).
536+
`alpha` is a scalar.
484537
"""
485538
gemv(tA, alpha, A, x)
486539

@@ -496,18 +549,18 @@ gemv(tA, A, x)
496549
"""
497550
gbmv!(trans, m, kl, ku, alpha, A, x, beta, y)
498551
499-
Update vector `y` as `alpha*A*x + beta*y` or `alpha*A'*x + beta*y` according to `trans` ('N'
500-
or 'T'). The matrix `A` is a general band matrix of dimension `m` by `size(A,2)` with `kl`
501-
sub-diagonals and `ku` super-diagonals. Returns the updated `y`.
552+
Update vector `y` as `alpha*A*x + beta*y` or `alpha*A'*x + beta*y` according to `trans` (`'N'` (meaning not transposed)
553+
or `'T'` (meaning transposed)). The matrix `A` is a general band matrix of dimension `m` by `size(A,2)` with `kl`
554+
sub-diagonals and `ku` super-diagonals. `alpha` and `beta` are scalars. Returns the updated `y`.
502555
"""
503556
function gbmv! end
504557

505558
"""
506559
gbmv(trans, m, kl, ku, alpha, A, x, beta, y)
507560
508-
Returns `alpha*A*x` or `alpha*A'*x` according to `trans` ('N' or 'T'). The matrix `A` is a
509-
general band matrix of dimension `m` by `size(A,2)` with `kl` sub-diagonals and `ku`
510-
super-diagonals.
561+
Returns `alpha*A*x` or `alpha*A'*x` according to `trans` (`'N'` (meaning not transposed) or `'T'` (meaning transposed)).
562+
The matrix `A` is a general band matrix of dimension `m` by `size(A,2)` with `kl` sub-diagonals and `ku`
563+
super-diagonals. `alpha` and `beta` are scalars.
511564
"""
512565
function gbmv end
513566

@@ -551,7 +604,7 @@ end
551604
symv!(ul, alpha, A, x, beta, y)
552605
553606
Update the vector `y` as `alpha*A*x + beta*y`. `A` is assumed to be symmetric. Only the `ul`
554-
triangle of `A` is used. Returns the updated `y`.
607+
triangle of `A` is used. `alpha` and `beta` are scalars. Returns the updated `y`.
555608
"""
556609
function symv! end
557610

@@ -600,14 +653,17 @@ end
600653
"""
601654
symv(ul, alpha, A, x)
602655
603-
Returns `alpha*A*x`. `A` is assumed to be symmetric. Only the `ul` triangle of `A` is used.
656+
Returns `alpha*A*x`. `A` is assumed to be symmetric.
657+
Only the `ul` (`'U'` for upper, `'L'` for lower) triangle of `A` is used.
658+
`alpha` is a scalar.
604659
"""
605660
symv(ul, alpha, A, x)
606661

607662
"""
608663
symv(ul, A, x)
609664
610-
Returns `A*x`. `A` is assumed to be symmetric. Only the `ul` triangle of `A` is used.
665+
Returns `A*x`. `A` is assumed to be symmetric.
666+
Only the `ul` (`'U'` for upper, `'L'` for lower) triangle of `A` is used.
611667
"""
612668
symv(ul, A, x)
613669

@@ -683,6 +739,7 @@ end
683739
684740
Returns `alpha*A*x` where `A` is a symmetric band matrix of order `size(A,2)` with `k`
685741
super-diagonals stored in the argument `A`.
742+
Only the `uplo` (`'U'` for upper, `'L'` for lower) triangle of `A` is used.
686743
"""
687744
sbmv(uplo, k, alpha, A, x)
688745

@@ -691,6 +748,7 @@ sbmv(uplo, k, alpha, A, x)
691748
692749
Returns `A*x` where `A` is a symmetric band matrix of order `size(A,2)` with `k`
693750
super-diagonals stored in the argument `A`.
751+
Only the `uplo` (`'U'` for upper, `'L'` for lower) triangle of `A` is used.
694752
"""
695753
sbmv(uplo, k, A, x)
696754

@@ -701,6 +759,7 @@ Update vector `y` as `alpha*A*x + beta*y` where `A` is a a symmetric band matrix
701759
`size(A,2)` with `k` super-diagonals stored in the argument `A`. The storage layout for `A`
702760
is described the reference BLAS module, level-2 BLAS at
703761
<http://www.netlib.org/lapack/explore-html/>.
762+
Only the `uplo` (`'U'` for upper, `'L'` for lower) triangle of `A` is used.
704763
705764
Returns the updated `y`.
706765
"""
@@ -743,23 +802,26 @@ end
743802
trmv(ul, tA, dA, A, b)
744803
745804
Returns `op(A)*b`, where `op` is determined by `tA`
746-
(`N` for identity, `T` for transpose `A`, and `C` for conjugate
747-
transpose `A`). Only the `ul` triangle (`U` for upper, `L`
748-
for lower) of `A` is used. `dA` indicates if `A` is
749-
unit-triangular (the diagonal is assumed to be all ones if `U`,
750-
or non-unit if `N`).
805+
(`'N'` for identity, `'T'` for transpose `A`, and `'C'` for conjugate
806+
transpose `A`). Only the `ul` triangle (`'U'` for upper, `'L'`
807+
for lower) of `A` is used.
808+
The diagonal is assumed to be all ones if `dA` is `'U'`, or the
809+
diagonal values are read from
810+
`A` if `dA` is `'N'`.
751811
"""
752812
function trmv end
753813

754814
"""
755815
trmv!(ul, tA, dA, A, b)
756816
757817
Returns `op(A)*b`, where `op` is determined by `tA`
758-
(`N` for identity, `T` for transpose `A`, and `C` for conjugate
759-
transpose `A`). Only the `ul` triangle (`U` for upper, `L`
760-
for lower) of `A` is used. `dA` indicates if `A` is
761-
unit-triangular (the diagonal is assumed to be all ones if `U`,
762-
or non-unit if `N`). The multiplication occurs in-place on `b`.
818+
(`'N'` for identity, `'T'` for transpose `A`, and `'C'` for conjugate
819+
transpose `A`). Only the `ul` triangle (`'U'` for upper, `'L'`
820+
for lower) of `A` is used.
821+
The diagonal is assumed to be all ones if `dA` is `'U'`, or the
822+
diagonal values are read from
823+
`A` if `dA` is `'N'`.
824+
The multiplication occurs in-place on `b`.
763825
"""
764826
function trmv! end
765827

@@ -798,8 +860,11 @@ end
798860
trsv!(ul, tA, dA, A, b)
799861
800862
Overwrite `b` with the solution to `A*x = b` or one of the other two variants determined by
801-
`tA` (transpose `A`) and `ul` (triangle of `A` used). `dA` indicates if `A` is
802-
unit-triangular (the diagonal is assumed to be all ones). Returns the updated `b`.
863+
`tA` (transpose `A` if `'T'`, `A` if `'N'`, conjugate-transpose if `'C'`)
864+
and `ul` (triangle of `A` used, `'U'` for upper, `'L`' for lower).
865+
The diagonal is assumed to be all ones if `dA` is `'U'`, or the diagonal values are read from
866+
`A` if `dA` is `'N'`.
867+
Returns the updated `b`.
803868
"""
804869
function trsv! end
805870

@@ -808,7 +873,8 @@ function trsv! end
808873
809874
Returns the solution to `A*x = b` or one of the other two variants determined by `tA`
810875
(transpose `A`) and `ul` (triangle of `A` is used.) `dA` indicates if `A` is unit-triangular
811-
(the diagonal is assumed to be all ones).
876+
(the diagonal is assumed to be all ones if `dA` is `'U'`, or the diagonal values are read from
877+
`A` if `dA` is `'N'`).
812878
"""
813879
function trsv end
814880

@@ -878,7 +944,7 @@ end
878944
syr!(uplo, alpha, x, A)
879945
880946
Rank-1 update of the symmetric matrix `A` with vector `x` as `alpha*x*x.' + A`. When `uplo`
881-
is 'U' the upper triangle of `A` is updated ('L' for lower triangle). Returns `A`.
947+
is `'U'` the upper triangle of `A` is updated (`'L'` for lower triangle). Returns `A`.
882948
"""
883949
function syr! end
884950

@@ -908,7 +974,7 @@ end
908974
her!(uplo, alpha, x, A)
909975
910976
Methods for complex arrays only. Rank-1 update of the Hermitian matrix `A` with vector `x`
911-
as `alpha*x*x' + A`. When `uplo` is 'U' the upper triangle of `A` is updated ('L' for lower
977+
as `alpha*x*x' + A`. When `uplo` is `'U'` the upper triangle of `A` is updated (`'L'` for lower
912978
triangle). Returns `A`.
913979
"""
914980
function her! end
@@ -1045,15 +1111,15 @@ end
10451111
symm(side, ul, alpha, A, B)
10461112
10471113
Returns `alpha*A*B` or `alpha*B*A` according to `side`. `A` is assumed to be symmetric. Only
1048-
the `ul` triangle of `A` is used.
1114+
the `ul` triangle (`'U'` for upper, `'L'` for lower) of `A` is used.
10491115
"""
10501116
symm(side, ul, alpha, A, B)
10511117

10521118
"""
10531119
symm(side, ul, A, B)
10541120
10551121
Returns `A*B` or `B*A` according to `side`. `A` is assumed to be symmetric. Only the `ul`
1056-
triangle of `A` is used.
1122+
triangle (`'U'` for upper, `'L'` for lower) of `A` is used.
10571123
"""
10581124
symm(side, ul, A, B)
10591125

@@ -1068,7 +1134,8 @@ symm(tA::Char, tB::Char, alpha, A, B)
10681134
symm!(side, ul, alpha, A, B, beta, C)
10691135
10701136
Update `C` as `alpha*A*B + beta*C` or `alpha*B*A + beta*C` according to `side`. `A` is
1071-
assumed to be symmetric. Only the `ul` triangle of `A` is used. Returns the updated `C`.
1137+
assumed to be symmetric. Only the `ul` (`'U'` for upper, `'L'` for lower) triangle of
1138+
`A` is used. Returns the updated `C`.
10721139
"""
10731140
symm!
10741141

@@ -1116,16 +1183,16 @@ end
11161183
syrk!(uplo, trans, alpha, A, beta, C)
11171184
11181185
Rank-k update of the symmetric matrix `C` as `alpha*A*A.' + beta*C` or `alpha*A.'*A +
1119-
beta*C` according to whether `trans` is 'N' or 'T'. When `uplo` is 'U' the upper triangle of
1120-
`C` is updated ('L' for lower triangle). Returns `C`.
1186+
beta*C` according to whether `trans` is `'N'` or `'T'`. When `uplo` is `'U'` the upper triangle of
1187+
`C` is updated (`'L'` for lower triangle). Returns `C`.
11211188
"""
11221189
function syrk! end
11231190

11241191
"""
11251192
syrk(uplo, trans, alpha, A)
11261193
1127-
Returns either the upper triangle or the lower triangle, according to `uplo` ('U' or 'L'),
1128-
of `alpha*A*A.'` or `alpha*A.'*A`, according to `trans` ('N' or 'T').
1194+
Returns either the upper triangle or the lower triangle, according to `uplo` (`'U'` or `'L'`),
1195+
of `alpha*A*A.'` or `alpha*A.'*A`, according to `trans` (`'N'` or `'T'`).
11291196
"""
11301197
function syrk end
11311198

@@ -1170,8 +1237,8 @@ syrk(uplo::Char, trans::Char, A::StridedVecOrMat) = syrk(uplo, trans, one(eltype
11701237
herk!(uplo, trans, alpha, A, beta, C)
11711238
11721239
Methods for complex arrays only. Rank-k update of the Hermitian matrix `C` as `alpha*A*A' +
1173-
beta*C` or `alpha*A'*A + beta*C` according to whether `trans` is 'N' or 'T'. When `uplo` is
1174-
'U' the upper triangle of `C` is updated ('L' for lower triangle). Returns `C`.
1240+
beta*C` or `alpha*A'*A + beta*C` according to whether `trans` is `'N'` or `'T'`. When `uplo` is
1241+
`'U'` the upper triangle of `C` is updated (`'L'` for lower triangle). Returns `C`.
11751242
"""
11761243
function herk! end
11771244

@@ -1301,38 +1368,48 @@ end
13011368
"""
13021369
trmm!(side, ul, tA, dA, alpha, A, B)
13031370
1304-
Update `B` as `alpha*A*B` or one of the other three variants determined by `side` (`A` on
1305-
left or right) and `tA` (transpose `A`). Only the `ul` triangle of `A` is used. `dA`
1306-
indicates if `A` is unit-triangular (the diagonal is assumed to be all ones). Returns the
1307-
updated `B`.
1371+
Update `B` as `alpha*A*B` or one of the other three variants determined by `side` (`'L'` for `A` on
1372+
left, `'R'` for `A` on right) and `tA` (transpose `A`). Only the `ul` (`'U'` for upper, `'L'` for lower)
1373+
triangle of `A` is used.
1374+
The diagonal is assumed to be all ones if `dA` is `'U'`, or the diagonal values are read from
1375+
`A` if `dA` is `'N'`.
1376+
Returns the updated `B`.
13081377
"""
13091378
function trmm! end
13101379

13111380
"""
13121381
trmm(side, ul, tA, dA, alpha, A, B)
13131382
1314-
Returns `alpha*A*B` or one of the other three variants determined by `side` (`A` on left or
1315-
right) and `tA` (transpose `A`). Only the `ul` triangle of `A` is used. `dA` indicates if
1316-
`A` is unit-triangular (the diagonal is assumed to be all ones).
1383+
Returns `alpha*A*B` or one of the other three variants determined by `side` (`'L'` for `A` on left,
1384+
`'R'` for `A` on right) and `tA` (transpose `A`).
1385+
Only the `ul` (`'U'` for upper, `'L'` for lower) triangle of `A` is used.
1386+
The diagonal is assumed to be all ones if `dA` is `'U'`, or the diagonal values are read from
1387+
`A` if `dA` is `'N'`.
13171388
"""
13181389
function trmm end
13191390

13201391
"""
13211392
trsm!(side, ul, tA, dA, alpha, A, B)
13221393
13231394
Overwrite `B` with the solution to `A*X = alpha*B` or one of the other three variants
1324-
determined by `side` (`A` on left or right of `X`) and `tA` (transpose `A`). Only the `ul`
1325-
triangle of `A` is used. `dA` indicates if `A` is unit-triangular (the diagonal is assumed
1326-
to be all ones). Returns the updated `B`.
1395+
determined by `side` (`'L'` for `A` on left of `X`, `'R'` for `A` on right of `X`)
1396+
and `tA` (transpose `A`).
1397+
Only the `ul` (`'U'` for upper, `'L'` for lower) triangle of `A` is used.
1398+
The diagonal is assumed to be all ones if `dA` is `'U'`, or the diagonal values are read from
1399+
`A` if `dA` is `'N'`.
1400+
Returns the updated `B`.
13271401
"""
13281402
function trsm! end
13291403

13301404
"""
13311405
trsm(side, ul, tA, dA, alpha, A, B)
13321406
13331407
Returns the solution to `A*X = alpha*B` or one of the other three variants determined by
1334-
`side` (`A` on left or right of `X`) and `tA` (transpose `A`). Only the `ul` triangle of `A`
1335-
is used. `dA` indicates if `A` is unit-triangular (the diagonal is assumed to be all ones).
1408+
determined by `side` (`'L'` for `A` on left of `X`, `'R'` for `A` on right of `X`)
1409+
and `tA` (transpose `A`).
1410+
Only the `ul` (`'U'` for upper, `'L'` for lower) triangle of `A` is used.
1411+
The diagonal is assumed to be all ones if `dA` is `'U'`, or the diagonal values are read from
1412+
`A` if `dA` is `'N'`.
13361413
"""
13371414
function trsm end
13381415

0 commit comments

Comments
 (0)