Skip to content

Commit

Permalink
Actually run sparsevector tests
Browse files Browse the repository at this point in the history
Fix a few simple bugs
  • Loading branch information
mbauman committed Oct 7, 2015
1 parent a389967 commit 0d9f1a1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,14 @@ convert{Tv,TvS,TiS}(::Type{SparseVector{Tv}}, s::SparseVector{TvS,TiS}) =
### Rand Construction
sprand{T}(n::Integer, p::AbstractFloat, rfn::Function, ::Type{T}) = sprand(GLOBAL_RNG, n, p, rfn, T)
function sprand{T}(r::AbstractRNG, n::Integer, p::AbstractFloat, rfn::Function, ::Type{T})
I = randsubseq(1:convert(Int, n), p)
I = randsubseq(r, 1:convert(Int, n), p)
V = rfn(r, T, length(I))
SparseVector(n, I, V)
end

sprand(n::Integer, p::AbstractFloat, rfn::Function) = sprand(GLOBAL_RNG, n, p, rfn)
function sprand(r::AbstractRNG, n::Integer, p::AbstractFloat, rfn::Function)
I = randsubseq(1:convert(Int, n), p)
I = randsubseq(r, 1:convert(Int, n), p)
V = rfn(r, length(I))
SparseVector(n, I, V)
end
Expand Down
1 change: 1 addition & 0 deletions test/sparse.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: http://julialang.org/license

include("sparsedir/sparse.jl")
include("sparsedir/sparsevector.jl")
if Base.USE_GPL_LIBS
include("sparsedir/umfpack.jl")
include("sparsedir/cholmod.jl")
Expand Down
9 changes: 3 additions & 6 deletions test/sparsedir/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ end

### Show

@test string(spv_x1) == "Sparse vector, length = 8, with 3 Float64 entries:\n" *
" [2] = 1.25\n" *
" [5] = -0.75\n" *
" [6] = 3.5\n"

@test contains(string(spv_x1), "1.25")
@test contains(string(spv_x1), "-0.75")
@test contains(string(spv_x1), "3.5")

### Other Constructors

Expand Down Expand Up @@ -144,7 +142,6 @@ end
let xr = sprandbool(1000, 0.9)
@test isa(xr, SparseVector{Bool,Int})
@test length(xr) == 1000
@test all(nonzeros(xr))

This comment has been minimized.

Copy link
@tkelman

tkelman Oct 7, 2015

Contributor

nonzeros not implemented?

This comment has been minimized.

Copy link
@mbauman

mbauman Oct 7, 2015

Author Member

It is… just that sprandbool randomly creates both true and false values. Brain fart on my part. I suppose we could do all(nonzeros(xr) | !nonzeros(xr)) instead. is wrong.

This comment has been minimized.

Copy link
@tkelman

tkelman Oct 7, 2015

Contributor

the falses shouldn't be stored in a sparse boolean vector (not by default, anyway)

This comment has been minimized.

Copy link
@mbauman

mbauman Oct 7, 2015

Author Member

Good grief, I need to go to bed. Test was right, my implementation is wrong. I'll fix it in the morning. Thanks for the catch.

end

let r1 = MersenneTwister(), r2 = MersenneTwister()
Expand Down

0 comments on commit 0d9f1a1

Please sign in to comment.