Skip to content

Instantly share code, notes, and snippets.

@KristofferC
Created May 21, 2015 08:47
Show Gist options
  • Save KristofferC/5b02b179208f72bbf591 to your computer and use it in GitHub Desktop.
Save KristofferC/5b02b179208f72bbf591 to your computer and use it in GitHub Desktop.
function isstructsym(A::SparseMatrixCSC)
m, n = size(A)
if m != n; return false; end
colptr = A.colptr
rowval = A.rowval
nzval = A.nzval
tracker = copy(A.colptr)
@inbounds for col = 1:A.n
for p = tracker[col]:colptr[col+1]-1
val = nzval[p]
row = rowval[p]
row < col && return false
if row > col
row2 = rowval[tracker[row]]
row2 > col && return false
if row2 == col
tracker[row] += 1
end
end
end
end
return true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment