spla
cpu_format_dense_vec.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_FORMAT_DENSE_VEC_HPP
29 #define SPLA_CPU_FORMAT_DENSE_VEC_HPP
30 
31 #include <cpu/cpu_formats.hpp>
32 
33 namespace spla {
34 
40  template<typename T>
41  void cpu_dense_vec_resize(const uint n_rows,
42  CpuDenseVec<T>& vec) {
43  vec.Ax.resize(n_rows);
44  vec.values = n_rows;
45  }
46 
47  template<typename T>
48  void cpu_dense_vec_fill(const T fill_value,
49  CpuDenseVec<T>& vec) {
50  std::fill(vec.Ax.begin(), vec.Ax.end(), fill_value);
51  }
52 
53  template<typename T>
54  void cpu_dense_vec_to_dok(const uint n_rows,
55  const T fill_value,
56  const CpuDenseVec<T>& in,
57  CpuDokVec<T>& out) {
58  assert(out.values == 0);
59  assert(out.Ax.empty());
60 
61  for (uint i = 0; i < n_rows; ++i) {
62  if (in.Ax[i] != fill_value) {
63  out.Ax[i] = in.Ax[i];
64  out.values += 1;
65  }
66  }
67  }
68 
73 }// namespace spla
74 
75 #endif//SPLA_CPU_FORMAT_DENSE_VEC_HPP
CPU one-dim array for dense vector representation.
Definition: cpu_formats.hpp:74
std::vector< T > Ax
Definition: cpu_formats.hpp:80
Definition: cpu_formats.hpp:55
robin_hood::unordered_flat_map< uint, T > Ax
Definition: cpu_formats.hpp:63
uint values
Definition: tdecoration.hpp:58
void cpu_dense_vec_fill(const T fill_value, CpuDenseVec< T > &vec)
Definition: cpu_format_dense_vec.hpp:48
void cpu_dense_vec_resize(const uint n_rows, CpuDenseVec< T > &vec)
Definition: cpu_format_dense_vec.hpp:41
void cpu_dense_vec_to_dok(const uint n_rows, const T fill_value, const CpuDenseVec< T > &in, CpuDokVec< T > &out)
Definition: cpu_format_dense_vec.hpp:54
std::uint32_t uint
Library index and size type.
Definition: config.hpp:56
Definition: algorithm.hpp:37