|
1 | | -# Python Directory |
| 1 | +# pycubool |
2 | 2 |
|
3 | | -This directory is intended to store python wrappers and other |
4 | | -python utilities, required for using `cubool` library within |
5 | | -testing infrastructure and etc. |
| 3 | +[](https://research.jetbrains.org/) |
| 4 | +[](https://github.com/JetBrains-Research/cuBool/actions) |
| 5 | +[](https://github.com/JetBrains-Research/cuBool/blob/master/LICENSE) |
6 | 6 |
|
7 | | -## Structure |
| 7 | +`pycubool` is a python wrapper for [cuBool](https://github.com/JetBrains-Research/cuBool) library. |
| 8 | + |
| 9 | +**cuBool** is a linear Boolean algebra library primitives and operations for |
| 10 | +work with sparse matrices written on the NVIDIA CUDA platform. The primary |
| 11 | +goal of the library is implementation, testing and profiling algorithms for |
| 12 | +solving *formal-language-constrained problems*, such as *context-free* |
| 13 | +and *regular* path queries with various semantics for graph databases. |
| 14 | +The library provides C-compatible API, written in the GraphBLAS style, |
| 15 | +as well as python high-level wrapper with automated resources management and fancy syntax sugar. |
| 16 | + |
| 17 | +**The primary library primitive** is a sparse boolean matrix. The library provides |
| 18 | +the most popular operations for matrix manipulation, such as construction from |
| 19 | +values, transpose, sub-matrix extraction, matrix-to-vector reduce, matrix-matrix |
| 20 | +element-wise addition, matrix-matrix multiplication and Kronecker product. |
| 21 | + |
| 22 | +**As a fallback** library provides sequential backend for mentioned above operations |
| 23 | +for computations on CPU side only. This backend is selected automatically |
| 24 | +if Cuda compatible device is not presented in the system. This can be quite handy for |
| 25 | +prototyping algorithms on a local computer for later running on a powerful server. |
| 26 | + |
| 27 | +## Example |
| 28 | + |
| 29 | +The following Python code snippet demonstrates, how the `pycubool` |
| 30 | +wrapper can be used to compute the transitive closure problem for the |
| 31 | +directed graph within python environment: |
| 32 | + |
| 33 | +```python |
| 34 | +import pycubool |
| 35 | + |
| 36 | +def transitive_closure(a: pycubool.Matrix): |
| 37 | + """ |
| 38 | + Evaluates transitive closure for the provided |
| 39 | + adjacency matrix of the graph. |
| 40 | +
|
| 41 | + :param a: Adjacency matrix of the graph |
| 42 | + :return: The transitive closure adjacency matrix |
| 43 | + """ |
| 44 | + |
| 45 | + t = a.dup() # Duplicate matrix where to store result |
| 46 | + total = 0 # Current number of values |
| 47 | + |
| 48 | + while total != t.nvals: |
| 49 | + total = t.nvals |
| 50 | + t.mxm(t, out=t, accumulate=True) # t += t * t |
| 51 | + |
| 52 | + return t |
| 53 | +``` |
| 54 | + |
| 55 | +## Directory structure |
| 56 | + |
| 57 | +``` |
| 58 | +pycubool |
| 59 | +├── docs - documents, text files and various helpful stuff |
| 60 | +├── demo - examples and basic programs |
| 61 | +├── pycubool - package with `cuBool` C API wrapper |
| 62 | +└── tests - tests for python wrapper |
| 63 | +``` |
| 64 | + |
| 65 | +## License |
| 66 | + |
| 67 | +This project is licensed under MIT License. License text can be found in the |
| 68 | +[license file](https://github.com/JetBrains-Research/cuBool/blob/master/python/LICENSE.md). |
8 | 69 |
|
9 | | -- `pycubool` - python wrapper for the `cubool c api` |
10 | | -- `tests` - unit tests for pycubool wrapper |
|
0 commit comments