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

add rand(::Tuple) #25278

Merged
merged 2 commits into from
Dec 4, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
LinearAlgebra: delete _rand_pm1! in favor of rand!
  • Loading branch information
rfourquet committed Nov 30, 2018
commit 3ba74d69d3ab75dd74eb3c966aad629f7531ec3d
11 changes: 3 additions & 8 deletions stdlib/SparseArrays/src/linalg.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

import LinearAlgebra: checksquare
using Random: rand!

## sparse matrix multiplication

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

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

function _rand_pm1!(v)
for i in eachindex(v)
v[i] = rand()<0.5 ? 1 : -1
end
end

function _any_abs_eq(v,n::Int)
for vv in v
if abs(vv)==n
Expand All @@ -949,7 +944,7 @@ function opnormestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A))
X[1:n,1] .= 1
for j = 2:t
while true
_rand_pm1!(view(X,1:n,j))
rand!(view(X,1:n,j), (-1, 1))
yaux = X[1:n,j]' * X[1:n,1:j-1]
if !_any_abs_eq(yaux,n)
break
Expand Down Expand Up @@ -1010,7 +1005,7 @@ function opnormestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A))
end
end
if repeated
_rand_pm1!(view(S,1:n,j))
rand!(view(S,1:n,j), (-1, 1))
else
break
end
Expand Down