Welcome to RGRI’s documentation!

Index

GraphBLAS Objects

template<typename T, std::integral I = std::size_t, typename Hint = grb::sparse, typename Allocator = std::allocator<T>>
class matrix

A GraphBLAS matrix object.

  1. Template parameter T specifies the type of values stored in the matrix.

  2. I is an integer type used to record the indices of stored elements.

  3. Hint is a hint as to what backend data structure should be used to store the matrix elements, and can be either grb::sparse or grb::dense.

  4. Allocator is the C++ allocator used to allocate memory.

Public Types

using scalar_type = T

Type of scalar elements stored in the matrix.

using index_type = I

Type used to reference the indices of elements stored in the matrix.

using value_type = matrix_entry<T, I>

A tuple-like type containing:

  1. A tuple-like type with two index_type elements storing the row and column index of the element.

  2. An element of type scalar_type.

using allocator_type = Allocator

Allocator type.

using size_type = std::size_t

A large unsigned integral type.

using difference_type = std::ptrdiff_t

A large signed integral type.

Public Functions

inline matrix(grb::index<I> shape)

Construct an empty matrix of dimension shape[0] x shape[1]

inline matrix(std::string file_path)

Construct a matrix from the Matrix Market file stored at location file_path.

inline grb::index<I> shape() const noexcept

Dimensions of the matrix.

inline size_type size() const noexcept

Number of stored values in the matrix.

inline iterator begin() noexcept

Iterator to the beginning.

inline const_iterator begin() const noexcept

Const iterator to the beginning.

inline iterator end() noexcept

Iterator to the end.

inline const_iterator end() const noexcept

Const iterator to the end.

template<typename InputIt>
inline void insert(InputIt first, InputIt last)

Insert elements in the range [first, last).

inline std::pair<iterator, bool> insert(const value_type &value)

Insert the matrix_entry value into the matrix. If no element is already present at the index, insert the element and return a pair containing an iterator to the newly inserted element and the boolean value true. If an element already exists at the index, return a pair containing an iterator to the element that prevented inserting, along with the boolean value false.

inline void reshape(grb::index<I> shape)

Reshape the matrix dimensions to be shape[0] x shape[1]. Any elements outside the new shape will be deleted.

template<typename T, std::integral I = std::size_t, typename Hint = grb::dense, typename Allocator = std::allocator<T>>
class vector

Public Types

using scalar_type = T

Type of scalar values stored in the matrix.

using index_type = I

Type used to store indices.

using allocator_type = Allocator

Allocator type.

Public Functions

inline I shape() const noexcept

Shape of the vector.

inline size_type size() const noexcept

Number of values stored in the vector.

inline iterator begin() noexcept

Iterator to the beginning.

inline iterator end() noexcept

Iterator to the end.

inline const_iterator begin() const noexcept

Const iterator to the beginning.

inline const_iterator end() const noexcept

Const iterator to the end.

Example

#include <iostream>
#include <grb/grb.hpp>
int main(int argc, char** argv) {
  // Create a new matrix, reading in from a file.
  grb::matrix<float, int> a("data/chesapeake.mtx");

  size_t m = a.shape()[0];
  size_t k = a.shape()[1];

  std::cout << "chesapeake.mtx is a " << m << " by " << k << " matrix." << std::endl;

  // Set element 12,9 (row 12, column 9) to 12.
  a[{12, 9}] = 12;

  grb::matrix<float, int> b("data/chesapeake.mtx");

  auto c = grb::multiply(a, b);

  std::cout << "Sum of elements is " << grb::sum(c) << std::endl;

  return 0;
}

Binary Operators

Binary operators are function objects that implement binary operators, that is operators that accept two inputs and produce a single output. A collection of binary operators are pre-defined by GraphBLAS.

template<typename T = void, typename U = T, typename V = void>
struct plus : public grb::binary_op_impl_<plus_impl_, T, U, V>

The binary operator grb::plus, which forms a monoid on integral types.

template<typename T = void, typename U = T, typename V = void>
struct minus : public grb::binary_op_impl_<minus_impl_, T, U, V>
template<typename T = void, typename U = T, typename V = void>
struct multiplies : public grb::binary_op_impl_<multiplies_impl_, T, U, V>

Subclassed by grb::times< T, U, V >

template<typename T = void, typename U = T, typename V = void>
struct times : public grb::multiplies<T, U, V>
template<typename T = void, typename U = T, typename V = void>
struct max : public grb::binary_op_impl_<max_impl_, T, U, V>
template<typename T = void, typename U = T, typename V = void>
struct min : public grb::binary_op_impl_<min_impl_, T, U, V>
template<typename T = void, typename U = T, typename V = void>
struct modulus : public grb::binary_op_impl_<modulus_impl_, T, U, V>

Monoid Traits

template<typename Fn, typename T>
class grb::monoid_traits
static constexpr T identity()
template<typename Fn, typename T>
using grb::monoid_traits_v = typename grb::monoid_traits::value

Identity of the

Algorithms

template<MatrixRange A, VectorRange B, BinaryOperator<grb::matrix_scalar_t<A>, grb::vector_scalar_t<B>> Combine = grb::multiplies<>, BinaryOperator<grb::elementwise_return_type_t<A, B, Combine>, grb::elementwise_return_type_t<A, B, Combine>, grb::elementwise_return_type_t<A, B, Combine>> Reduce = grb::plus<>, MaskVectorRange M = grb::full_vector_mask<>>
auto grb::multiply(A &&a, B &&b, Reduce &&reduce = Reduce{}, Combine &&combine = Combine(), M &&mask = M{})

Multiply a matrix times a vector.

Multiply two matrices.

Warning

doxygenfunction: Cannot find function “grb::dot” in doxygen xml output for project “RGRI” from directory: build/xml

template<typename MatrixType>
auto grb::sum(const MatrixType &matrix)

Compute the sum of all elements in the matrix matrix, using the conventional + operator.

template<MatrixRange A, MatrixRange B, BinaryOperator<grb::matrix_scalar_t<A>, grb::matrix_scalar_t<B>> Combine, MaskMatrixRange M = grb::full_matrix_mask<>>
auto grb::ewise_union(A &&a, B &&b, Combine &&combine, M &&mask = M{})
template<MatrixRange A, MatrixRange B, BinaryOperator<grb::matrix_scalar_t<A>, grb::matrix_scalar_t<B>> Combine, MaskMatrixRange M = grb::full_matrix_mask<>>
auto grb::ewise_intersection(A &&a, B &&b, Combine &&combine, M &&mask = M{})

Utility Functions

template<grb::MatrixRange M>
void grb::print(M &&matrix, std::string label = "")

Print the GraphBLAS matrix range matrix to standard output, optionally printing the string label.

template<grb::VectorRange V>
void grb::print(V &&vector, std::string label = "")

Print the GraphBLAS vector object vector to standard output, optionally adding the string label.