Ginkgo  Generated from tags/v1.0.0^0 branch based on master. Ginkgo version 1.0.0
A numerical linear algebra library targeting many-core architectures
mtx_io.hpp
1 /*******************************<GINKGO LICENSE>******************************
2 Copyright (c) 2017-2019, the Ginkgo authors
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 
16 3. Neither the name of the copyright holder nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 ******************************<GINKGO LICENSE>*******************************/
32 
33 #ifndef GKO_CORE_BASE_MTX_IO_HPP_
34 #define GKO_CORE_BASE_MTX_IO_HPP_
35 
36 
37 #include <istream>
38 
39 
40 #include <ginkgo/core/base/matrix_data.hpp>
41 
42 
43 namespace gko {
44 
45 
60 template <typename ValueType = default_precision, typename IndexType = int32>
61 matrix_data<ValueType, IndexType> read_raw(std::istream &is);
62 
63 
67 enum class layout_type {
71  array,
76 };
77 
78 
93 template <typename ValueType, typename IndexType>
94 void write_raw(std::ostream &os, const matrix_data<ValueType, IndexType> &data,
96 
97 
112 template <typename MatrixType, typename StreamType, typename... MatrixArgs>
113 inline std::unique_ptr<MatrixType> read(StreamType &&is, MatrixArgs &&... args)
114 {
115  auto mtx = MatrixType::create(std::forward<MatrixArgs>(args)...);
116  mtx->read(read_raw<typename MatrixType::value_type,
117  typename MatrixType::index_type>(is));
118  return mtx;
119 }
120 
121 
133 template <typename MatrixType, typename StreamType>
134 inline void write(StreamType &&os, MatrixType *matrix,
136 {
137  matrix_data<typename MatrixType::value_type,
138  typename MatrixType::index_type>
139  data{};
140  matrix->write(data);
141  write_raw(os, data, layout);
142 }
143 
144 
145 } // namespace gko
146 
147 
148 #endif // GKO_CORE_BASE_MTX_IO_HPP_
The matrix should be written as dense matrix in column-major order.
void write(StreamType &&os, MatrixType *matrix, layout_type layout=layout_type::array)
Reads a matrix stored in matrix market format from an input stream.
Definition: mtx_io.hpp:134
layout_type
Specifies the layout type when writing data in matrix market format.
Definition: mtx_io.hpp:67
The Ginkgo namespace.
Definition: abstract_factory.hpp:45
The matrix should be written as a sparse matrix in coordinate format.
void write_raw(std::ostream &os, const matrix_data< ValueType, IndexType > &data, layout_type layout=layout_type::array)
Writes a matrix_data structure to a stream in matrix market format.
std::unique_ptr< MatrixType > read(StreamType &&is, MatrixArgs &&... args)
Reads a matrix stored in matrix market format from an input stream.
Definition: mtx_io.hpp:113
matrix_data< ValueType, IndexType > read_raw(std::istream &is)
Reads a matrix stored in matrix market format from an input stream.
This structure is used as an intermediate data type to store a sparse matrix.
Definition: matrix_data.hpp:102