Skip to content

Instantly share code, notes, and snippets.

@IainNZ
Created September 6, 2015 21:51
Show Gist options
  • Save IainNZ/12a712c8650d0a95a20d to your computer and use it in GitHub Desktop.
Save IainNZ/12a712c8650d0a95a20d to your computer and use it in GitHub Desktop.
for col in 1:n
for idx in colptr[i]:colptr[i]-1
row = rowval[idx]
nzv = nzvals[idx]
if row==col && nzv
return true
elseif row>col
break
end
end
end
return false
@sbromberger
Copy link

has_self_loop(g::SimpleSparseGraph) =
    @inbounds for col in 1:g.fm.n
        @inbounds for idx in g.fm.colptr[col]:g.fm.colptr[col+1]-1
            row = g.fm.rowval[idx]
            nzv = g.fm.nzval[idx]
            if row == col && nzv
                return true
            elseif row > col
                break
            end
        end
    end
    return false
end

@IainNZ
Copy link
Author

IainNZ commented Sep 6, 2015

function has_self_loop(g::SimpleSparseGraph)
   n = g.fm
   colptr = g.fm.colptr
   rowval = g.fm.rowval 
   nzval = g.fm.nzval
   @inbounds for col in 1:n
        for idx in colptr[col]:colptr[col+1]-1
            row = rowval[idx]
            nzv = nzval[idx]
            if row == col && nzv
                return true
            elseif row > col
                break
            end
        end
    end
    return false
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment