Skip to content

Commit d946f29

Browse files
authored
Merge pull request #47 from eriknw/readme_code_highlighting
Don't use subassign syntax in README.md
2 parents e197076 + 5c1b6b4 commit d946f29

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

README.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Python wrapper around GraphBLAS
1111

1212
To install, `conda install -c conda-forge grblas`. This will also install the SuiteSparse `graphblas` compiled C library.
1313

14-
Currently works with SuiteSparse:GraphBLAS, but the goal is to make it work with all implementations of the GraphBLAS spec.
14+
Currently works with [SuiteSparse:GraphBLAS](https://github.com/DrTimothyAldenDavis/GraphBLAS), but the goal is to make it work with all implementations of the GraphBLAS spec.
1515

1616
The approach taken with this library is to follow the C-API specification as closely as possible while making improvements
1717
allowed with the Python syntax. Because the spec always passes in the output object to be written to, we follow the same,
@@ -86,11 +86,12 @@ s = A[row_index, col_index].value # extract single element
8686
```
8787
## Assign
8888
```python
89-
M[rows, cols](mask, accum) << A # rows and cols are a list or a slice
90-
M[rows, col_index](mask, accum) << v # assign column
91-
M[row_index, cols](mask, accum) << v # assign row
92-
M[rows, cols](mask, accum) << s # assign scalar to many elements
93-
M[row_index, col_index] << s # assign scalar to single element (mask and accum not allowed)
89+
M(mask, accum)[rows, cols] << A # rows and cols are a list or a slice
90+
M(mask, accum)[rows, col_index] << v # assign column
91+
M(mask, accum)[row_index, cols] << v # assign row
92+
M(mask, accum)[rows, cols] << s # assign scalar to many elements
93+
M[row_index, col_index] << s # assign scalar to single element
94+
# (mask and accum not allowed)
9495
del M[row_index, col_index] # remove single element
9596
```
9697
## Apply
@@ -113,7 +114,7 @@ B = A.dup() # dup
113114
A = Matrix.from_values([row_indices], [col_indices], [values]) # build
114115
```
115116
## New from delayed
116-
Delayed objects can be used to create a new object using `.new()` method instead of `<<` into an existing object
117+
Delayed objects can be used to create a new object using `.new()` method
117118
```python
118119
C = A.mxm(B, semiring).new()
119120
```
@@ -130,9 +131,9 @@ There is a mechanism to initialize `grblas` with a context prior to use. This al
130131
use as well as the blocking/non-blocking mode. If the context is not initialized, a default initialization will
131132
be performed automatically.
132133
```python
133-
import grblas
134+
import grblas as gb
134135
# Context initialization must happen before any other imports
135-
grblas.init('suitesparse', blocking=True)
136+
gb.init('suitesparse', blocking=True)
136137

137138
# Now we can import other items from grblas
138139
from grblas import binary, semiring
@@ -161,15 +162,22 @@ Similar methods exist for BinaryOp, Monoid, and Semiring.
161162

162163
## Import/Export connectors to the Python ecosystem
163164
`grblas.io` contains functions for converting to and from:
164-
- numpy arrays and matrices
165-
- `from_numpy(m)` (_1-D array becomes Vector, 2-D array or matrix becomes Matrix_)
166-
- `to_numpy(g, format='array')`
167-
- scipy.sparse matrices
168-
- `from_scipy_sparse_matrix(m)`
169-
- `to_scipy_sparse_matrix(m, format='csr')`
170-
- networkx graphs
171-
- `from_networkx(g)`
172-
- `to_networkx(g)`
165+
```python
166+
import grblas as gb
167+
168+
# numpy arrays
169+
# 1-D array becomes Vector, 2-D array becomes Matrix
170+
A = gb.io.from_numpy(m)
171+
m = gb.io.to_numpy(A)
172+
173+
# scipy.sparse matrices
174+
A = gb.io.from_scipy_sparse_matrix(m)
175+
m = gb.io.to_scipy_sparse_matrix(m, format='csr')
176+
177+
# networkx graphs
178+
A = gb.io.from_networkx(g)
179+
g = gb.io.to_networkx(A)
180+
```
173181

174182
## Attribution
175183
This library borrows some great ideas from [pygraphblas](https://github.com/michelp/pygraphblas),

0 commit comments

Comments
 (0)