Repository navigation
68 bool weights - #166
Open
eriknw wants to merge 1 commit into
Open
68 bool weights#166eriknw wants to merge 1 commit into
eriknw wants to merge 1 commit into
Conversation
NetworkX adds Python's bools as the ints 1 and 0, adds two of NumPy's as a logical or (np.True_ + np.True_ is True), and some of its answers hold a weight as it was given: the distance along one edge from floyd_warshall_predecessor_and_distance, the edges of ego_graph, the entries of adjacency_matrix. The conversion gave weights that were all bools a matrix of bools, which has no plus: modularity_matrix raised KeyError, and laplacian_matrix answered in bools where NetworkX answers in ints. Bools beside ints or floats became numbers, so an answer that holds a weight gave 1 where NetworkX gives True, and mutual_weight gave 2 where NetworkX gives True. A weight with a bool value anywhere is now refused at conversion, and NetworkX answers. A matrix of bools says so at once. In a matrix of numbers a bool is held as 1 or 0, so only the edges with those values are looked up, one at a time when they are few, and all the values at once, their types gathered at C speed, when they are many. A cast to int64 would match NetworkX's sums, but not the answers that hold a weight as given, nor NumPy's logical or. A graph rebuilt from its matrix, as by reverse or k_truss, no longer takes bool weights either, so its note no longer says they come back as numbers.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 61-generic-declines #166 +/- ##
=======================================================
- Coverage 92.90% 92.83% -0.08%
=======================================================
Files 182 183 +1
Lines 11294 11488 +194
Branches 1281 1314 +33
=======================================================
+ Hits 10493 10665 +172
- Misses 547 560 +13
- Partials 254 263 +9 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NetworkX adds Python's bools as the ints 1 and 0, adds two of NumPy's as a logical or (
np.True_ + np.True_isTrue), and some of its answers hold a weight as it was given. A weight with a bool value anywhere is now refused at conversion, so NetworkX answers. A cast of bools to int64 would match NetworkX's sums, but not the answers that hold a weight as given, nor NumPy's logical or, so it was not the rule.modularity_matrixanddirected_modularity_matrixraisedKeyError: 'plus does not work with BOOL'where NetworkX answers;laplacian_matrixanswered a matrix of bools (True for 3 and for -1);normalized_laplacian_matrixanswered -1.0 for every edge where NetworkX gives -0.408 and the like. Answers that hold a weight gave 1 where NetworkX givesTrue: the distance along one edge fromfloyd_warshall_predecessor_and_distance, the edges ofego_graph. With NumPy's boolsmutual_weightgave 2 where NetworkX givesTrue.Trueis not 1), floats within 1e-9. Before: 211 of 1548 calls differed in NetworkX dev, 219 of 1548 in 3.7 and 205 of 1512 in 3.6.1. After: none. Of those before, 67 in each were the bools' own (43 in value, 24 in type only): the same call with each bool an int matched NetworkX. The rest those int twins share, such asclustering's 0.0 where NetworkX gives the int 0; the refusal leaves the bool calls among them to NetworkX too. The int twins' calls are unchanged (150, 158 and 144 differing before and after, none of them about bools).-Trueis -1) and adds back. So only the edges whose values are exactly 1 or 0 are looked up in the graph, one at a time when they are fewer than a quarter of the entries, and else all the values at once, their types gathered withmapandset. The check's cost beside the conversion, on 1000000 edges (Indicative, best of 3): nothing for float weights (none exactly 1 or 0), 10% for ints from 1 to 9, and 27% where every weight is 1, as large as a read of every value.reverseork_truss, whose weights were all bools came back exactly, bools and all; NetworkX answers it now, and so it does where such a name carries another edge attribute of bools, as a flag on a graph with no weights:ego_graph,reverse,k_trussand thek_corefamily leave those to NetworkX too (a review found 13 such calls of 242). Names that read no edge data, such aspagerankwithweight=Noneortriangles, still serve these graphs, and so does every name where the bools are another attribute beside numeric weights. The note on those names no longer says bools come back as numbers.reverse,k_truss,k_coreandego_graph. Tests that bools convert, andmodularity's test on a NetworkX graph with bool weights, are changed to the new rule; a backend graph that already holds bools is still served. 11 mutants of the refusal each fail them, in NetworkX dev, 3.7 and 3.6.1.Stacked on #156.