Debian Codegraph @

src/atlas/linalg/sparse/SparseMatrixView.h

raw
1 /*
2 * (C) Copyright 2024- ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include "eckit/linalg/types.h"
14
15 namespace atlas {
16 namespace linalg {
17
18 //----------------------------------------------------------------------------------------------------------------------
19
20 template <typename Value, typename Index=eckit::linalg::Index>
21 class SparseMatrixView {
22 public:
23 using value_type = Value;
24 using index_type = Index;
25 using size_type = std::size_t;
26
27 ~SparseMatrixView() = default;
28
29 SparseMatrixView() = default;
30
31 SparseMatrixView(
32 size_type rows,
33 size_type cols,
34 size_type nnz,
35 value_type const* value,
36 index_type const* inner,
37 index_type const* outer) :
38 rows_(rows), cols_(cols), nnz_(nnz), outer_(outer), inner_(inner), value_(value) {
39 }
40 SparseMatrixView(const SparseMatrixView& other) = default;
41
42 size_type rows() const { return rows_; }
43 size_type cols() const { return cols_; }
44 size_type nnz() const { return nnz_; }
45 size_type outer_size() const { return rows() + 1; }
46 size_type inner_size() const { return nnz(); }
47 size_type value_size() const { return nnz(); }
48 index_type const* outer() const { return outer_; }
49 index_type const* inner() const { return inner_; }
50 value_type const* value() const { return value_; }
51 bool empty() const { return nnz() == 0; }
52
53 private:
54 size_type rows_{0};
55 size_type cols_{0};
56 size_type nnz_{0};
57 index_type const* outer_{nullptr};
58 index_type const* inner_{nullptr};
59 value_type const* value_{nullptr};
60 };
61
62 //----------------------------------------------------------------------------------------------------------------------
63 } // namespace linalg
64 } // namespace atlas