Skip to content

Commit 3ba74d6

Browse files
committed
LinearAlgebra: delete _rand_pm1! in favor of rand!
1 parent c271362 commit 3ba74d6

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

stdlib/SparseArrays/src/linalg.jl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
import LinearAlgebra: checksquare
4+
using Random: rand!
45

56
## sparse matrix multiplication
67

@@ -929,12 +930,6 @@ function opnormestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A))
929930

930931
S = zeros(T <: Real ? Int : Ti, n, t)
931932

932-
function _rand_pm1!(v)
933-
for i in eachindex(v)
934-
v[i] = rand()<0.5 ? 1 : -1
935-
end
936-
end
937-
938933
function _any_abs_eq(v,n::Int)
939934
for vv in v
940935
if abs(vv)==n
@@ -949,7 +944,7 @@ function opnormestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A))
949944
X[1:n,1] .= 1
950945
for j = 2:t
951946
while true
952-
_rand_pm1!(view(X,1:n,j))
947+
rand!(view(X,1:n,j), (-1, 1))
953948
yaux = X[1:n,j]' * X[1:n,1:j-1]
954949
if !_any_abs_eq(yaux,n)
955950
break
@@ -1010,7 +1005,7 @@ function opnormestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A))
10101005
end
10111006
end
10121007
if repeated
1013-
_rand_pm1!(view(S,1:n,j))
1008+
rand!(view(S,1:n,j), (-1, 1))
10141009
else
10151010
break
10161011
end

0 commit comments

Comments
 (0)