Welcome to RGRI’s documentation!
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.
Template parameter
T
specifies the type of values stored in the matrix.I
is an integer type used to record the indices of stored elements.Hint
is a hint as to what backend data structure should be used to store the matrix elements, and can be eithergrb::sparse
orgrb::dense
.Allocator
is the C++ allocator used to allocate memory.
Public Types
-
using value_type = matrix_entry<T, I>
A tuple-like type containing:
A tuple-like type with two
index_type
elements storing the row and column index of the element.An element of type
scalar_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(std::string file_path)
Construct a matrix from the Matrix Market file stored at location
file_path
.
-
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 valuetrue
. If an element already exists at the index, return a pair containing an iterator to the element that prevented inserting, along with the boolean valuefalse
.
-
template<typename T, std::integral I = std::size_t, typename Hint = grb::dense, typename Allocator = std::allocator<T>>
class vector Public Types
Public Functions
-
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.
-
inline size_type size() const noexcept
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>
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.