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

make sprand type stable #16074

Merged
merged 1 commit into from
May 1, 2016

Conversation

KristofferC
Copy link
Member

@KristofferC KristofferC commented Apr 27, 2016

fixes #16073

@KristofferC
Copy link
Member Author

Actually, maybe the second sprand function is better as:

function sprand{T}(m::Integer, n::Integer, density::AbstractFloat,
                rfn::Function, t::Type{T}=eltype(rfn(1)))
    return sprand(GLOBAL_RNG, m, n, density, rfn, t)
end

@KristofferC
Copy link
Member Author

KristofferC commented Apr 27, 2016

Added that.

Edit: Removed that. The passed random function doesn't take a RNG object for the second sprand function

@KristofferC KristofferC force-pushed the kc/sprand_typestable branch from 3fa04ff to f0080a0 Compare April 27, 2016 16:23
@KristofferC
Copy link
Member Author

KristofferC commented Apr 27, 2016

Interesting, git reset --hard to an old commit and then force pushing that commit means that travis will fail because it thinks a newer commit exist.

@KristofferC KristofferC force-pushed the kc/sprand_typestable branch from f0080a0 to 6434092 Compare April 27, 2016 17:00
@nalimilan
Copy link
Member

Maybe git commit --amend date=now?

@KristofferC
Copy link
Member Author

I just rebased on a newer master commit

@@ -917,7 +917,7 @@ function sprand{T}(m::Integer, n::Integer, density::AbstractFloat,
rfn::Function, ::Type{T}=eltype(rfn(1)))
N = m*n
N == 0 && return spzeros(T,m,n)
N == 1 && return rand() <= density ? sparse(rfn(1)) : spzeros(T,1,1)
N == 1 && return rand() <= density ? sparse([1], [1], rfn(GLOBAL_RNG,1)) : spzeros(T,1,1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. Will fix in a while. rfn should not take a RNG.

@KristofferC KristofferC force-pushed the kc/sprand_typestable branch from 6434092 to a7f3108 Compare April 28, 2016 10:23
@KristofferC
Copy link
Member Author

Test passes, ready for review / merge.

# 16073
@inferred sprand(1, 1, 1.0)
@inferred sprand(1, 1, 1.0, rand, Float64)
@inferred sprand(1, 1, 1.0, x->round(Int,rand(x)*100))
Copy link
Member

@Sacha0 Sacha0 Apr 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why x -> round(Int, rand(x)*100) rather than x -> rand(0:100, x)?

Copy link
Member Author

@KristofferC KristofferC Apr 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied this from another test that happened to fail when I did a mistake in implementing this PR:

let S = sprand(50, 30, 0.5, x->round(Int,rand(x)*100)), I = sprandbool(50, 30, 0.2)

also fix use of undefined variable in sprand
@KristofferC KristofferC force-pushed the kc/sprand_typestable branch from a7f3108 to 8159a38 Compare May 1, 2016 08:40
@KristofferC
Copy link
Member Author

Bump

@ViralBShah ViralBShah merged commit 7346571 into JuliaLang:master May 1, 2016
@ViralBShah
Copy link
Member

I guess we should separately have a version of sprand for random sparse vectors.

@ViralBShah
Copy link
Member

We already do - this was just a type inference issue in the sprand case for matrices. All good. Thanks.

@ViralBShah ViralBShah added the sparse Sparse arrays label May 1, 2016
@KristofferC KristofferC deleted the kc/sprand_typestable branch May 1, 2016 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sparse Sparse arrays
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sprand is type unstable
4 participants