Skip to content

Commit c15a86c

Browse files
committed
LinearAlgebra: delete _rand_pm1! in favor of rand!
1 parent bb0d78a commit c15a86c

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

stdlib/SparseArrays/src/linalg.jl

+3-8
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

@@ -735,12 +736,6 @@ function opnormestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A))
735736

736737
S = zeros(T <: Real ? Int : Ti, n, t)
737738

738-
function _rand_pm1!(v)
739-
for i in eachindex(v)
740-
v[i] = rand()<0.5 ? 1 : -1
741-
end
742-
end
743-
744739
function _any_abs_eq(v,n::Int)
745740
for vv in v
746741
if abs(vv)==n
@@ -755,7 +750,7 @@ function opnormestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A))
755750
X[1:n,1] .= 1
756751
for j = 2:t
757752
while true
758-
_rand_pm1!(view(X,1:n,j))
753+
rand!(view(X,1:n,j), (-1, 1))
759754
yaux = X[1:n,j]' * X[1:n,1:j-1]
760755
if !_any_abs_eq(yaux,n)
761756
break
@@ -816,7 +811,7 @@ function opnormestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A))
816811
end
817812
end
818813
if repeated
819-
_rand_pm1!(view(S,1:n,j))
814+
rand!(view(S,1:n,j), (-1, 1))
820815
else
821816
break
822817
end

0 commit comments

Comments
 (0)