Skip to content

Commit

Permalink
write cholmod matrix market test file to tmp directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolewski committed Feb 26, 2015
1 parent 46f6cac commit bef6bf3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion base/sparse/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ end
# default is Cint which is probably sufficient when converted from dense matrix
Sparse(A::Dense) = dense_to_sparse(A, Cint)
Sparse(L::Factor) = factor_to_sparse!(copy(L))
function Sparse(filename::ASCIIString)
function Sparse(filename::ByteString)
f = open(filename)
A = read_sparse(CFILE(f), SuiteSparse_long)
close(f)
Expand Down
34 changes: 25 additions & 9 deletions test/sparsedir/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,31 @@ B = CHOLMOD.Sparse(SparseMatrixCSC{Float64,Int32}(sprandn(48, 48, 0.1))) # A has
@test_approx_eq A*B sparse(A)*sparse(B)

# test Sparse constructor for c_SparseVoid (and read_sparse)
writedlm("tmp.mtx", ["%%MatrixMarket matrix coordinate real symmetric","3 3 4","1 1 1","2 2 1","3 2 0.5","3 3 1"])
@test sparse(CHOLMOD.Sparse("tmp.mtx")) == [1 0 0;0 1 0.5;0 0.5 1]
run(`rm tmp.mtx`)
writedlm("tmp.mtx", ["%%MatrixMarket matrix coordinate complex Hermitian","3 3 4","1 1 1.0 0.0","2 2 1.0 0.0","3 2 0.5 0.5","3 3 1.0 0.0"])
@test sparse(CHOLMOD.Sparse("tmp.mtx")) == [1 0 0;0 1 0.5-0.5im;0 0.5+0.5im 1]
run(`rm tmp.mtx`)
writedlm("tmp.mtx", ["%%MatrixMarket matrix coordinate real symmetric","%3 3 4","1 1 1","2 2 1","3 2 0.5","3 3 1"])
@test_throws ArgumentError sparse(CHOLMOD.Sparse("tmp.mtx"))
run(`rm tmp.mtx`)
let testfile = joinpath(tempdir(), "tmp.mtx")
try
writedlm(testfile, ["%%MatrixMarket matrix coordinate real symmetric","3 3 4","1 1 1","2 2 1","3 2 0.5","3 3 1"])
@test sparse(CHOLMOD.Sparse(testfile)) == [1 0 0;0 1 0.5;0 0.5 1]
finally
rm(testfile)
end
end
let testfile = joinpath(tempdir(), "tmp.mtx")
try
writedlm(testfile, ["%%MatrixMarket matrix coordinate complex Hermitian",
"3 3 4","1 1 1.0 0.0","2 2 1.0 0.0","3 2 0.5 0.5","3 3 1.0 0.0"])
@test sparse(CHOLMOD.Sparse(testfile)) == [1 0 0;0 1 0.5-0.5im;0 0.5+0.5im 1]
finally
rm(testfile)
end
end
let testfile = joinpath(tempdir(), "tmp.mtx")
try
writedlm(testfile, ["%%MatrixMarket matrix coordinate real symmetric","%3 3 4","1 1 1","2 2 1","3 2 0.5","3 3 1"])
@test_throws ArgumentError sparse(CHOLMOD.Sparse(testfile))
finally
rm(testfile)
end
end

# test that Sparse(Ptr) constructor throws the right places
@test_throws ArgumentError CHOLMOD.Sparse(convert(Ptr{CHOLMOD.C_Sparse{Float64,CHOLMOD.SuiteSparse_long}}, C_NULL))
Expand Down

0 comments on commit bef6bf3

Please sign in to comment.