Skip to content

Commit 6df3ec0

Browse files
committed
Added examples for ones, eye. Fixed up BitArray docs.
Removed calls to `rand` in the doctests.
1 parent e4a377c commit 6df3ec0

File tree

5 files changed

+262
-241
lines changed

5 files changed

+262
-241
lines changed

base/array.jl

+63
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,42 @@ for (fname, felt) in ((:zeros,:zero), (:ones,:one))
171171
($fname){T}(A::AbstractArray{T}) = fill!(similar(A), ($felt)(T))
172172
end
173173
end
174+
"""
175+
ones([T::Type=Float64,] dims)
176+
177+
Create an array of all ones of specified type. The type defaults to `Float64` if not specified.
178+
"""
179+
function ones(dims::Dims) end
180+
181+
"""
182+
ones(A)
183+
184+
Create an array of all ones with the same element type and shape as `A`.
185+
186+
```jldoctest
187+
julia> A = [1 2 3; 4 5 6; 7 8 9]
188+
3×3 Array{Int64,2}:
189+
1 2 3
190+
4 5 6
191+
7 8 9
192+
193+
julia> ones(A)
194+
3×3 Array{Int64,2}:
195+
1 1 1
196+
1 1 1
197+
1 1 1
198+
```
199+
200+
Note the difference from [`eye`](:func:`eye`).
201+
"""
202+
function ones(A) end
203+
204+
"""
205+
eye([T::Type=Float64,] m::Integer, n::Integer)
174206
207+
`m`-by-`n` identity matrix.
208+
The default element type is `Float64`.
209+
"""
175210
function eye(T::Type, m::Integer, n::Integer)
176211
a = zeros(T,m,n)
177212
for i = 1:min(m,n)
@@ -181,7 +216,35 @@ function eye(T::Type, m::Integer, n::Integer)
181216
end
182217
eye(m::Integer, n::Integer) = eye(Float64, m, n)
183218
eye(T::Type, n::Integer) = eye(T, n, n)
219+
"""
220+
eye([T::Type=Float64,] n::Integer)
221+
222+
`n`-by-`n` identity matrix.
223+
The default element type is `Float64`.
224+
"""
184225
eye(n::Integer) = eye(Float64, n)
226+
227+
"""
228+
eye(A)
229+
230+
Constructs an identity matrix of the same dimensions and type as `A`.
231+
232+
```jldoctest
233+
julia> A = [1 2 3; 4 5 6; 7 8 9]
234+
3×3 Array{Int64,2}:
235+
1 2 3
236+
4 5 6
237+
7 8 9
238+
239+
julia> eye(A)
240+
3×3 Array{Int64,2}:
241+
1 0 0
242+
0 1 0
243+
0 0 1
244+
```
245+
246+
Note the difference from [`ones`](:func:`ones`).
247+
"""
185248
eye{T}(x::AbstractMatrix{T}) = eye(T, size(x, 1), size(x, 2))
186249

187250
function one{T}(x::AbstractMatrix{T})

base/bitarray.jl

+63-72
Original file line numberDiff line numberDiff line change
@@ -1438,35 +1438,8 @@ end
14381438
"""
14391439
rol!(dest::BitVector, src::BitVector, i::Integer) -> BitVector
14401440
1441-
Performs a left rotation operation on `src` and put the result into `dest`.
1442-
1443-
```jldoctest
1444-
julia> a = bitrand(5)
1445-
5-element BitArray{1}:
1446-
false
1447-
false
1448-
true
1449-
true
1450-
true
1451-
1452-
julia> b = falses(5);
1453-
1454-
julia> rol!(b,a,2)
1455-
5-element BitArray{1}:
1456-
true
1457-
true
1458-
true
1459-
false
1460-
false
1461-
1462-
julia> rol!(b,a,3)
1463-
5-element BitArray{1}:
1464-
true
1465-
true
1466-
false
1467-
false
1468-
true
1469-
```
1441+
Performs a left rotation operation on `src` and puts the result into `dest`.
1442+
`i` controls how far to rotate each bit.
14701443
"""
14711444
function rol!(dest::BitVector, src::BitVector, i::Integer)
14721445
length(dest) == length(src) || throw(ArgumentError("destination and source should be of same size"))
@@ -1483,56 +1456,46 @@ end
14831456
"""
14841457
rol!(B::BitVector, i::Integer) -> BitVector
14851458
1486-
Performs a left rotation operation on `B`.
1459+
Performs a left rotation operation in-place on `B`.
1460+
`i` controls how far to rotate each bit.
1461+
"""
1462+
function rol!(B::BitVector, i::Integer)
1463+
return rol!(B, B, i)
1464+
end
1465+
1466+
"""
1467+
rol(B::BitVector, i::Integer) -> BitVector
1468+
1469+
Performs a left rotation operation, returning a new `BitVector`.
1470+
`i` controls how far to rotate each bit.
1471+
See also [`rol!`](:func:`rol!`).
14871472
14881473
```jldoctest
1489-
julia> a = bitrand(5)
1474+
julia> A = BitArray([true, true, false, false, true])
14901475
5-element BitArray{1}:
14911476
true
1477+
true
14921478
false
14931479
false
14941480
true
1495-
true
14961481
1497-
julia> rol!(a,4)
1482+
julia> rol(A,1)
14981483
5-element BitArray{1}:
14991484
true
1500-
true
15011485
false
15021486
false
15031487
true
1504-
"""
1505-
function rol!(B::BitVector, i::Integer)
1506-
return rol!(B, B, i)
1507-
end
1508-
1509-
"""
1510-
rol(B::BitVector, i::Integer) -> BitVector
1511-
1512-
Performs a left rotation operation without modifying `B`.
1513-
See also [`rol!`](:func:`rol!`).
1514-
"""
1515-
function rol(B::BitVector, i::Integer)
1516-
return rol!(similar(B), B, i)
1517-
end
1518-
1519-
"""
1520-
ror!(dest::BitVector, src::BitVector, i::Integer) -> BitVector
1521-
1522-
Performs a right rotation operation on `src` and put the result into `dest`.
1488+
true
15231489
1524-
```jldoctest
1525-
julia> a = bitrand(5)
1490+
julia> rol(A,2)
15261491
5-element BitArray{1}:
15271492
false
15281493
false
15291494
true
15301495
true
15311496
true
15321497
1533-
julia> b = falses(5);
1534-
1535-
julia> ror!(b,a,2)
1498+
julia> rol(A,5)
15361499
5-element BitArray{1}:
15371500
true
15381501
true
@@ -1541,6 +1504,16 @@ julia> ror!(b,a,2)
15411504
true
15421505
```
15431506
"""
1507+
function rol(B::BitVector, i::Integer)
1508+
return rol!(similar(B), B, i)
1509+
end
1510+
1511+
"""
1512+
ror!(dest::BitVector, src::BitVector, i::Integer) -> BitVector
1513+
1514+
Performs a right rotation operation on `src` and puts the result into `dest`.
1515+
`i` controls how far to rotate each bit.
1516+
"""
15441517
function ror!(dest::BitVector, src::BitVector, i::Integer)
15451518
length(dest) == length(src) || throw(ArgumentError("destination and source should be of same size"))
15461519
n = length(dest)
@@ -1556,36 +1529,54 @@ end
15561529
"""
15571530
ror!(B::BitVector, i::Integer) -> BitVector
15581531
1559-
Performs a right rotation operation on `B`.
1532+
Performs a right rotation operation in-place on `B`.
1533+
`i` controls how far to rotate each bit.
1534+
"""
1535+
function ror!(B::BitVector, i::Integer)
1536+
return ror!(B, B, i)
1537+
end
1538+
1539+
"""
1540+
ror(B::BitVector, i::Integer) -> BitVector
1541+
1542+
Performs a right rotation operation on `B`, returning a new `BitVector`.
1543+
`i` controls how far to rotate each bit.
1544+
See also [`ror!`](:func:`ror!`).
15601545
15611546
```jldoctest
1562-
julia> a = bitrand(5)
1547+
julia> A = BitArray([true, true, false, false, true])
15631548
5-element BitArray{1}:
1564-
false
15651549
true
1550+
true
1551+
false
15661552
false
15671553
true
1554+
1555+
julia> ror(A,1)
1556+
5-element BitArray{1}:
1557+
true
1558+
true
1559+
true
1560+
false
15681561
false
15691562
1570-
julia> ror!(a,3)
1563+
julia> ror(A,2)
15711564
5-element BitArray{1}:
15721565
false
15731566
true
1567+
true
1568+
true
1569+
false
1570+
1571+
julia> ror(A,5)
1572+
5-element BitArray{1}:
1573+
true
1574+
true
15741575
false
15751576
false
15761577
true
15771578
```
15781579
"""
1579-
function ror!(B::BitVector, i::Integer)
1580-
return ror!(B, B, i)
1581-
end
1582-
1583-
"""
1584-
ror(B::BitVector, i::Integer) -> BitVector
1585-
1586-
Performs a right rotation operation without modifying `B`.
1587-
See also [`ror!`](:func:`ror!`).
1588-
"""
15891580
function ror(B::BitVector, i::Integer)
15901581
return ror!(similar(B), B, i)
15911582
end

base/docs/helpdb/Base.jl

-35
Original file line numberDiff line numberDiff line change
@@ -1225,20 +1225,6 @@ of the problem that is solved on each processor.
12251225
"""
12261226
peakflops
12271227

1228-
"""
1229-
ones(type, dims)
1230-
1231-
Create an array of all ones of specified type. The type defaults to `Float64` if not specified.
1232-
"""
1233-
ones(t,dims)
1234-
1235-
"""
1236-
ones(A)
1237-
1238-
Create an array of all ones with the same element type and shape as `A`.
1239-
"""
1240-
ones(A)
1241-
12421228
"""
12431229
ind2chr(string, i)
12441230
@@ -4068,27 +4054,6 @@ Euler integral of the first kind ``\\operatorname{B}(x,y) = \\Gamma(x)\\Gamma(y)
40684054
"""
40694055
beta
40704056

4071-
"""
4072-
eye(n)
4073-
4074-
`n`-by-`n` identity matrix.
4075-
"""
4076-
eye(n::Int)
4077-
4078-
"""
4079-
eye(m, n)
4080-
4081-
`m`-by-`n` identity matrix.
4082-
"""
4083-
eye(m, n)
4084-
4085-
"""
4086-
eye(A)
4087-
4088-
Constructs an identity matrix of the same dimensions and type as `A`.
4089-
"""
4090-
eye(A)
4091-
40924057
"""
40934058
diagind(M[, k])
40944059

0 commit comments

Comments
 (0)