1 /*
2 * Copyright (c) 2007, 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_MATRIXTYPES_SYMMETRIC_IMPL_SYMATRIX_H
34 #define FLENS_MATRIXTYPES_SYMMETRIC_IMPL_SYMATRIX_H 1
35
36 #include <cxxblas/typedefs.h>
37 #include <flens/matrixtypes/symmetric/symmetricmatrix.h>
38 #include <flens/typedefs.h>
39
40 namespace flens {
41
42 // forward declarations
43 template <typename FS>
44 class GeMatrix;
45
46 template <typename FS>
47 class HeMatrix;
48
49 template <typename FS>
50 class TrMatrix;
51
52 template <typename FS>
53 class SyMatrix
54 : public SymmetricMatrix<SyMatrix<FS> >
55 {
56 public:
57 typedef FS Engine;
58 typedef typename Engine::ElementType ElementType;
59 typedef typename Engine::IndexType IndexType;
60
61 // view types from Engine
62 typedef typename Engine::ConstView EngineConstView;
63 typedef typename Engine::View EngineView;
64 typedef typename Engine::NoView EngineNoView;
65
66 typedef typename Engine::ConstArrayView ConstArrayView;
67 typedef typename Engine::ArrayView ArrayView;
68 typedef typename Engine::Array Array;
69
70 // view types for
71 typedef DenseVector<ConstArrayView> ConstVectorView;
72 typedef DenseVector<ArrayView> VectorView;
73 typedef DenseVector<Array> Vector;
74
75 typedef GeMatrix<EngineConstView> ConstGeneralView;
76 typedef GeMatrix<EngineView> GeneralView;
77 typedef GeMatrix<EngineNoView> GeneralNoView;
78
79 typedef HeMatrix<EngineConstView> ConstHermitianView;
80 typedef HeMatrix<EngineView> HermitianView;
81 typedef HeMatrix<EngineNoView> HermitianNoView;
82
83 typedef SyMatrix<EngineConstView> ConstView;
84 typedef SyMatrix<EngineView> View;
85 typedef SyMatrix<EngineNoView> NoView;
86
87 typedef TrMatrix<EngineConstView> ConstTriangularView;
88 typedef TrMatrix<EngineView> TriangularView;
89 typedef TrMatrix<EngineNoView> TriangularNoView;
90
91 SyMatrix(const Engine &engine, StorageUpLo upLo);
92
93 SyMatrix(const SyMatrix &rhs);
94
95 template <typename RHS>
96 SyMatrix(const SyMatrix<RHS> &rhs);
97
98 template <typename RHS>
99 SyMatrix(SyMatrix<RHS> &rhs);
100
101 template <typename RHS>
102 SyMatrix(const Matrix<RHS> &rhs);
103
104 // -- operators --------------------------------------------------------
105 void
106 operator=(const ElementType &value);
107
108 SyMatrix &
109 operator=(const SyMatrix &rhs);
110
111 template <typename RHS>
112 SyMatrix &
113 operator=(const Matrix<RHS> &rhs);
114
115 const ElementType &
116 operator()(IndexType row, IndexType col) const;
117
118 ElementType &
119 operator()(IndexType row, IndexType col);
120
121 // rectangular views
122 const ConstGeneralView
123 operator()(const Range<IndexType> &rows,
124 const Range<IndexType> &cols) const;
125
126 GeneralView
127 operator()(const Range<IndexType> &rows,
128 const Range<IndexType> &cols);
129
130 // rectangular views (all rows selected)
131 const ConstGeneralView
132 operator()(const Underscore<IndexType> &,
133 const Range<IndexType> &cols) const;
134
135 GeneralView
136 operator()(const Underscore<IndexType> &,
137 const Range<IndexType> &cols);
138
139 // rectangular views (all columns selected)
140 const ConstGeneralView
141 operator()(const Range<IndexType> &rows,
142 const Underscore<IndexType> &) const;
143
144 GeneralView
145 operator()(const Range<IndexType> &rows,
146 const Underscore<IndexType> &);
147
148 // row view (vector view)
149 const ConstVectorView
150 operator()(IndexType row, const Underscore<IndexType> &) const;
151
152 VectorView
153 operator()(IndexType row, const Underscore<IndexType> &);
154
155 const ConstVectorView
156 operator()(IndexType row, const Range<IndexType> &cols) const;
157
158 VectorView
159 operator()(IndexType row, const Range<IndexType> &cols);
160
161 // column view (vector view)
162 const ConstVectorView
163 operator()(const Underscore<IndexType> &, IndexType col) const;
164
165 VectorView
166 operator()(const Underscore<IndexType> &, IndexType col);
167
168 const ConstVectorView
169 operator()(const Range<IndexType> &rows, IndexType col) const;
170
171 VectorView
172 operator()(const Range<IndexType> &rows, IndexType col);
173
174 // -- views ------------------------------------------------------------
175
176 // general views
177 const ConstGeneralView
178 general() const;
179
180 GeneralView
181 general();
182
183 // hermitian views
184 const ConstHermitianView
185 hermitian() const;
186
187 HermitianView
188 hermitian();
189
190 // triangular views
191 const ConstTriangularView
192 triangular() const;
193
194 TriangularView
195 triangular();
196
197 // -- methods ----------------------------------------------------------
198
199 IndexType
200 dim() const;
201
202 IndexType
203 numRows() const;
204
205 IndexType
206 numCols() const;
207
208 IndexType
209 firstRow() const;
210
211 IndexType
212 lastRow() const;
213
214 IndexType
215 firstCol() const;
216
217 IndexType
218 lastCol() const;
219
220 const ElementType *
221 data() const;
222
223 ElementType *
224 data();
225
226 IndexType
227 leadingDimension() const;
228
229 StorageOrder
230 order() const;
231
232 template <typename RHS>
233 bool
234 resize(const SyMatrix<RHS> &rhs,
235 const ElementType &value = ElementType());
236
237 bool
238 resize(IndexType dim,
239 IndexType firstIndex = Engine::defaultIndexBase,
240 const ElementType &value = ElementType());
241
242 // -- implementation ---------------------------------------------------
243
244 const Engine &
245 engine() const;
246
247 Engine &
248 engine();
249
250 StorageUpLo
251 upLo() const;
252
253 StorageUpLo &
254 upLo();
255
256 private:
257 Engine _engine;
258 StorageUpLo _upLo;
259 };
260
261 } // namespace flens
262
263 #endif // FLENS_MATRIXTYPES_SYMMETRIC_IMPL_SYMATRIX_H
2 * Copyright (c) 2007, 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_MATRIXTYPES_SYMMETRIC_IMPL_SYMATRIX_H
34 #define FLENS_MATRIXTYPES_SYMMETRIC_IMPL_SYMATRIX_H 1
35
36 #include <cxxblas/typedefs.h>
37 #include <flens/matrixtypes/symmetric/symmetricmatrix.h>
38 #include <flens/typedefs.h>
39
40 namespace flens {
41
42 // forward declarations
43 template <typename FS>
44 class GeMatrix;
45
46 template <typename FS>
47 class HeMatrix;
48
49 template <typename FS>
50 class TrMatrix;
51
52 template <typename FS>
53 class SyMatrix
54 : public SymmetricMatrix<SyMatrix<FS> >
55 {
56 public:
57 typedef FS Engine;
58 typedef typename Engine::ElementType ElementType;
59 typedef typename Engine::IndexType IndexType;
60
61 // view types from Engine
62 typedef typename Engine::ConstView EngineConstView;
63 typedef typename Engine::View EngineView;
64 typedef typename Engine::NoView EngineNoView;
65
66 typedef typename Engine::ConstArrayView ConstArrayView;
67 typedef typename Engine::ArrayView ArrayView;
68 typedef typename Engine::Array Array;
69
70 // view types for
71 typedef DenseVector<ConstArrayView> ConstVectorView;
72 typedef DenseVector<ArrayView> VectorView;
73 typedef DenseVector<Array> Vector;
74
75 typedef GeMatrix<EngineConstView> ConstGeneralView;
76 typedef GeMatrix<EngineView> GeneralView;
77 typedef GeMatrix<EngineNoView> GeneralNoView;
78
79 typedef HeMatrix<EngineConstView> ConstHermitianView;
80 typedef HeMatrix<EngineView> HermitianView;
81 typedef HeMatrix<EngineNoView> HermitianNoView;
82
83 typedef SyMatrix<EngineConstView> ConstView;
84 typedef SyMatrix<EngineView> View;
85 typedef SyMatrix<EngineNoView> NoView;
86
87 typedef TrMatrix<EngineConstView> ConstTriangularView;
88 typedef TrMatrix<EngineView> TriangularView;
89 typedef TrMatrix<EngineNoView> TriangularNoView;
90
91 SyMatrix(const Engine &engine, StorageUpLo upLo);
92
93 SyMatrix(const SyMatrix &rhs);
94
95 template <typename RHS>
96 SyMatrix(const SyMatrix<RHS> &rhs);
97
98 template <typename RHS>
99 SyMatrix(SyMatrix<RHS> &rhs);
100
101 template <typename RHS>
102 SyMatrix(const Matrix<RHS> &rhs);
103
104 // -- operators --------------------------------------------------------
105 void
106 operator=(const ElementType &value);
107
108 SyMatrix &
109 operator=(const SyMatrix &rhs);
110
111 template <typename RHS>
112 SyMatrix &
113 operator=(const Matrix<RHS> &rhs);
114
115 const ElementType &
116 operator()(IndexType row, IndexType col) const;
117
118 ElementType &
119 operator()(IndexType row, IndexType col);
120
121 // rectangular views
122 const ConstGeneralView
123 operator()(const Range<IndexType> &rows,
124 const Range<IndexType> &cols) const;
125
126 GeneralView
127 operator()(const Range<IndexType> &rows,
128 const Range<IndexType> &cols);
129
130 // rectangular views (all rows selected)
131 const ConstGeneralView
132 operator()(const Underscore<IndexType> &,
133 const Range<IndexType> &cols) const;
134
135 GeneralView
136 operator()(const Underscore<IndexType> &,
137 const Range<IndexType> &cols);
138
139 // rectangular views (all columns selected)
140 const ConstGeneralView
141 operator()(const Range<IndexType> &rows,
142 const Underscore<IndexType> &) const;
143
144 GeneralView
145 operator()(const Range<IndexType> &rows,
146 const Underscore<IndexType> &);
147
148 // row view (vector view)
149 const ConstVectorView
150 operator()(IndexType row, const Underscore<IndexType> &) const;
151
152 VectorView
153 operator()(IndexType row, const Underscore<IndexType> &);
154
155 const ConstVectorView
156 operator()(IndexType row, const Range<IndexType> &cols) const;
157
158 VectorView
159 operator()(IndexType row, const Range<IndexType> &cols);
160
161 // column view (vector view)
162 const ConstVectorView
163 operator()(const Underscore<IndexType> &, IndexType col) const;
164
165 VectorView
166 operator()(const Underscore<IndexType> &, IndexType col);
167
168 const ConstVectorView
169 operator()(const Range<IndexType> &rows, IndexType col) const;
170
171 VectorView
172 operator()(const Range<IndexType> &rows, IndexType col);
173
174 // -- views ------------------------------------------------------------
175
176 // general views
177 const ConstGeneralView
178 general() const;
179
180 GeneralView
181 general();
182
183 // hermitian views
184 const ConstHermitianView
185 hermitian() const;
186
187 HermitianView
188 hermitian();
189
190 // triangular views
191 const ConstTriangularView
192 triangular() const;
193
194 TriangularView
195 triangular();
196
197 // -- methods ----------------------------------------------------------
198
199 IndexType
200 dim() const;
201
202 IndexType
203 numRows() const;
204
205 IndexType
206 numCols() const;
207
208 IndexType
209 firstRow() const;
210
211 IndexType
212 lastRow() const;
213
214 IndexType
215 firstCol() const;
216
217 IndexType
218 lastCol() const;
219
220 const ElementType *
221 data() const;
222
223 ElementType *
224 data();
225
226 IndexType
227 leadingDimension() const;
228
229 StorageOrder
230 order() const;
231
232 template <typename RHS>
233 bool
234 resize(const SyMatrix<RHS> &rhs,
235 const ElementType &value = ElementType());
236
237 bool
238 resize(IndexType dim,
239 IndexType firstIndex = Engine::defaultIndexBase,
240 const ElementType &value = ElementType());
241
242 // -- implementation ---------------------------------------------------
243
244 const Engine &
245 engine() const;
246
247 Engine &
248 engine();
249
250 StorageUpLo
251 upLo() const;
252
253 StorageUpLo &
254 upLo();
255
256 private:
257 Engine _engine;
258 StorageUpLo _upLo;
259 };
260
261 } // namespace flens
262
263 #endif // FLENS_MATRIXTYPES_SYMMETRIC_IMPL_SYMATRIX_H