33#ifndef GKO_PUBLIC_CORE_BASE_MATRIX_ASSEMBLY_DATA_HPP_
34#define GKO_PUBLIC_CORE_BASE_MATRIX_ASSEMBLY_DATA_HPP_
41#include <unordered_map>
44#include <ginkgo/core/base/dim.hpp>
45#include <ginkgo/core/base/math.hpp>
46#include <ginkgo/core/base/matrix_data.hpp>
47#include <ginkgo/core/base/types.hpp>
48#include <ginkgo/core/base/utils.hpp>
55template <
typename IndexType>
56struct symbolic_nonzero_hash {
57 symbolic_nonzero_hash() =
default;
63 std::size_t operator()(std::pair<IndexType, IndexType>
nnz)
const noexcept
65 return static_cast<std::size_t
>(
nnz.first) * num_cols_ +
nnz.second;
87template <
typename ValueType = default_precision,
typename IndexType =
int32>
90 using value_type = ValueType;
91 using index_type = IndexType;
95 nonzeros_(0, detail::symbolic_nonzero_hash<index_type>(size_[1]))
107 void add_value(index_type row, index_type col, value_type val)
109 auto ind = std::make_pair(row, col);
110 nonzeros_[
ind] += val;
121 void set_value(index_type row, index_type col, value_type val)
123 auto ind = std::make_pair(row, col);
124 nonzeros_[
ind] = val;
136 const auto it = nonzeros_.find(std::make_pair(row, col));
137 if (
it == nonzeros_.end()) {
153 return nonzeros_.find(std::make_pair(row, col)) != nonzeros_.end();
162 return nonzeros_.size();
172 using nonzero_type =
typename output_type::nonzero_type;
174 std::pair<std::pair<index_type, index_type>, value_type>;
176 data.nonzeros.reserve(nonzeros_.size());
177 std::transform(nonzeros_.begin(), nonzeros_.end(),
179 return nonzero_type{entry.first.first,
183 data.ensure_row_major_order();
200 std::unordered_map<std::pair<index_type, index_type>, value_type,
201 detail::symbolic_nonzero_hash<index_type>>
This structure is used as an intermediate type to assemble a sparse matrix.
Definition matrix_assembly_data.hpp:88
void add_value(index_type row, index_type col, value_type val)
Sets the matrix value at (row, col).
Definition matrix_assembly_data.hpp:107
void set_value(index_type row, index_type col, value_type val)
Sets the matrix value at (row, col).
Definition matrix_assembly_data.hpp:121
size_type get_num_stored_elements() const noexcept
Definition matrix_assembly_data.hpp:160
bool contains(index_type row, index_type col)
Returns true iff the matrix contains an entry at (row, col).
Definition matrix_assembly_data.hpp:151
value_type get_value(index_type row, index_type col)
Gets the matrix value at (row, col).
Definition matrix_assembly_data.hpp:134
dim< 2 > get_size() const noexcept
Definition matrix_assembly_data.hpp:157
matrix_data< ValueType, IndexType > get_ordered_data() const
Definition matrix_assembly_data.hpp:169
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:55
This structure is used as an intermediate data type to store a sparse matrix.
Definition matrix_data.hpp:155