Skip to content

Commit d9e36ac

Browse files
committed
[Python/Project] Add example && update readme info
1 parent 98702f0 commit d9e36ac

File tree

4 files changed

+73
-23
lines changed

4 files changed

+73
-23
lines changed

README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ The library provides C-compatible API, written in the GraphBLAS style.
1818
cuBool library C API. This package exports library features and primitives
1919
in high-level format with automated resources management and fancy syntax sugar.
2020

21-
**The primary library primitive** is a sparse boolean matrix. The library provides
22-
the most popular operations for matrix manipulation, such as construction from
23-
values, transpose, sub-matrix extraction, matrix-to-vector reduce, matrix-matrix
24-
element-wise addition, matrix-matrix multiplication and Kronecker product.
21+
**The primary library primitives** are sparse matrix and sparse vector of boolean values.
22+
The library provides the most popular operations for matrix manipulation,
23+
such as construction from values, transpose, sub-matrix/sub-vector extraction, matrix-to-vector reduce,
24+
element-wise addition, matrix-matrix, matrix-vector, vector-matrix multiplication, and Kronecker product.
2525

2626
**As a fallback** library provides sequential backend for mentioned above operations
2727
for computations on CPU side only. This backend is selected automatically
2828
if Cuda compatible device is not presented in the system. This can be quite handy for
29-
prototyping algorithms on a local computer for later running on a powerful server.
29+
prototyping algorithms on a local computer for later running on a powerful server.
3030

3131
**PyPI package web page** is following [link](https://pypi.org/project/pycubool/).
3232

@@ -36,20 +36,23 @@ prototyping algorithms on a local computer for later running on a powerful serve
3636
- Python package for every-day tasks
3737
- Cuda backend for computations
3838
- Cpu backend for computations
39-
- Matrix creation (empty, from data, with random data)
39+
- Matrix/vector creation (empty, from data, with random data)
4040
- Matrix-matrix operations (multiplication, element-wise addition, kronecker product)
41+
- Matrix-vector operations (matrix-vector and vector-matrix multiplication)
42+
- Vector-vector operations (element-wise addition)
4143
- Matrix operations (equality, transpose, reduce to vector, extract sub-matrix)
42-
- Matrix data extraction (as lists, as list of pairs)
43-
- Matrix syntax sugar (pretty string printing, slicing, iterating through non-zero values)
44+
- Vector operations (equality, reduce to value, extract sub-vector)
45+
- Matrix/vector data extraction (as lists, as list of pairs)
46+
- Matrix/vector syntax sugar (pretty string printing, slicing, iterating through non-zero values)
4447
- IO (import/export matrix from/to `.mtx` file format)
4548
- GraphViz (export single matrix or set of matrices as a graph with custom color and label settings)
46-
- Debug (matrix string debug markers, logging)
49+
- Debug (matrix string debug markers, logging)
4750

4851
### Platforms
4952

5053
- Linux based OS (tested on Ubuntu 20.04)
51-
- Windows (coming soon)
52-
- macOS (coming soon)
54+
- Windows (not tested yet)
55+
- macOS (not tested yet)
5356

5457
### Simple example
5558

python/README.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,35 @@ The library provides C-compatible API, written in the GraphBLAS style.
1919
cuBool library C API. This package exports library features and primitives
2020
in high-level format with automated resources management and fancy syntax sugar.
2121

22-
**The primary library primitive** is a sparse boolean matrix. The library provides
23-
the most popular operations for matrix manipulation, such as construction from
24-
values, transpose, sub-matrix extraction, matrix-to-vector reduce, matrix-matrix
25-
element-wise addition, matrix-matrix multiplication and Kronecker product.
22+
**The primary library primitives** are sparse matrix and sparse vector of boolean values.
23+
The library provides the most popular operations for matrix manipulation,
24+
such as construction from values, transpose, sub-matrix/sub-vector extraction, matrix-to-vector reduce,
25+
element-wise addition, matrix-matrix, matrix-vector, vector-matrix multiplication, and Kronecker product.
2626

2727
**As a fallback** library provides sequential backend for mentioned above operations
2828
for computations on CPU side only. This backend is selected automatically
2929
if Cuda compatible device is not presented in the system. This can be quite handy for
3030
prototyping algorithms on a local computer for later running on a powerful server.
3131

32-
## Features
32+
### Features
3333

3434
- C API for performance-critical computations
3535
- Python package for every-day tasks
3636
- Cuda backend for computations
3737
- Cpu backend for computations
38-
- Matrix creation (empty, from data, with random data)
38+
- Matrix/vector creation (empty, from data, with random data)
3939
- Matrix-matrix operations (multiplication, element-wise addition, kronecker product)
40+
- Matrix-vector operations (matrix-vector and vector-matrix multiplication)
41+
- Vector-vector operations (element-wise addition)
4042
- Matrix operations (equality, transpose, reduce to vector, extract sub-matrix)
41-
- Matrix data extraction (as lists, as list of pairs)
42-
- Matrix syntax sugar (pretty string printing, slicing, iterating through non-zero values)
43+
- Vector operations (equality, reduce to value, extract sub-vector)
44+
- Matrix/vector data extraction (as lists, as list of pairs)
45+
- Matrix/vector syntax sugar (pretty string printing, slicing, iterating through non-zero values)
4346
- IO (import/export matrix from/to `.mtx` file format)
4447
- GraphViz (export single matrix or set of matrices as a graph with custom color and label settings)
4548
- Debug (matrix string debug markers, logging)
4649

47-
## Simple example
50+
### Simple example
4851

4952
Create sparse matrices, compute matrix-matrix product and print the result to the output:
5053

@@ -64,7 +67,31 @@ b[2, 1] = True
6467
print(a, b, a.mxm(b), sep="\n")
6568
```
6669

67-
## Transitive closure example
70+
### Vector example
71+
72+
Create sparse matrix and vector, compute matrix-vector and vector-matrix products and print the result:
73+
74+
```python
75+
import pycubool as cb
76+
77+
m = cb.Matrix.empty(shape=(3, 4))
78+
m[0, 1] = True
79+
m[1, 0] = True
80+
m[1, 3] = True
81+
m[2, 2] = True
82+
83+
v = cb.Vector.empty(nrows=4)
84+
v[0] = True
85+
v[2] = True
86+
87+
t = cb.Vector.empty(nrows=3)
88+
t[0] = True
89+
t[2] = True
90+
91+
print(m.mxv(v), t.vxm(m), sep="\n")
92+
```
93+
94+
### Transitive closure example
6895

6996
Compute the transitive closure problem for the directed graph and print the result:
7097

@@ -88,7 +115,7 @@ while total != t.nvals:
88115
print(a, t, sep="\n")
89116
```
90117

91-
## GraphViz example
118+
### GraphViz example
92119

93120
Generate GraphViz graph script for a graph stored as a set of adjacency matrices:
94121

python/examples/basic.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@
1616

1717
print(a, b, a.mxm(b), sep="\n")
1818

19+
#
20+
# Vector example
21+
#
22+
23+
m = cb.Matrix.empty(shape=(3, 4))
24+
m[0, 1] = True
25+
m[1, 0] = True
26+
m[1, 3] = True
27+
m[2, 2] = True
28+
29+
v = cb.Vector.empty(nrows=4)
30+
v[0] = True
31+
v[2] = True
32+
33+
t = cb.Vector.empty(nrows=3)
34+
t[0] = True
35+
t[2] = True
36+
37+
print(m.mxv(v), t.vxm(m), sep="\n")
38+
1939
#
2040
# Transitive closure example
2141
#

python/features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,4 @@ def gen_matrix(size, seed):
197197
vector[0] = True
198198
vector[2] = True
199199
vector[3] = True
200-
print(vector)
200+
print(vector)

0 commit comments

Comments
 (0)