Английская Википедия:GraphBLAS
Шаблон:Short description Шаблон:Orphan
Шаблон:Infobox technology standard
GraphBLAS (Шаблон:IPAc-en) is an API specification that defines standard building blocks for graph algorithms in the language of linear algebra.[1][2] GraphBLAS is built upon the notion that a sparse matrix can be used to represent graphs as either an adjacency matrix or an incidence matrix. The GraphBLAS specification describes how graph operations (e.g. traversing and transforming graphs) can be efficiently implemented via linear algebraic methods (e.g. matrix multiplication) over different semirings.[3]
The development of GraphBLAS and its various implementations is an ongoing community effort, including representatives from industry, academia, and government research labs.[4][5]
Background
Graph algorithms have long taken advantage of the idea that a graph can be represented as a matrix, and graph operations can be performed as linear transformations and other linear algebraic operations on sparse matrices.[6]Шаблон:Rp For example, matrix-vector multiplication can be used to perform a step in a breadth-first search.[6]Шаблон:Rp
The GraphBLAS specification (and the various libraries that implement it) provides data structures and functions to compute these linear algebraic operations. In particular, GraphBLAS specifies sparse matrix objects which map well to graphs where vertices are likely connected to relatively few neighbors (i.e. the degree of a vertex is significantly smaller than the total number of vertices in the graph). The specification also allows for the use of different semirings to accomplish operations in a variety of mathematical contexts.
Originally motivated by the need for standardization in graph analytics, similar to its namesake BLAS,[7] the GraphBLAS standard has also begun to interest people outside the graph community, including researchers in machine learning,[8] and bioinformatics.[9] GraphBLAS implementations have also been used in high-performance graph database applications such as RedisGraph.[10][11][12][13][14]
Specification
The GraphBLAS specification has been in development since 2013,[15] and has reached version 2.1.0 as of December 2023.[16] While formally a specification for the C programming language, a variety of programming languages have been used to develop implementations in the spirit of GraphBLAS, including C++,[17] Java,[18] and Nvidia CUDA.[19]
Compliant implementations and language bindings
There are currently two fully-compliant reference implementations of the GraphBLAS specification.[20][21] Bindings assuming a compliant specification exist for the Python,[22] MATLAB,[23] and Julia[24][25] programming languages.
Linear algebraic foundations
The mathematical foundations of GraphBLAS are based in linear algebra and the duality between matrices and graphs.[26][27]
Each graph operation in GraphBLAS operates on a semiring, which is made up of the following elements:
- A scalar addition operator (<math>\oplus</math>)
- A scalar multiplication operator (<math>\otimes</math>)
- A set (or domain)
Note that the zero element (i.e. the element that represents the absence of an edge in the graph) can also be reinterpreted.[26]Шаблон:Rp For example, the following algebras can be implemented in GraphBLAS:
Algebra | <math>\oplus</math> | <math>\otimes</math> | Domain | Zero Element |
---|---|---|---|---|
Standard arithmetic | <math>+</math> | <math>\times</math> | <math>\R</math> | 0 |
Max–plus algebra | <math>\max</math> | <math>+</math> | <math>\{-\infty\} \cup \R</math> | <math>-\infty</math> |
Min–plus algebra | <math>\min</math> | <math>+</math> | <math>\{+\infty\} \cup \R</math> | <math>+\infty</math> |
Max–min algebra | <math>\max</math> | <math>\min</math> | <math>[0, +\infty)</math> | 0 |
Min–max algebra | <math>\min</math> | <math>\max</math> | <math>(-\infty, 0]</math> | 0 |
Galois field | XOR | AND | <math>\{0,1\}</math> | 0 |
All the examples above satisfy the following two conditions in their respective domains:
- Additive identity, <math>a \oplus 0 = a</math>
- Multiplicative annihilation, <math>a \otimes 0 = 0</math>
For instance, a user can specify the min-plus algebra over the domain of double-precision floating point numbers with GrB_Semiring_new(&min_plus_semiring, GrB_MIN_FP64, GrB_PLUS_FP64)
.
Functionality
While the GraphBLAS specification generally allows significant flexibility in implementation, some functionality and implementation details are explicitly described:
- GraphBLAS objects, including matrices and vectors, are opaque data structures.[16]Шаблон:Rp
- Non-blocking execution mode, which permits lazy or asynchronous evaluation of certain operations.[16]Шаблон:Rp
- Masked assignment, denoted <math>A\langle M \rangle = B</math>, which assigns elements of matrix <math>B</math> to matrix <math>A</math> only in positions where the mask matrix <math>M</math> is non-zero.[16]Шаблон:Rp
The GraphBLAS specification also prescribes that library implementations be thread-safe.[16]Шаблон:Rp
Example code
The following is a GraphBLAS 2.1-compliant example of a breadth-first search in the C programming language.[16]Шаблон:Rp
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "GraphBLAS.h"
/*
* Given a boolean n x n adjacency matrix A and a source vertex s, performs a BFS traversal
* of the graph and sets v[i] to the level in which vertex i is visited (v[s] == 1).
* If i is not reachable from s, then v[i] = 0 does not have a stored element.
* Vector v should be uninitialized on input.
*/
GrB_Info BFS(GrB_Vector *v, GrB_Matrix A, GrB_Index s)
{
GrB_Index n;
GrB_Matrix_nrows(&n,A); // n = # of rows of A
GrB_Vector_new(v,GrB_INT32,n); // Vector<int32_t> v(n)
GrB_Vector q; // vertices visited in each level
GrB_Vector_new(&q, GrB_BOOL, n); // Vector<bool> q(n)
GrB_Vector_setElement(q, (bool)true, s); // q[s] = true, false everywhere else
/*
* BFS traversal and label the vertices.
*/
int32_t level = 0; // level = depth in BFS traversal
GrB_Index nvals;
do {
++level; // next level (start with 1)
GrB_apply(*v, GrB_NULL, GrB_PLUS_INT32,
GrB_SECOND_INT32, q, level, GrB_NULL); // v[q] = level
GrB_vxm(q, *v, GrB_NULL, GrB_LOR_LAND_SEMIRING_BOOL,
q, A, GrB_DESC_RC); // q[!v] = q ||.&& A; finds all the
// unvisited successors from current q
GrB_Vector_nvals(&nvals, q);
} while (nvals); // if there is no successor in q, we are done.
GrB_free(&q); // q vector no longer needed
return GrB_SUCCESS;
}
See also
References
External links
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ 6,0 6,1 Шаблон:Cite book
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite book
- ↑ Шаблон:Cite news
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite news
- ↑ Шаблон:Cite news
- ↑ Шаблон:Cite news
- ↑ Шаблон:Cite news
- ↑ Шаблон:Cite book
- ↑ 16,0 16,1 16,2 16,3 16,4 16,5 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ 26,0 26,1 Шаблон:Cite book
- ↑ For additional mathematical background, see Шаблон:Cite book