-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Conversation
Oh gosh 😂 |
Thanks for picking this work up @fredrikekre! :) Please feel welcome to squash out / remove / * my early commits as you see fit. |
8037c99
to
7da6987
Compare
NEWS.md
Outdated
@@ -563,6 +563,11 @@ Deprecated or removed | |||
and/or shape depending on `opts...`. For an algebraic multiplicative identity, | |||
consider `one(A)` ([#24656]). | |||
|
|||
* `ones(dims...)` `and ones(T, dims)` have been deprecated. The replacements are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"and ones(T, dims)
" -> "and ones(T, dims)
?
NEWS.md
Outdated
@@ -563,6 +563,11 @@ Deprecated or removed | |||
and/or shape depending on `opts...`. For an algebraic multiplicative identity, | |||
consider `one(A)` ([#24656]). | |||
|
|||
* `ones(dims...)` `and ones(T, dims)` have been deprecated. The replacements are | |||
`fill(1.0, dims...)` and `fill(one(T), dims...)`, but other common patterns, such as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps mention using literals also for other common types, e.g. fill(1, dims...)
for Int
s, fill(1f0, dims...)
for Float32
, e.g. fill(1+0im, dims...)
for complex types, fill(0x1, dims...)
for UInt8
s, e.g. fill(1m, dims...)
for unitful types, et cetera? And perhaps fill(T(1), dims...)
as another alternative alongside fill(one(T), dims...)
?
base/array.jl
Outdated
@@ -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 [`similar`](@ref). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add a reference to fill
?
base/linalg/qr.jl
Outdated
xmin = ones(T, 1) | ||
xmax = ones(T, 1) | ||
xmin = fill(one(T), 1) | ||
xmax = fill(one(T), 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps vector literals?
@@ -211,7 +211,7 @@ For users coming to Julia from R, these are some noteworthy differences: | |||
by default. To get optimal performance when looping over arrays, the order of the loops should | |||
be reversed in Julia relative to NumPy (see relevant section of [Performance Tips](@ref man-performance-tips)). | |||
* Julia's updating operators (e.g. `+=`, `-=`, ...) are *not in-place* whereas NumPy's are. This | |||
means `A = ones(4); B = A; B += 3` doesn't change values in `A`, it rather rebinds the name `B` | |||
means `A = fill(1, 4); B = A; B .+= 3` doesn't change values in `A`, it rather rebinds the name `B` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch re. +=
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I hadn't read the rest of the sentence :). +=
is indeed correct, rather than .+=
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, the reason I changed was that vector + scalar is deprecated, so perhaps we should just rewrite the example completely.
Edit: Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect! :)
global mrefs = TestSerCnt(ones(10)) | ||
@test remotecall_fetch(()->(mrefs.v, 2*mrefs.v, 3*mrefs.v), id_other) == (ones(10), 2*ones(10), 3*ones(10)) | ||
global mrefs = TestSerCnt(fill(1.,10)) | ||
@test remotecall_fetch(()->(mrefs.v, 2*mrefs.v, 3*mrefs.v), id_other) == (fill(1.,10), fill(2.,10), fill(3.,10)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -1180,7 +1179,7 @@ end | |||
X = [ i+2j for i=1:5, j=1:5 ] | |||
@test X[2,3] == 8 | |||
@test X[4,5] == 14 | |||
@test isequal(ones(2,3) * ones(2,3)', [3. 3.; 3. 3.]) | |||
@test isequal(fill(3.,2,2), [3. 3.; 3. 3.]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why this test exists under the heading "comprehensions" and what purpose it serves :).
8cf78a2
to
6db0c9b
Compare
base/abstractarray.jl
Outdated
@@ -31,7 +31,7 @@ lengths of dimensions you asked for. | |||
|
|||
# Examples | |||
```jldoctest | |||
julia> A = ones(2,3,4); | |||
julia> A = fill(1,2,3,4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fill(1,2,3,4)
-> fill(1, (2,3,4))
for these examples? :)
Sure, give it a shot. We'll see how much kicking and screaming there is. |
Triage likes replacing the uses of |
Rebased and dropped the last commit for later. |
eec1872
to
273c6c3
Compare
@@ -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). |
There was a problem hiding this comment.
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
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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). |
There was a problem hiding this comment.
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
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
stdlib/SuiteSparse/test/cholmod.jl
Outdated
x = fill(1., 5) | ||
@test cholfact(sparse(Float16(1)I, 5, 5))\x == x | ||
@test cholfact(Symmetric(sparse(Float16(1)I, 5, 5)))\x == x | ||
@test cholfact(Hermitian(sparse(Complex{Float16}(1)I, 5, 5)))\x == fill(1.0+0im, 5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could simplify the RHS to x
I think?
f67d64b
to
2065aa7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Much thanks for seeing this work through @fredrikekre! :)
Linking #25392 (comment) but with |
Some joint work between me and @Sacha0. I have to say, rewriting all of the
ones
call tofill
is a real pleasure. I was skeptic at first, but now I lovefill
just as much as @Sacha0.Please read JuliaLang/LinearAlgebra.jl#484 and #24595 and the linked discussion therein.
This PR has also been rebased for hours through the large changes of
eye
, anduninitialized
array constructors, so it better get merged! 😄