It's tricky, but sprank is definitely not competitive with finer implementations. As you certainly know, rank calculations are very unstable, so if your matrix has integer entries you should prefer an exact method, or a calculation in a finite field. (Sadly, Julia does not contain, yet, sparse matrices with non-real/complex entries). See
http://dx.doi.org.sci-hub.io/10.1145/2513109.2513116 for a recent discussion of sparse matrix rank.
The following routines compute null spaces. To obtain the rank, you subtract the nullspace dimension from the row space dimension (i.e. number of columns). If you want pure Julia, you could try
function julia_null_space{T}(A::SparseMatrixCSC{T})
SVD = svdfact(full(A), thin = false)
any(1.e-8 .< SVD.S .< 1.e-4) && error("Values are dangerously small")
indstart = sum(SVD.S .> 1.e-8) + 1
nullspace = SVD.Vt[indstart:end,:]'
return sparse(nullspace .* (abs(nullspace) .> 1.e-8))
end
If you have MATLAB, the following is faster:
using MATLAB
global m_session = MSession()
function matlab_null_space{T}(A::SparseMatrixCSC{T})
m, n = size(A)
(m == 0 || n == 0) && return speye(T, n)
put_variable(m_session,:A,convert(SparseMatrixCSC{Float64},A))
eval_string(m_session,"N = spqr_null(A,struct('tol',1.e-8));")
eval_string(m_session,"ns = spqr_null_mult(N,speye(size(N.X,2)),1);")
eval_string(m_session,"ns = sparseclean(ns,1.e-8);")
ns = get_mvariable(m_session,:ns)
return jvariable(ns)
end
HTH, Laurent