{"action":"created","issue":{"url":"https://api.github.com/repos/scipy/scipy/issues/4409","labels_url":"https://api.github.com/repos/scipy/scipy/issues/4409/labels{/name}","comments_url":"https://api.github.com/repos/scipy/scipy/issues/4409/comments","events_url":"https://api.github.com/repos/scipy/scipy/issues/4409/events","html_url":"https://github.com/scipy/scipy/issues/4409","id":54522277,"number":4409,"title":"scipy.sparse.csgraph needs tests and documentation for non-canonical input","user":{"login":"jnothman","id":78827,"avatar_url":"https://avatars.githubusercontent.com/u/78827?v=3","gravatar_id":"","url":"https://api.github.com/users/jnothman","html_url":"https://github.com/jnothman","followers_url":"https://api.github.com/users/jnothman/followers","following_url":"https://api.github.com/users/jnothman/following{/other_user}","gists_url":"https://api.github.com/users/jnothman/gists{/gist_id}","starred_url":"https://api.github.com/users/jnothman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnothman/subscriptions","organizations_url":"https://api.github.com/users/jnothman/orgs","repos_url":"https://api.github.com/users/jnothman/repos","events_url":"https://api.github.com/users/jnothman/events{/privacy}","received_events_url":"https://api.github.com/users/jnothman/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/scipy/scipy/labels/scipy.sparse.csgraph","name":"scipy.sparse.csgraph","color":"207de5"},{"url":"https://api.github.com/repos/scipy/scipy/labels/task","name":"task","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-15T23:53:15Z","updated_at":"2015-01-17T23:46:20Z","closed_at":null,"body":"CSR/CSC matrices and others can be non-canonical in that they have unsorted or even duplicate indices for a particular row, as well as entries that have an explicit \"0\" entry in a cell.\r\n\r\nWhile I expect the `csgraph` methods work for unsorted indices, there should certainly be a test for the effect of duplicate indices (and I don't see one presently). In addition, at least `connected_components` treats explicit zeros as indicative of an edge (thus `connected_components(X)` for CSR X is not always equivalent to `connected_components(X.A)`), which should be documented."},"comment":{"url":"https://api.github.com/repos/scipy/scipy/issues/comments/70389805","html_url":"https://github.com/scipy/scipy/issues/4409#issuecomment-70389805","issue_url":"https://api.github.com/repos/scipy/scipy/issues/4409","id":70389805,"user":{"login":"argriffing","id":101416,"avatar_url":"https://avatars.githubusercontent.com/u/101416?v=3","gravatar_id":"","url":"https://api.github.com/users/argriffing","html_url":"https://github.com/argriffing","followers_url":"https://api.github.com/users/argriffing/followers","following_url":"https://api.github.com/users/argriffing/following{/other_user}","gists_url":"https://api.github.com/users/argriffing/gists{/gist_id}","starred_url":"https://api.github.com/users/argriffing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/argriffing/subscriptions","organizations_url":"https://api.github.com/users/argriffing/orgs","repos_url":"https://api.github.com/users/argriffing/repos","events_url":"https://api.github.com/users/argriffing/events{/privacy}","received_events_url":"https://api.github.com/users/argriffing/received_events","type":"User","site_admin":false},"created_at":"2015-01-17T23:46:20Z","updated_at":"2015-01-17T23:46:20Z","body":"The conventions adopted by `sparse.csgraph` seem problematic to me.\r\n\r\nFrom the docs:\r\n```\r\n[...] In this case, the dense representation above leads to ambiguities: how can non-edges be represented if zero is a meaningful value? In this case, either a masked or sparse representation must be used to eliminate the ambiguity [...]\r\n```\r\n\r\nTo me this implies that csgraph wants the presence vs. absence of entries in a `scipy.sparse` matrix to correspond to the presence vs. absence of edges in the corresponding graph, while simultaneously allowing `0` to be a valid edge value.  I see this as incompatible with the `scipy.sparse` semantics where the explicit vs. implicit representation of a zero is an implementation detail.\r\n\r\n```\r\n>>> a = csr_matrix(np.ones((4, 4)))\r\n>>> a.nnz\r\n16\r\n>>> (0*a).A\r\narray([[ 0.,  0.,  0.,  0.],\r\n       [ 0.,  0.,  0.,  0.],\r\n       [ 0.,  0.,  0.,  0.],\r\n       [ 0.,  0.,  0.,  0.]])\r\n>>> (0*a).nnz\r\n16\r\n>>> (a-a).A\r\narray([[ 0.,  0.,  0.,  0.],\r\n       [ 0.,  0.,  0.,  0.],\r\n       [ 0.,  0.,  0.,  0.],\r\n       [ 0.,  0.,  0.,  0.]])\r\n>>> (a-a).nnz\r\n0\r\n```"}}