spla
io.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_IO_HPP
29 #define SPLA_IO_HPP
30 
31 #include "config.hpp"
32 
33 #include <filesystem>
34 #include <vector>
35 
36 namespace spla {
37 
47  class MtxLoader {
48  public:
49  SPLA_API explicit MtxLoader(std::string name = "");
50  SPLA_API ~MtxLoader() = default;
51 
62  SPLA_API bool load(std::filesystem::path file_path,
63  bool offset_indices = true,
64  bool make_undirected = true,
65  bool remove_loops = true);
66 
75  SPLA_API bool save(const std::filesystem::path& file_path,
76  bool stats_only = false);
77 
78  SPLA_API void calc_stats();
79  SPLA_API void output_stats();
80 
81  [[nodiscard]] SPLA_API const std::vector<uint>& get_Ai() const;
82  [[nodiscard]] SPLA_API const std::vector<uint>& get_Aj() const;
83  [[nodiscard]] SPLA_API uint get_n_rows() const;
84  [[nodiscard]] SPLA_API uint get_n_cols() const;
85  [[nodiscard]] SPLA_API std::size_t get_n_values() const;
86 
87  private:
88  std::string m_name;
89  std::filesystem::path m_file_path;
90  std::vector<uint> m_Ai;
91  std::vector<uint> m_Aj;
92  bool m_base_is_zero = false;
93  uint m_n_rows = 0;
94  uint m_n_cols = 0;
95  std::size_t m_n_values = 0;
96  double m_deg_avg = -1.0;
97  double m_deg_sd = -1.0;
98  double m_deg_min = -1.0;
99  double m_deg_max = -1.0;
100  std::vector<double> m_deg_distribution;
101  std::vector<uint> m_deg_ranges;
102  };
103 
108 }// namespace spla
109 
110 #endif//SPLA_IO_HPP
Loader for matrix data stored in matrix-market (.mtx) format.
Definition: io.hpp:47
uint get_n_rows() const
Definition: io.cpp:371
void calc_stats()
Definition: io.cpp:273
~MtxLoader()=default
const std::vector< uint > & get_Aj() const
Definition: io.cpp:367
const std::vector< uint > & get_Ai() const
Definition: io.cpp:364
void output_stats()
Definition: io.cpp:335
bool load(std::filesystem::path file_path, bool offset_indices=true, bool make_undirected=true, bool remove_loops=true)
Load .mtx data from given file path.
Definition: io.cpp:50
bool save(const std::filesystem::path &file_path, bool stats_only=false)
Saves loaded data at file.
Definition: io.cpp:235
std::size_t get_n_values() const
Definition: io.cpp:377
MtxLoader(std::string name="")
Definition: io.cpp:47
uint get_n_cols() const
Definition: io.cpp:374
#define SPLA_API
Definition: config.hpp:43
std::uint32_t uint
Library index and size type.
Definition: config.hpp:56
Definition: algorithm.hpp:37