spla
Loading...
Searching...
No Matches
cpu_formats.hpp
Go to the documentation of this file.
1/**********************************************************************************/
2/* This file is part of spla project */
3/* https://github.com/SparseLinearAlgebra/spla */
4/**********************************************************************************/
5/* MIT License */
6/* */
7/* Copyright (c) 2023 SparseLinearAlgebra */
8/* */
9/* Permission is hereby granted, free of charge, to any person obtaining a copy */
10/* of this software and associated documentation files (the "Software"), to deal */
11/* in the Software without restriction, including without limitation the rights */
12/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13/* copies of the Software, and to permit persons to whom the Software is */
14/* furnished to do so, subject to the following conditions: */
15/* */
16/* The above copyright notice and this permission notice shall be included in all */
17/* copies or substantial portions of the Software. */
18/* */
19/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25/* SOFTWARE. */
26/**********************************************************************************/
27
28#ifndef SPLA_CPU_FORMATS_HPP
29#define SPLA_CPU_FORMATS_HPP
30
31#include <spla/config.hpp>
32
33#include <core/tdecoration.hpp>
34#include <util/pair_hash.hpp>
35
36#include <robin_hood.hpp>
37
38#include <algorithm>
39#include <cassert>
40#include <functional>
41#include <numeric>
42#include <string>
43#include <unordered_map>
44#include <utility>
45#include <vector>
46
47namespace spla {
48
54 template<typename T>
55 class CpuDokVec : public TDecoration<T> {
56 public:
58
59 ~CpuDokVec() override = default;
60
61 using Reduce = std::function<T(T accum, T added)>;
62
63 robin_hood::unordered_flat_map<uint, T> Ax{};
64 Reduce reduce = [](T, T a) { return a; };
65 };
66
73 template<typename T>
74 class CpuDenseVec : public TDecoration<T> {
75 public:
77
78 ~CpuDenseVec() override = default;
79
80 std::vector<T> Ax{};
81 };
82
89 template<typename T>
90 class CpuCooVec : public TDecoration<T> {
91 public:
93
94 ~CpuCooVec() override = default;
95
96 std::vector<uint> Ai;
97 std::vector<T> Ax;
98 };
99
106 template<typename T>
107 class CpuLil : public TDecoration<T> {
108 public:
110
111 ~CpuLil() override = default;
112
113 using Entry = std::pair<uint, T>;
114 using Row = std::vector<Entry>;
115 using Reduce = std::function<T(T accum, T added)>;
116
117 std::vector<Row> Ar{};
118 Reduce reduce = [](T, T a) { return a; };
119 };
120
127 template<typename T>
128 class CpuDok : public TDecoration<T> {
129 public:
131
132 ~CpuDok() override = default;
133
134 using Key = std::pair<uint, uint>;
135 using Reduce = std::function<T(T accum, T added)>;
136
137 robin_hood::unordered_flat_map<Key, T, pair_hash> Ax;
138 Reduce reduce = [](T, T a) { return a; };
139 };
140
147 template<typename T>
148 class CpuCoo : public TDecoration<T> {
149 public:
151
152 ~CpuCoo() override = default;
153
154 std::vector<uint> Ai;
155 std::vector<uint> Aj;
156 std::vector<T> Ax;
157 };
158
165 template<typename T>
166 class CpuCsr : public TDecoration<T> {
167 public:
169
170 ~CpuCsr() override = default;
171
172 std::vector<uint> Ap;
173 std::vector<uint> Aj;
174 std::vector<T> Ax;
175 };
176
181}// namespace spla
182
183#endif//SPLA_CPU_FORMATS_HPP
Named storage format for library matrix data objects.
Named storage format for library vector data objects.
CPU list-of-coordinates sparse vector representation.
Definition cpu_formats.hpp:90
~CpuCooVec() override=default
static constexpr FormatVector FORMAT
Definition cpu_formats.hpp:92
std::vector< uint > Ai
Definition cpu_formats.hpp:96
std::vector< T > Ax
Definition cpu_formats.hpp:97
CPU list of coordinates matrix format.
Definition cpu_formats.hpp:148
std::vector< uint > Aj
Definition cpu_formats.hpp:155
~CpuCoo() override=default
std::vector< T > Ax
Definition cpu_formats.hpp:156
std::vector< uint > Ai
Definition cpu_formats.hpp:154
static constexpr FormatMatrix FORMAT
Definition cpu_formats.hpp:150
CPU compressed sparse row matrix format.
Definition cpu_formats.hpp:166
std::vector< uint > Ap
Definition cpu_formats.hpp:172
std::vector< uint > Aj
Definition cpu_formats.hpp:173
static constexpr FormatMatrix FORMAT
Definition cpu_formats.hpp:168
std::vector< T > Ax
Definition cpu_formats.hpp:174
~CpuCsr() override=default
CPU one-dim array for dense vector representation.
Definition cpu_formats.hpp:74
~CpuDenseVec() override=default
static constexpr FormatVector FORMAT
Definition cpu_formats.hpp:76
std::vector< T > Ax
Definition cpu_formats.hpp:80
Definition cpu_formats.hpp:55
static constexpr FormatVector FORMAT
Definition cpu_formats.hpp:57
robin_hood::unordered_flat_map< uint, T > Ax
Definition cpu_formats.hpp:63
~CpuDokVec() override=default
std::function< T(T accum, T added)> Reduce
Definition cpu_formats.hpp:61
Reduce reduce
Definition cpu_formats.hpp:64
Dictionary of keys sparse matrix format.
Definition cpu_formats.hpp:128
std::function< T(T accum, T added)> Reduce
Definition cpu_formats.hpp:135
robin_hood::unordered_flat_map< Key, T, pair_hash > Ax
Definition cpu_formats.hpp:137
~CpuDok() override=default
Reduce reduce
Definition cpu_formats.hpp:138
std::pair< uint, uint > Key
Definition cpu_formats.hpp:134
static constexpr FormatMatrix FORMAT
Definition cpu_formats.hpp:130
CPU list-of-list matrix format for fast incremental build.
Definition cpu_formats.hpp:107
static constexpr FormatMatrix FORMAT
Definition cpu_formats.hpp:109
std::vector< Entry > Row
Definition cpu_formats.hpp:114
std::function< T(T accum, T added)> Reduce
Definition cpu_formats.hpp:115
std::pair< uint, T > Entry
Definition cpu_formats.hpp:113
~CpuLil() override=default
std::vector< Row > Ar
Definition cpu_formats.hpp:117
Reduce reduce
Definition cpu_formats.hpp:118
Base class for typed decoration for storage object.
Definition tdecoration.hpp:50
Definition algorithm.hpp:37