1 /*
2 * Copyright (c) 2010, Michael Lehn
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1) Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3) Neither the name of the FLENS development group nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER 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 */
32
33 #ifndef FLENS_IO_FULLSTORAGE_OUT_TCC
34 #define FLENS_IO_FULLSTORAGE_OUT_TCC 1
35
36 #include <cxxblas/typedefs.h>
37
38 namespace flens {
39
40 template <typename FS>
41 std::ostream &
42 operator<<(std::ostream &out, const GeMatrix<FS> &A)
43 {
44 typedef typename GeMatrix<FS>::IndexType IndexType;
45 # ifdef FLENS_IO_WITH_RANGES
46 IndexType defaultIndexBase = FS::defaultIndexBase;
47
48 out << "[";
49 (A.firstRow()==defaultIndexBase) ? out << A.numRows()
50 : out << A.firstRow()
51 << ".."
52 << A.lastRow();
53 out << ", ";
54 (A.firstCol()==defaultIndexBase) ? out << A.numCols()
55 : out << A.firstCol()
56 << ".."
57 << A.lastCol();
58 out << "]" << std::endl;
59 # endif // FLENS_IO_WITH_RANGES
60
61 out << std::endl;
62 //out.setf(std::ios::fixed|std::ios::right);
63 for (IndexType i=A.firstRow(); i<=A.lastRow(); ++i) {
64 for (IndexType j=A.firstCol(); j<=A.lastCol(); ++j) {
65 out.width(20);
66 out << A(i,j) << " ";
67 }
68 out << std::endl;
69 }
70 return out;
71 }
72
73 template <typename FS>
74 std::ostream &
75 operator<<(std::ostream &out, const HeMatrix<FS> &A)
76 {
77 typedef typename HeMatrix<FS>::ElementType ElementType;
78 typedef typename HeMatrix<FS>::IndexType IndexType;
79 # ifdef FLENS_IO_WITH_RANGES
80 IndexType defaultIndexBase = FS::defaultIndexBase;
81
82 if ((A.firstRow()==defaultIndexBase)
83 && (A.firstCol()==defaultIndexBase))
84 {
85 out << "[" << A.dim() << ", " << A.dim()
86 << "]" << std::endl;
87 } else {
88 out << "[" << A.firstRow() << ".." << A.lastRow()
89 << ", " << A.firstCol() << ".." << A.lastCol()
90 << "]" << std::endl;
91 }
92 # endif // FLENS_IO_WITH_RANGES
93
94 out << std::endl;
95 out.setf(std::ios::fixed|std::ios::right);
96 for (IndexType i=A.firstRow(); i<=A.lastRow(); ++i) {
97 for (IndexType j=A.firstCol(); j<=A.lastCol(); ++j) {
98 out.width(22);
99 if (i==j) {
100 out << ElementType(cxxblas::real(A(i,j)));
101 }
102 if (i<j) {
103 out << ((A.upLo()==cxxblas::Upper)
104 ? A(i,j)
105 : cxxblas::conjugate(A(j,i)));
106 }
107 if (i>j) {
108 out << ((A.upLo()==cxxblas::Upper)
109 ? cxxblas::conjugate(A(j,i))
110 : A(i,j));
111 }
112 }
113 out << std::endl;
114 }
115 return out;
116 }
117
118 template <typename FS>
119 std::ostream &
120 operator<<(std::ostream &out, const SyMatrix<FS> &A)
121 {
122 typedef typename GeMatrix<FS>::IndexType IndexType;
123
124 # ifdef FLENS_IO_WITH_RANGES
125 IndexType defaultIndexBase = FS::defaultIndexBase;
126
127 if ((A.firstRow()==defaultIndexBase)
128 && (A.firstCol()==defaultIndexBase))
129 {
130 out << "[" << A.dim() << ", " << A.dim()
131 << "]" << std::endl;
132 } else {
133 out << "[" << A.firstRow() << ".." << A.lastRow()
134 << ", " << A.firstCol() << ".." << A.lastCol()
135 << "]" << std::endl;
136 }
137 # endif // FLENS_IO_WITH_RANGES
138
139 out << std::endl;
140 out.setf(std::ios::fixed|std::ios::right);
141 for (IndexType i=A.firstRow(); i<=A.lastRow(); ++i) {
142 for (IndexType j=A.firstCol(); j<=A.lastCol(); ++j) {
143 out.width(11);
144 out << ((A.upLo()==cxxblas::Upper)
145 ? A(std::min(i,j), std::max(i,j))
146 : A(std::max(i,j), std::min(i,j)));
147 out << " ";
148 }
149 out << std::endl;
150 }
151 return out;
152 }
153
154 template <typename FS>
155 std::ostream &
156 operator<<(std::ostream &out, const TrMatrix<FS> &A)
157 {
158 typedef typename GeMatrix<FS>::IndexType IndexType;
159 typedef typename GeMatrix<FS>::ElementType ElementType;
160
161 # ifdef FLENS_IO_WITH_RANGES
162 IndexType defaultIndexBase = FS::defaultIndexBase;
163
164 if ((A.firstRow()==defaultIndexBase)
165 && (A.firstCol()==defaultIndexBase))
166 {
167 out << "[" << A.dim() << ", " << A.dim()
168 << "]" << std::endl;
169 } else {
170 out << "[" << A.firstRow() << ".." << A.lastRow()
171 << ", " << A.firstCol() << ".." << A.lastCol()
172 << "]" << std::endl;
173 }
174 # endif // FLENS_IO_WITH_RANGES
175
176 out << std::endl;
177 // out.setf(std::ios::fixed|std::ios::right);
178 for (IndexType i=A.firstRow(); i<=A.lastRow(); ++i) {
179 for (IndexType j=A.firstCol(); j<=A.lastCol(); ++j) {
180 out.width(20);
181 if (i==j) {
182 (A.diag()==cxxblas::Unit) ? out << ElementType(1)
183 : out << A(i,j);
184 } else {
185 if (((i>j) && (A.upLo()==cxxblas::Lower))
186 || ((i<j) && (A.upLo()==cxxblas::Upper))) {
187 out << A(i,j);
188 } else {
189 out << ElementType(0);
190 }
191 }
192 out << " ";
193 }
194 out << std::endl;
195 }
196 return out;
197 }
198
199 } // namespace flens
200
201 #endif // FLENS_IO_FULLSTORAGE_OUT_TCC
2 * Copyright (c) 2010, Michael Lehn
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1) Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3) Neither the name of the FLENS development group nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER 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 */
32
33 #ifndef FLENS_IO_FULLSTORAGE_OUT_TCC
34 #define FLENS_IO_FULLSTORAGE_OUT_TCC 1
35
36 #include <cxxblas/typedefs.h>
37
38 namespace flens {
39
40 template <typename FS>
41 std::ostream &
42 operator<<(std::ostream &out, const GeMatrix<FS> &A)
43 {
44 typedef typename GeMatrix<FS>::IndexType IndexType;
45 # ifdef FLENS_IO_WITH_RANGES
46 IndexType defaultIndexBase = FS::defaultIndexBase;
47
48 out << "[";
49 (A.firstRow()==defaultIndexBase) ? out << A.numRows()
50 : out << A.firstRow()
51 << ".."
52 << A.lastRow();
53 out << ", ";
54 (A.firstCol()==defaultIndexBase) ? out << A.numCols()
55 : out << A.firstCol()
56 << ".."
57 << A.lastCol();
58 out << "]" << std::endl;
59 # endif // FLENS_IO_WITH_RANGES
60
61 out << std::endl;
62 //out.setf(std::ios::fixed|std::ios::right);
63 for (IndexType i=A.firstRow(); i<=A.lastRow(); ++i) {
64 for (IndexType j=A.firstCol(); j<=A.lastCol(); ++j) {
65 out.width(20);
66 out << A(i,j) << " ";
67 }
68 out << std::endl;
69 }
70 return out;
71 }
72
73 template <typename FS>
74 std::ostream &
75 operator<<(std::ostream &out, const HeMatrix<FS> &A)
76 {
77 typedef typename HeMatrix<FS>::ElementType ElementType;
78 typedef typename HeMatrix<FS>::IndexType IndexType;
79 # ifdef FLENS_IO_WITH_RANGES
80 IndexType defaultIndexBase = FS::defaultIndexBase;
81
82 if ((A.firstRow()==defaultIndexBase)
83 && (A.firstCol()==defaultIndexBase))
84 {
85 out << "[" << A.dim() << ", " << A.dim()
86 << "]" << std::endl;
87 } else {
88 out << "[" << A.firstRow() << ".." << A.lastRow()
89 << ", " << A.firstCol() << ".." << A.lastCol()
90 << "]" << std::endl;
91 }
92 # endif // FLENS_IO_WITH_RANGES
93
94 out << std::endl;
95 out.setf(std::ios::fixed|std::ios::right);
96 for (IndexType i=A.firstRow(); i<=A.lastRow(); ++i) {
97 for (IndexType j=A.firstCol(); j<=A.lastCol(); ++j) {
98 out.width(22);
99 if (i==j) {
100 out << ElementType(cxxblas::real(A(i,j)));
101 }
102 if (i<j) {
103 out << ((A.upLo()==cxxblas::Upper)
104 ? A(i,j)
105 : cxxblas::conjugate(A(j,i)));
106 }
107 if (i>j) {
108 out << ((A.upLo()==cxxblas::Upper)
109 ? cxxblas::conjugate(A(j,i))
110 : A(i,j));
111 }
112 }
113 out << std::endl;
114 }
115 return out;
116 }
117
118 template <typename FS>
119 std::ostream &
120 operator<<(std::ostream &out, const SyMatrix<FS> &A)
121 {
122 typedef typename GeMatrix<FS>::IndexType IndexType;
123
124 # ifdef FLENS_IO_WITH_RANGES
125 IndexType defaultIndexBase = FS::defaultIndexBase;
126
127 if ((A.firstRow()==defaultIndexBase)
128 && (A.firstCol()==defaultIndexBase))
129 {
130 out << "[" << A.dim() << ", " << A.dim()
131 << "]" << std::endl;
132 } else {
133 out << "[" << A.firstRow() << ".." << A.lastRow()
134 << ", " << A.firstCol() << ".." << A.lastCol()
135 << "]" << std::endl;
136 }
137 # endif // FLENS_IO_WITH_RANGES
138
139 out << std::endl;
140 out.setf(std::ios::fixed|std::ios::right);
141 for (IndexType i=A.firstRow(); i<=A.lastRow(); ++i) {
142 for (IndexType j=A.firstCol(); j<=A.lastCol(); ++j) {
143 out.width(11);
144 out << ((A.upLo()==cxxblas::Upper)
145 ? A(std::min(i,j), std::max(i,j))
146 : A(std::max(i,j), std::min(i,j)));
147 out << " ";
148 }
149 out << std::endl;
150 }
151 return out;
152 }
153
154 template <typename FS>
155 std::ostream &
156 operator<<(std::ostream &out, const TrMatrix<FS> &A)
157 {
158 typedef typename GeMatrix<FS>::IndexType IndexType;
159 typedef typename GeMatrix<FS>::ElementType ElementType;
160
161 # ifdef FLENS_IO_WITH_RANGES
162 IndexType defaultIndexBase = FS::defaultIndexBase;
163
164 if ((A.firstRow()==defaultIndexBase)
165 && (A.firstCol()==defaultIndexBase))
166 {
167 out << "[" << A.dim() << ", " << A.dim()
168 << "]" << std::endl;
169 } else {
170 out << "[" << A.firstRow() << ".." << A.lastRow()
171 << ", " << A.firstCol() << ".." << A.lastCol()
172 << "]" << std::endl;
173 }
174 # endif // FLENS_IO_WITH_RANGES
175
176 out << std::endl;
177 // out.setf(std::ios::fixed|std::ios::right);
178 for (IndexType i=A.firstRow(); i<=A.lastRow(); ++i) {
179 for (IndexType j=A.firstCol(); j<=A.lastCol(); ++j) {
180 out.width(20);
181 if (i==j) {
182 (A.diag()==cxxblas::Unit) ? out << ElementType(1)
183 : out << A(i,j);
184 } else {
185 if (((i>j) && (A.upLo()==cxxblas::Lower))
186 || ((i<j) && (A.upLo()==cxxblas::Upper))) {
187 out << A(i,j);
188 } else {
189 out << ElementType(0);
190 }
191 }
192 out << " ";
193 }
194 out << std::endl;
195 }
196 return out;
197 }
198
199 } // namespace flens
200
201 #endif // FLENS_IO_FULLSTORAGE_OUT_TCC