Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite all calls to ones(...) #25087

Merged
merged 1 commit into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ lengths of dimensions you asked for.

# Examples
```jldoctest
julia> A = ones(2,3,4);
julia> A = fill(1, (2,3,4));

julia> size(A, 2)
3

julia> size(A,3,2)
julia> size(A, 3, 2)
(4, 3)
```
"""
Expand All @@ -51,9 +51,9 @@ Return the valid range of indices for array `A` along dimension `d`.

# Examples
```jldoctest
julia> A = ones(5,6,7);
julia> A = fill(1, (5,6,7));

julia> axes(A,2)
julia> axes(A, 2)
Base.OneTo(6)
```
"""
Expand All @@ -69,7 +69,7 @@ Return the tuple of valid indices for array `A`.

# Examples
```jldoctest
julia> A = ones(5,6,7);
julia> A = fill(1, (5,6,7));

julia> axes(A)
(Base.OneTo(5), Base.OneTo(6), Base.OneTo(7))
Expand Down Expand Up @@ -104,7 +104,7 @@ exploit linear indexing.

# Examples
```jldoctest
julia> A = ones(5,6,7);
julia> A = fill(1, (5,6,7));

julia> b = linearindices(A);

Expand All @@ -131,7 +131,7 @@ Return the number of dimensions of `A`.

# Examples
```jldoctest
julia> A = ones(3,4,5);
julia> A = fill(1, (3,4,5));

julia> ndims(A)
3
Expand Down Expand Up @@ -225,7 +225,7 @@ Return the distance in memory (in number of elements) between adjacent elements

# Examples
```jldoctest
julia> A = ones(3,4,5);
julia> A = fill(1, (3,4,5));

julia> stride(A,2)
3
Expand All @@ -252,7 +252,7 @@ Return a tuple of the memory strides in each dimension.

# Examples
```jldoctest
julia> A = ones(3,4,5);
julia> A = fill(1, (3,4,5));

julia> strides(A)
(1, 3, 12)
Expand Down
10 changes: 5 additions & 5 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ types.

# Examples
```jldoctest
julia> eltype(ones(Float32,2,2))
julia> eltype(fill(1f0, (2,2)))
Float32

julia> eltype(ones(Int8,2,2))
Int8
julia> eltype(fill(0x1, (2,2)))
UInt8
```
"""
eltype(::Type) = Any
Expand Down Expand Up @@ -343,7 +343,7 @@ fill(v, dims::Integer...) = fill!(Array{typeof(v)}(uninitialized, dims...), v)
zeros([T=Float64,] dims...)

Create an `Array`, with element type `T`, of all zeros with size specified by `dims`.
See also [`ones`](@ref), [`similar`](@ref).
See also [`fill`](@ref), [`ones`](@ref).
Copy link
Member

@Sacha0 Sacha0 Jan 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ref fill and ones (rather than fill and similar)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reference to similar here should have been removed as part of #24656/#24863. I assume the reason we referenced it here was because previously we had both zeros(A) and similar(A) doing similar things for A::AbstractArray.


# Examples
```jldoctest
Expand All @@ -363,7 +363,7 @@ function zeros end
ones([T=Float64,] dims...)

Create an `Array`, with element type `T`, of all ones with size specified by `dims`.
See also [`zeros`](@ref), [`similar`](@ref).
See also: [`fill`](@ref), [`zeros`](@ref).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here, why ref fill and zeros (rather than fill and similar)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.


# Examples
```jldoctest
Expand Down
2 changes: 1 addition & 1 deletion base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ function vcat(A::BitMatrix...)
nrowsA = [size(a, 1) for a in A]
Ac = [a.chunks for a in A]
pos_d = 1
pos_s = ones(Int, nargs)
pos_s = fill(1, nargs)
for j = 1:ncols, k = 1:nargs
copy_chunks!(Bc, pos_d, Ac[k], pos_s[k], nrowsA[k])
pos_s[k] += nrowsA[k]
Expand Down
2 changes: 1 addition & 1 deletion base/combinatorics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function nextprod(a::Vector{Int}, x)
throw(ArgumentError("unsafe for x > typemax(Int), got $x"))
end
k = length(a)
v = ones(Int, k) # current value of each counter
v = fill(1, k) # current value of each counter
mx = [nextpow(ai,x) for ai in a] # maximum value of each counter
v[1] = mx[1] # start at first case that is >= x
p::widen(Int) = mx[1] # initial value of product in this case
Expand Down
4 changes: 2 additions & 2 deletions base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -926,14 +926,14 @@ An indexing operation into an array, `a`, tried to access an out-of-bounds eleme

# Examples
```jldoctest
julia> A = ones(7);
julia> A = fill(1.0, 7);

julia> A[8]
ERROR: BoundsError: attempt to access 7-element Array{Float64,1} at index [8]
Stacktrace:
[1] getindex(::Array{Float64,1}, ::Int64) at ./array.jl:758

julia> B = ones(2, 3);
julia> B = fill(1.0, (2,3));

julia> B[2, 4]
ERROR: BoundsError: attempt to access 2×3 Array{Float64,2} at index [2, 4]
Expand Down
4 changes: 2 additions & 2 deletions base/indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ Check two array shapes for compatibility, allowing trailing singleton dimensions
whichever shape has more dimensions.

```jldoctest
julia> a = ones(3,4,1,1,1);
julia> a = fill(1, (3,4,1,1,1));

julia> b = ones(3,4);
julia> b = fill(1, (3,4));

julia> promote_shape(a,b)
(Base.OneTo(3), Base.OneTo(4), Base.OneTo(1), Base.OneTo(1), Base.OneTo(1))
Expand Down
14 changes: 7 additions & 7 deletions base/linalg/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ Dot product of two vectors consisting of `n` elements of array `X` with stride `

# Examples
```jldoctest
julia> dot(10, ones(10), 1, ones(20), 2)
julia> dot(10, fill(1.0, 10), 1, fill(1.0, 20), 2)
10.0
```
"""
Expand All @@ -243,7 +243,7 @@ conjugating the first vector.

# Examples
```jldoctest
julia> Base.BLAS.dotc(10, im*ones(10), 1, complex.(ones(20), ones(20)), 2)
julia> Base.BLAS.dotc(10, fill(1.0im, 10), 1, fill(1.0+im, 20), 2)
10.0 - 10.0im
```
"""
Expand All @@ -257,7 +257,7 @@ with stride `incx` and `n` elements of array `Y` with stride `incy`.

# Examples
```jldoctest
julia> Base.BLAS.dotu(10, im*ones(10), 1, complex.(ones(20), ones(20)), 2)
julia> Base.BLAS.dotu(10, fill(1.0im, 10), 1, fill(1.0+im, 20), 2)
-10.0 + 10.0im
```
"""
Expand Down Expand Up @@ -349,10 +349,10 @@ stride1(x::Array) = 1

# Examples
```jldoctest
julia> Base.BLAS.nrm2(4, ones(8), 2)
julia> Base.BLAS.nrm2(4, fill(1.0, 8), 2)
2.0

julia> Base.BLAS.nrm2(1, ones(8), 2)
julia> Base.BLAS.nrm2(1, fill(1.0, 8), 2)
1.0
```
"""
Expand Down Expand Up @@ -382,10 +382,10 @@ Sum of the absolute values of the first `n` elements of array `X` with stride `i

# Examples
```jldoctest
julia> Base.BLAS.asum(5, im*ones(10), 2)
julia> Base.BLAS.asum(5, fill(1.0im, 10), 2)
5.0

julia> Base.BLAS.asum(2, im*ones(10), 5)
julia> Base.BLAS.asum(2, fill(1.0im, 10), 5)
2.0
```
"""
Expand Down
10 changes: 5 additions & 5 deletions base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ compute the cosine. Otherwise, the cosine is determined by calling [`exp`](@ref)

# Examples
```jldoctest
julia> cos(ones(2, 2))
julia> cos(fill(1.0, (2,2)))
2×2 Array{Float64,2}:
0.291927 -0.708073
-0.708073 0.291927
Expand Down Expand Up @@ -786,7 +786,7 @@ compute the sine. Otherwise, the sine is determined by calling [`exp`](@ref).

# Examples
```jldoctest
julia> sin(ones(2, 2))
julia> sin(fill(1.0, (2,2)))
2×2 Array{Float64,2}:
0.454649 0.454649
0.454649 0.454649
Expand Down Expand Up @@ -820,7 +820,7 @@ Compute the matrix sine and cosine of a square matrix `A`.

# Examples
```jldoctest
julia> S, C = sincos(ones(2, 2));
julia> S, C = sincos(fill(1.0, (2,2)));

julia> S
2×2 Array{Float64,2}:
Expand Down Expand Up @@ -872,7 +872,7 @@ compute the tangent. Otherwise, the tangent is determined by calling [`exp`](@re

# Examples
```jldoctest
julia> tan(ones(2, 2))
julia> tan(fill(1.0, (2,2)))
2×2 Array{Float64,2}:
-1.09252 -1.09252
-1.09252 -1.09252
Expand Down Expand Up @@ -1144,7 +1144,7 @@ will return a Cholesky factorization.

# Examples
```jldoctest
julia> A = Array(Bidiagonal(ones(5, 5), :U))
julia> A = Array(Bidiagonal(fill(1.0, (5, 5)), :U))
5×5 Array{Float64,2}:
1.0 1.0 0.0 0.0 0.0
0.0 1.0 1.0 0.0 0.0
Expand Down
12 changes: 6 additions & 6 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Upper triangle of a matrix.

# Examples
```jldoctest
julia> a = ones(4,4)
julia> a = fill(1.0, (4,4))
4×4 Array{Float64,2}:
1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0
Expand All @@ -145,7 +145,7 @@ Lower triangle of a matrix.

# Examples
```jldoctest
julia> a = ones(4,4)
julia> a = fill(1.0, (4,4))
4×4 Array{Float64,2}:
1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0
Expand All @@ -169,7 +169,7 @@ Returns the upper triangle of `M` starting from the `k`th superdiagonal.

# Examples
```jldoctest
julia> a = ones(4,4)
julia> a = fill(1.0, (4,4))
4×4 Array{Float64,2}:
1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0
Expand Down Expand Up @@ -200,7 +200,7 @@ Returns the lower triangle of `M` starting from the `k`th superdiagonal.

# Examples
```jldoctest
julia> a = ones(4,4)
julia> a = fill(1.0, (4,4))
4×4 Array{Float64,2}:
1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0
Expand Down Expand Up @@ -1209,9 +1209,9 @@ running in parallel, only 1 BLAS thread is used. The argument `n` still refers t
of the problem that is solved on each processor.
"""
function peakflops(n::Integer=2000; parallel::Bool=false)
a = ones(Float64,100,100)
a = fill(1.,100,100)
t = @elapsed a2 = a*a
a = ones(Float64,n,n)
a = fill(1.,n,n)
t = @elapsed a2 = a*a
@assert a2[1,1] == n
parallel ? sum(pmap(peakflops, [ n for i in 1:nworkers()])) : (2*Float64(n)^3/t)
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3731,7 +3731,7 @@ for (stev, stebz, stegr, stein, elty) in
isplit = similar(dv, BlasInt,n)
w = similar(dv, $elty,n)
if length(iblock_in) < m #Not enough block specifications
iblock[1:m] = ones(BlasInt, m)
iblock[1:m] = fill(BlasInt(1), m)
w[1:m] = sort(w_in)
else
iblock[1:m] = iblock_in
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ For multiple arguments, return a vector.

# Examples
```jldoctest
julia> A = ones(4,4); B = zeros(5,5);
julia> A = fill(1, (4,4)); B = fill(1, (5,5));

julia> LinAlg.checksquare(A, B)
2-element Array{Int64,1}:
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ factorize(A::Tridiagonal) = lufact(A)
function getproperty(F::LU{T,Tridiagonal{T,V}}, d::Symbol) where {T,V}
m, n = size(F)
if d == :L
L = Array(Bidiagonal(ones(T, n), getfield(getfield(F, :factors), :dl), d))
L = Array(Bidiagonal(fill(one(T), n), getfield(getfield(F, :factors), :dl), d))
for i = 2:n
tmp = L[getfield(F, :ipiv)[i], 1:i - 1]
L[getfield(F, :ipiv)[i], 1:i - 1] = L[i, 1:i - 1]
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,8 @@ function ldiv!(A::QRPivoted{T}, B::StridedMatrix{T}, rcond::Real) where T<:BlasF
return B, 0
end
rnk = 1
xmin = ones(T, 1)
xmax = ones(T, 1)
xmin = T[1]
xmax = T[1]
tmin = tmax = ar
while rnk < nr
tmin, smin, cmin = LAPACK.laic1!(2, xmin, tmin, view(A.factors, 1:rnk, rnk + 1), A.factors[rnk + 1, rnk + 1])
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ adjoint!(A::UpperTriangular) = LowerTriangular(copytri!(A.data, 'U' , true))
adjoint!(A::UnitUpperTriangular) = UnitLowerTriangular(copytri!(A.data, 'U' , true))

diag(A::LowerTriangular) = diag(A.data)
diag(A::UnitLowerTriangular) = ones(eltype(A), size(A,1))
diag(A::UnitLowerTriangular) = fill(one(eltype(A)), size(A,1))
diag(A::UpperTriangular) = diag(A.data)
diag(A::UnitUpperTriangular) = ones(eltype(A), size(A,1))
diag(A::UnitUpperTriangular) = fill(one(eltype(A)), size(A,1))

# Unary operations
-(A::LowerTriangular) = LowerTriangular(-A.data)
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ An object of type [`UniformScaling`](@ref), representing an identity matrix of a

# Examples
```jldoctest
julia> ones(5, 6) * I == ones(5, 6)
julia> fill(1, (5,6)) * I == fill(1, (5,6))
true

julia> [1 2im 3; 1im 2 3] * I
Expand Down
2 changes: 1 addition & 1 deletion base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ module IteratorsMD
CartesianIndex(1, 2, 2)
CartesianIndex(2, 2, 2)

julia> CartesianIndices(ones(2,3))
julia> CartesianIndices(fill(1, (2,3)))
2×3 CartesianIndices{2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}:
CartesianIndex(1, 1) CartesianIndex(1, 2) CartesianIndex(1, 3)
CartesianIndex(2, 1) CartesianIndex(2, 2) CartesianIndex(2, 3)
Expand Down
2 changes: 1 addition & 1 deletion base/sparse/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ end

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