From bef6bf335773cafdc2786f1fbabacc01e0be6260 Mon Sep 17 00:00:00 2001 From: jake bolewski Date: Thu, 26 Feb 2015 02:41:35 -0500 Subject: [PATCH] write cholmod matrix market test file to tmp directory --- base/sparse/cholmod.jl | 2 +- test/sparsedir/cholmod.jl | 34 +++++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/base/sparse/cholmod.jl b/base/sparse/cholmod.jl index f8409b04f17c1..463a8cb37815c 100644 --- a/base/sparse/cholmod.jl +++ b/base/sparse/cholmod.jl @@ -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) diff --git a/test/sparsedir/cholmod.jl b/test/sparsedir/cholmod.jl index 9b3d28bdf717f..671cd918dc9db 100644 --- a/test/sparsedir/cholmod.jl +++ b/test/sparsedir/cholmod.jl @@ -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))