-
-
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 zeros(...) calls #25392
rewrite all zeros(...) calls #25392
Conversation
One interesting thing that I encountered while doing this transformation is the difficulty to understand calls like Therefore; I think we should consider doing one of the following:
|
+1 for requiring the first argument to be a type. |
stdlib/SuiteSparse/test/umfpack.jl
Outdated
@@ -159,7 +159,7 @@ | |||
N = 10 | |||
p = 0.5 | |||
A = N*I + sprand(N, N, p) | |||
X = zeros(Complex{Float64}, N, N) | |||
X = fill(0.0+im, N, N) |
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.
That's not a complex zero.
base/multidimensional.jl
Outdated
@@ -1156,7 +1156,7 @@ the other elements are left untouched. | |||
```jldoctest | |||
julia> x = [1., 0., 3., 0., 5.]; | |||
|
|||
julia> y = zeros(7); | |||
julia> y = Vector{Float64}(uninitialized, 7); |
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.
The example is meant to show the last two zeros being preserved, so filling with uninitialized doesn't seem right.
b96ccdf
to
1a72f32
Compare
What about something like this, so it is really obvious where the type should go?
|
Triage likes |
… something else is clearly better
1a72f32
to
c3513ca
Compare
c3513ca
to
32bcb30
Compare
Rebased and regrouped the commits: The first commit removes all calls to If we decide to keep |
@@ -10,7 +10,7 @@ general nonsymmetric matrices respectively. | |||
|
|||
For the single matrix version, | |||
|
|||
`eigs(A; nev=6, ncv=max(20,2*nev+1), which=:LM, tol=0.0, maxiter=300, sigma=nothing, ritzvec=true, v0=zeros((0,))) -> (d,[v,],nconv,niter,nmult,resid)` | |||
`eigs(A; nev=6, ncv=max(20,2*nev+1), which=:LM, tol=0.0, maxiter=300, sigma=nothing, ritzvec=true, v0=[]) -> (d,[v,],nconv,niter,nmult,resid)` |
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.
In case preservation of the element type matters in this case, Float64[]
? :)
@@ -125,7 +125,7 @@ julia> λ | |||
|
|||
For the two-input generalized eigensolution version, | |||
|
|||
`eigs(A, B; nev=6, ncv=max(20,2*nev+1), which=:LM, tol=0.0, maxiter=300, sigma=nothing, ritzvec=true, v0=zeros((0,))) -> (d,[v,],nconv,niter,nmult,resid)` | |||
`eigs(A, B; nev=6, ncv=max(20,2*nev+1), which=:LM, tol=0.0, maxiter=300, sigma=nothing, ritzvec=true, v0=[]) -> (d,[v,],nconv,niter,nmult,resid)` |
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.
Likewise here, in case preservation of the element type matters in this case, Float64[]
? :)
@@ -17,7 +17,7 @@ using .ARPACK | |||
|
|||
## eigs | |||
""" | |||
eigs(A; nev=6, ncv=max(20,2*nev+1), which=:LM, tol=0.0, maxiter=300, sigma=nothing, ritzvec=true, v0=zeros((0,))) -> (d,[v,],nconv,niter,nmult,resid) | |||
eigs(A; nev=6, ncv=max(20,2*nev+1), which=:LM, tol=0.0, maxiter=300, sigma=nothing, ritzvec=true, v0=[]) -> (d,[v,],nconv,niter,nmult,resid) |
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.
(Likewise here the Float64[]
question.)
@@ -57,15 +57,15 @@ function eigs(A::AbstractMatrix, B::AbstractMatrix; kwargs...) | |||
eigs(convert(AbstractMatrix{Tnew}, A), convert(AbstractMatrix{Tnew}, B); kwargs...) | |||
end | |||
""" | |||
eigs(A, B; nev=6, ncv=max(20,2*nev+1), which=:LM, tol=0.0, maxiter=300, sigma=nothing, ritzvec=true, v0=zeros((0,))) -> (d,[v,],nconv,niter,nmult,resid) | |||
eigs(A, B; nev=6, ncv=max(20,2*nev+1), which=:LM, tol=0.0, maxiter=300, sigma=nothing, ritzvec=true, v0=[]) -> (d,[v,],nconv,niter,nmult,resid) |
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.
(Likewise here the Float64[]
question.)
@@ -246,7 +246,7 @@ function svds(A::AbstractMatrix{T}; kwargs...) where T | |||
end | |||
|
|||
""" | |||
svds(A; nsv=6, ritzvec=true, tol=0.0, maxiter=1000, ncv=2*nsv, v0=zeros((0,))) -> (SVD([left_sv,] s, [right_sv,]), nconv, niter, nmult, resid) | |||
svds(A; nsv=6, ritzvec=true, tol=0.0, maxiter=1000, ncv=2*nsv, v0=[]) -> (SVD([left_sv,] s, [right_sv,]), nconv, niter, nmult, resid) |
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.
(Likewise here the Float64[]
question.)
@test_throws DimensionMismatch LinAlg.checksquare(zeros(2,3)) | ||
A2x2, A3x3, A2x3 = Matrix{Float64}.(uninitialized, ((2,2), (3,3), (2,3))) | ||
@test LinAlg.checksquare(A2x2) == 2 | ||
@test LinAlg.checksquare(zA2x2, A3x3) == [2, 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.
zA2x2
-> A2x2
? :)
|
||
@test_throws DimensionMismatch LAPACK.orghr!(1, 10, C, zeros(elty,11)) | ||
@test_throws DimensionMismatch LAPACK.orghr!(1, 10, A10x10, x11) | ||
end | ||
end |
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.
Beautifully done rewriting this section :).
@@ -15,12 +15,13 @@ using Base.LinAlg: mul! | |||
((0,0), (0,4), (0,4)), | |||
((3,0), (0,0), (3,0)), | |||
((0,0), (0,0), (0,0)) ) | |||
@test Matrix{Float64}(uninitialized, dimsA) * Matrix{Float64}(uninitialized, dimsB) == zeros(dimsC) | |||
A, B, C = Matrix{Float64}.(uninitialized, (dimsA, dimsB, dimsC)) | |||
@test A * B == C |
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.
Will the ((3,0), (0,4), (3,4))
case not fail?
A = Matrix{Float64}(uninitialized, 5, 0) | ||
B = Matrix{ComplexF64}(uninitialized, 5, 0) | ||
@test A'A == B'B == fill(0, (0,0)) | ||
@test A*A' == B*B' == fill(0, (5,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.
Nicely done :).
b = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(b, zeros(n,n)) : b) | ||
x = eltya == Int ? rand(1:7, n) : copy!(Vector{eltya}(uninitialized, n), randn(n)) | ||
y = eltya == Int ? rand(1:7, n) : copy!(Vector{eltya}(uninitialized, n), randn(n)) | ||
b = eltya == Int ? rand(1:7, n, n) : copy!(Matrix{eltya}(uninitialized, n, n), randn(n,n)/2) |
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.
Would simpler convert(Vector{eltya}, randn(n))
-like rewrites work? :)
@@ -20,7 +20,7 @@ julia> A = [3+2im 9+2im; 8+7im 4+6im] | |||
3+2im 9+2im | |||
8+7im 4+6im | |||
|
|||
julia> B = zeros(Complex{Int64}, 2, 2) | |||
julia> B = [0+0im 0+0im; 0+0im 0+0im] |
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.
0im
suffices? :)
@@ -13,7 +13,7 @@ if Sys.iswindows() | |||
if len == 0 | |||
return Libc.GetLastError() != ERROR_ENVVAR_NOT_FOUND ? "" : onError(str) | |||
end | |||
val = zeros(UInt16,len) | |||
val = fill(zero(UInt16), len) |
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.
Slightly simpler: UInt16(0)
. (Edit: Likewise below with a number of different concrete types.)
An appreciable fraction of the first commit's rewrites seem like strict improvements; merging those rewrites would be lovely independent of Though more subjective, I also find most rewrites in commits three through nine improvements; merging some agreeable subset of those rewrites would be lovely independent of Much thanks for your efforts on this front @fredrikekre! :) |
Were you still interested in doing the changes suggested by Sacha0, or should we close this? |
Since |
This rewrites all
zeros([T, ] dims...)
calls, first commit is #25087See #24444, #24595, #25087