Skip to content

Commit f67d64b

Browse files
committed
rewrite all ones(...) calls in base, stdlib, test and documentation
1 parent a3e24cb commit f67d64b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+529
-525
lines changed

base/abstractarray.jl

+10-10
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ lengths of dimensions you asked for.
3131
3232
# Examples
3333
```jldoctest
34-
julia> A = ones(2,3,4);
34+
julia> A = fill(1, (2,3,4));
3535
3636
julia> size(A, 2)
3737
3
3838
39-
julia> size(A,3,2)
39+
julia> size(A, 3, 2)
4040
(4, 3)
4141
```
4242
"""
@@ -51,9 +51,9 @@ Return the valid range of indices for array `A` along dimension `d`.
5151
5252
# Examples
5353
```jldoctest
54-
julia> A = ones(5,6,7);
54+
julia> A = fill(1, (5,6,7));
5555
56-
julia> axes(A,2)
56+
julia> axes(A, 2)
5757
Base.OneTo(6)
5858
```
5959
"""
@@ -69,7 +69,7 @@ Return the tuple of valid indices for array `A`.
6969
7070
# Examples
7171
```jldoctest
72-
julia> A = ones(5,6,7);
72+
julia> A = fill(1, (5,6,7));
7373
7474
julia> axes(A)
7575
(Base.OneTo(5), Base.OneTo(6), Base.OneTo(7))
@@ -104,7 +104,7 @@ exploit linear indexing.
104104
105105
# Examples
106106
```jldoctest
107-
julia> A = ones(5,6,7);
107+
julia> A = fill(1, (5,6,7));
108108
109109
julia> b = linearindices(A);
110110
@@ -131,7 +131,7 @@ Return the number of dimensions of `A`.
131131
132132
# Examples
133133
```jldoctest
134-
julia> A = ones(3,4,5);
134+
julia> A = fill(1, (3,4,5));
135135
136136
julia> ndims(A)
137137
3
@@ -225,7 +225,7 @@ Return the distance in memory (in number of elements) between adjacent elements
225225
226226
# Examples
227227
```jldoctest
228-
julia> A = ones(3,4,5);
228+
julia> A = fill(1, (3,4,5));
229229
230230
julia> stride(A,2)
231231
3
@@ -252,7 +252,7 @@ Return a tuple of the memory strides in each dimension.
252252
253253
# Examples
254254
```jldoctest
255-
julia> A = ones(3,4,5);
255+
julia> A = fill(1, (3,4,5));
256256
257257
julia> strides(A)
258258
(1, 3, 12)
@@ -2043,4 +2043,4 @@ function hash(a::AbstractArray{T}, h::UInt) where T
20432043
end
20442044
!isequal(x2, x1) && (h = hash(x2, h))
20452045
return h
2046-
end
2046+
end

base/array.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ types.
7777
7878
# Examples
7979
```jldoctest
80-
julia> eltype(ones(Float32,2,2))
80+
julia> eltype(fill(1f0, (2,2)))
8181
Float32
8282
83-
julia> eltype(ones(Int8,2,2))
84-
Int8
83+
julia> eltype(fill(0x1, (2,2)))
84+
UInt8
8585
```
8686
"""
8787
eltype(::Type) = Any
@@ -343,7 +343,7 @@ fill(v, dims::Integer...) = fill!(Array{typeof(v)}(uninitialized, dims...), v)
343343
zeros([T=Float64,] dims...)
344344
345345
Create an `Array`, with element type `T`, of all zeros with size specified by `dims`.
346-
See also [`ones`](@ref), [`similar`](@ref).
346+
See also [`fill`](@ref), [`ones`](@ref).
347347
348348
# Examples
349349
```jldoctest
@@ -363,7 +363,7 @@ function zeros end
363363
ones([T=Float64,] dims...)
364364
365365
Create an `Array`, with element type `T`, of all ones with size specified by `dims`.
366-
See also [`zeros`](@ref), [`similar`](@ref).
366+
See also: [`fill`](@ref), [`zeros`](@ref).
367367
368368
# Examples
369369
```jldoctest

base/bitarray.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ function vcat(A::BitMatrix...)
18121812
nrowsA = [size(a, 1) for a in A]
18131813
Ac = [a.chunks for a in A]
18141814
pos_d = 1
1815-
pos_s = ones(Int, nargs)
1815+
pos_s = fill(1, nargs)
18161816
for j = 1:ncols, k = 1:nargs
18171817
copy_chunks!(Bc, pos_d, Ac[k], pos_s[k], nrowsA[k])
18181818
pos_s[k] += nrowsA[k]

base/combinatorics.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ function nextprod(a::Vector{Int}, x)
239239
throw(ArgumentError("unsafe for x > typemax(Int), got $x"))
240240
end
241241
k = length(a)
242-
v = ones(Int, k) # current value of each counter
242+
v = fill(1, k) # current value of each counter
243243
mx = [nextpow(ai,x) for ai in a] # maximum value of each counter
244244
v[1] = mx[1] # start at first case that is >= x
245245
p::widen(Int) = mx[1] # initial value of product in this case

base/docs/basedocs.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -926,14 +926,14 @@ An indexing operation into an array, `a`, tried to access an out-of-bounds eleme
926926
927927
# Examples
928928
```jldoctest
929-
julia> A = ones(7);
929+
julia> A = fill(1.0, 7);
930930
931931
julia> A[8]
932932
ERROR: BoundsError: attempt to access 7-element Array{Float64,1} at index [8]
933933
Stacktrace:
934934
[1] getindex(::Array{Float64,1}, ::Int64) at ./array.jl:758
935935
936-
julia> B = ones(2, 3);
936+
julia> B = fill(1.0, (2,3));
937937
938938
julia> B[2, 4]
939939
ERROR: BoundsError: attempt to access 2×3 Array{Float64,2} at index [2, 4]

base/indices.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ Check two array shapes for compatibility, allowing trailing singleton dimensions
3838
whichever shape has more dimensions.
3939
4040
```jldoctest
41-
julia> a = ones(3,4,1,1,1);
41+
julia> a = fill(1, (3,4,1,1,1));
4242
43-
julia> b = ones(3,4);
43+
julia> b = fill(1, (3,4));
4444
4545
julia> promote_shape(a,b)
4646
(Base.OneTo(3), Base.OneTo(4), Base.OneTo(1), Base.OneTo(1), Base.OneTo(1))

base/linalg/blas.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ Dot product of two vectors consisting of `n` elements of array `X` with stride `
228228
229229
# Examples
230230
```jldoctest
231-
julia> dot(10, ones(10), 1, ones(20), 2)
231+
julia> dot(10, fill(1.0, 10), 1, fill(1.0, 20), 2)
232232
10.0
233233
```
234234
"""
@@ -243,7 +243,7 @@ conjugating the first vector.
243243
244244
# Examples
245245
```jldoctest
246-
julia> Base.BLAS.dotc(10, im*ones(10), 1, complex.(ones(20), ones(20)), 2)
246+
julia> Base.BLAS.dotc(10, fill(1.0im, 10), 1, fill(1.0+im, 20), 2)
247247
10.0 - 10.0im
248248
```
249249
"""
@@ -257,7 +257,7 @@ with stride `incx` and `n` elements of array `Y` with stride `incy`.
257257
258258
# Examples
259259
```jldoctest
260-
julia> Base.BLAS.dotu(10, im*ones(10), 1, complex.(ones(20), ones(20)), 2)
260+
julia> Base.BLAS.dotu(10, fill(1.0im, 10), 1, fill(1.0+im, 20), 2)
261261
-10.0 + 10.0im
262262
```
263263
"""
@@ -349,10 +349,10 @@ stride1(x::Array) = 1
349349
350350
# Examples
351351
```jldoctest
352-
julia> Base.BLAS.nrm2(4, ones(8), 2)
352+
julia> Base.BLAS.nrm2(4, fill(1.0, 8), 2)
353353
2.0
354354
355-
julia> Base.BLAS.nrm2(1, ones(8), 2)
355+
julia> Base.BLAS.nrm2(1, fill(1.0, 8), 2)
356356
1.0
357357
```
358358
"""
@@ -382,10 +382,10 @@ Sum of the absolute values of the first `n` elements of array `X` with stride `i
382382
383383
# Examples
384384
```jldoctest
385-
julia> Base.BLAS.asum(5, im*ones(10), 2)
385+
julia> Base.BLAS.asum(5, fill(1.0im, 10), 2)
386386
5.0
387387
388-
julia> Base.BLAS.asum(2, im*ones(10), 5)
388+
julia> Base.BLAS.asum(2, fill(1.0im, 10), 5)
389389
2.0
390390
```
391391
"""

base/linalg/dense.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ compute the cosine. Otherwise, the cosine is determined by calling [`exp`](@ref)
753753
754754
# Examples
755755
```jldoctest
756-
julia> cos(ones(2, 2))
756+
julia> cos(fill(1.0, (2,2)))
757757
2×2 Array{Float64,2}:
758758
0.291927 -0.708073
759759
-0.708073 0.291927
@@ -786,7 +786,7 @@ compute the sine. Otherwise, the sine is determined by calling [`exp`](@ref).
786786
787787
# Examples
788788
```jldoctest
789-
julia> sin(ones(2, 2))
789+
julia> sin(fill(1.0, (2,2)))
790790
2×2 Array{Float64,2}:
791791
0.454649 0.454649
792792
0.454649 0.454649
@@ -820,7 +820,7 @@ Compute the matrix sine and cosine of a square matrix `A`.
820820
821821
# Examples
822822
```jldoctest
823-
julia> S, C = sincos(ones(2, 2));
823+
julia> S, C = sincos(fill(1.0, (2,2)));
824824
825825
julia> S
826826
2×2 Array{Float64,2}:
@@ -872,7 +872,7 @@ compute the tangent. Otherwise, the tangent is determined by calling [`exp`](@re
872872
873873
# Examples
874874
```jldoctest
875-
julia> tan(ones(2, 2))
875+
julia> tan(fill(1.0, (2,2)))
876876
2×2 Array{Float64,2}:
877877
-1.09252 -1.09252
878878
-1.09252 -1.09252
@@ -1144,7 +1144,7 @@ will return a Cholesky factorization.
11441144
11451145
# Examples
11461146
```jldoctest
1147-
julia> A = Array(Bidiagonal(ones(5, 5), :U))
1147+
julia> A = Array(Bidiagonal(fill(1.0, (5, 5)), :U))
11481148
5×5 Array{Float64,2}:
11491149
1.0 1.0 0.0 0.0 0.0
11501150
0.0 1.0 1.0 0.0 0.0

base/linalg/generic.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Upper triangle of a matrix.
121121
122122
# Examples
123123
```jldoctest
124-
julia> a = ones(4,4)
124+
julia> a = fill(1.0, (4,4))
125125
4×4 Array{Float64,2}:
126126
1.0 1.0 1.0 1.0
127127
1.0 1.0 1.0 1.0
@@ -145,7 +145,7 @@ Lower triangle of a matrix.
145145
146146
# Examples
147147
```jldoctest
148-
julia> a = ones(4,4)
148+
julia> a = fill(1.0, (4,4))
149149
4×4 Array{Float64,2}:
150150
1.0 1.0 1.0 1.0
151151
1.0 1.0 1.0 1.0
@@ -169,7 +169,7 @@ Returns the upper triangle of `M` starting from the `k`th superdiagonal.
169169
170170
# Examples
171171
```jldoctest
172-
julia> a = ones(4,4)
172+
julia> a = fill(1.0, (4,4))
173173
4×4 Array{Float64,2}:
174174
1.0 1.0 1.0 1.0
175175
1.0 1.0 1.0 1.0
@@ -200,7 +200,7 @@ Returns the lower triangle of `M` starting from the `k`th superdiagonal.
200200
201201
# Examples
202202
```jldoctest
203-
julia> a = ones(4,4)
203+
julia> a = fill(1.0, (4,4))
204204
4×4 Array{Float64,2}:
205205
1.0 1.0 1.0 1.0
206206
1.0 1.0 1.0 1.0
@@ -1209,9 +1209,9 @@ running in parallel, only 1 BLAS thread is used. The argument `n` still refers t
12091209
of the problem that is solved on each processor.
12101210
"""
12111211
function peakflops(n::Integer=2000; parallel::Bool=false)
1212-
a = ones(Float64,100,100)
1212+
a = fill(1.,100,100)
12131213
t = @elapsed a2 = a*a
1214-
a = ones(Float64,n,n)
1214+
a = fill(1.,n,n)
12151215
t = @elapsed a2 = a*a
12161216
@assert a2[1,1] == n
12171217
parallel ? sum(pmap(peakflops, [ n for i in 1:nworkers()])) : (2*Float64(n)^3/t)

base/linalg/lapack.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3731,7 +3731,7 @@ for (stev, stebz, stegr, stein, elty) in
37313731
isplit = similar(dv, BlasInt,n)
37323732
w = similar(dv, $elty,n)
37333733
if length(iblock_in) < m #Not enough block specifications
3734-
iblock[1:m] = ones(BlasInt, m)
3734+
iblock[1:m] = fill(BlasInt(1), m)
37353735
w[1:m] = sort(w_in)
37363736
else
37373737
iblock[1:m] = iblock_in

base/linalg/linalg.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ For multiple arguments, return a vector.
173173
174174
# Examples
175175
```jldoctest
176-
julia> A = ones(4,4); B = zeros(5,5);
176+
julia> A = fill(1, (4,4)); B = fill(1, (5,5));
177177
178178
julia> LinAlg.checksquare(A, B)
179179
2-element Array{Int64,1}:

base/linalg/lu.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ factorize(A::Tridiagonal) = lufact(A)
466466
function getproperty(F::LU{T,Tridiagonal{T,V}}, d::Symbol) where {T,V}
467467
m, n = size(F)
468468
if d == :L
469-
L = Array(Bidiagonal(ones(T, n), getfield(getfield(F, :factors), :dl), d))
469+
L = Array(Bidiagonal(fill(one(T), n), getfield(getfield(F, :factors), :dl), d))
470470
for i = 2:n
471471
tmp = L[getfield(F, :ipiv)[i], 1:i - 1]
472472
L[getfield(F, :ipiv)[i], 1:i - 1] = L[i, 1:i - 1]

base/linalg/qr.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,8 @@ function ldiv!(A::QRPivoted{T}, B::StridedMatrix{T}, rcond::Real) where T<:BlasF
754754
return B, 0
755755
end
756756
rnk = 1
757-
xmin = ones(T, 1)
758-
xmax = ones(T, 1)
757+
xmin = T[1]
758+
xmax = T[1]
759759
tmin = tmax = ar
760760
while rnk < nr
761761
tmin, smin, cmin = LAPACK.laic1!(2, xmin, tmin, view(A.factors, 1:rnk, rnk + 1), A.factors[rnk + 1, rnk + 1])

base/linalg/triangular.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,9 @@ adjoint!(A::UpperTriangular) = LowerTriangular(copytri!(A.data, 'U' , true))
347347
adjoint!(A::UnitUpperTriangular) = UnitLowerTriangular(copytri!(A.data, 'U' , true))
348348

349349
diag(A::LowerTriangular) = diag(A.data)
350-
diag(A::UnitLowerTriangular) = ones(eltype(A), size(A,1))
350+
diag(A::UnitLowerTriangular) = fill(one(eltype(A)), size(A,1))
351351
diag(A::UpperTriangular) = diag(A.data)
352-
diag(A::UnitUpperTriangular) = ones(eltype(A), size(A,1))
352+
diag(A::UnitUpperTriangular) = fill(one(eltype(A)), size(A,1))
353353

354354
# Unary operations
355355
-(A::LowerTriangular) = LowerTriangular(-A.data)

base/linalg/uniformscaling.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ An object of type [`UniformScaling`](@ref), representing an identity matrix of a
3838
3939
# Examples
4040
```jldoctest
41-
julia> ones(5, 6) * I == ones(5, 6)
41+
julia> fill(1, (5,6)) * I == fill(1, (5,6))
4242
true
4343
4444
julia> [1 2im 3; 1im 2 3] * I

base/multidimensional.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ module IteratorsMD
189189
CartesianIndex(1, 2, 2)
190190
CartesianIndex(2, 2, 2)
191191
192-
julia> CartesianIndices(ones(2,3))
192+
julia> CartesianIndices(fill(1, (2,3)))
193193
2×3 CartesianIndices{2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}:
194194
CartesianIndex(1, 1) CartesianIndex(1, 2) CartesianIndex(1, 3)
195195
CartesianIndex(2, 1) CartesianIndex(2, 2) CartesianIndex(2, 3)

base/sparse/linalg.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ end
406406

407407
function sparse_diff1(S::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti}
408408
m,n = size(S)
409-
m > 1 || return SparseMatrixCSC(0, n, ones(Ti,n+1), Ti[], Tv[])
409+
m > 1 || return SparseMatrixCSC(0, n, fill(one(Ti),n+1), Ti[], Tv[])
410410
colptr = Vector{Ti}(uninitialized, n+1)
411411
numnz = 2 * nnz(S) # upper bound; will shrink later
412412
rowval = Vector{Ti}(uninitialized, numnz)

0 commit comments

Comments
 (0)