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_HERMITIAN_IMPL_HEMATRIX_TCC
34 #define FLENS_MATRIXTYPES_HERMITIAN_IMPL_HEMATRIX_TCC 1
35
36 #include <flens/blas/level1/copy.h>
37 #include <flens/typedefs.h>
38
39 namespace flens {
40
41 template <typename FS>
42 HeMatrix<FS>::HeMatrix()
43 {
44 }
45
46 template <typename FS>
47 HeMatrix<FS>::HeMatrix(IndexType dim)
48 : _engine(dim, dim)
49 {
50 ASSERT(dim>=0);
51 }
52
53 template <typename FS>
54 HeMatrix<FS>::HeMatrix(IndexType dim, IndexType firstRow, IndexType firstCol)
55 : _engine(dim, dim, firstRow, firstCol)
56 {
57 ASSERT(dim>=0);
58 }
59
60 template <typename FS>
61 HeMatrix<FS>::HeMatrix(const Engine &engine, StorageUpLo upLo)
62 : _engine(engine), _upLo(upLo)
63 {
64 ASSERT(_engine.numRows()==_engine.numCols());
65 }
66
67 template <typename FS>
68 HeMatrix<FS>::HeMatrix(const HeMatrix &rhs)
69 : HermitianMatrix<HeMatrix<FS> >(),
70 _engine(rhs.engine()), _upLo(rhs.upLo())
71 {
72 }
73
74 template <typename FS>
75 template <typename RHS>
76 HeMatrix<FS>::HeMatrix(const HeMatrix<RHS> &rhs)
77 : _engine(rhs.engine()), _upLo(rhs.upLo())
78 {
79 }
80
81 template <typename FS>
82 template <typename RHS>
83 HeMatrix<FS>::HeMatrix(HeMatrix<RHS> &rhs)
84 : _engine(rhs.engine()), _upLo(rhs.upLo())
85 {
86 }
87
88 template <typename FS>
89 template <typename RHS>
90 HeMatrix<FS>::HeMatrix(const Matrix<RHS> &rhs)
91 {
92 blas::copy(rhs.impl(), *this);
93 }
94
95 // -- operators ----------------------------------------------------------------
96
97 template <typename FS>
98 const typename HeMatrix<FS>::ElementType &
99 HeMatrix<FS>::operator()(IndexType row, IndexType col) const
100 {
101 # ifndef NDEBUG
102 if (_upLo==Upper) {
103 ASSERT(col-firstCol()>=row-firstRow());
104 } else {
105 ASSERT(col-firstCol()<=row-firstRow());
106 }
107 # endif
108 return _engine(row, col);
109 }
110
111 template <typename FS>
112 typename HeMatrix<FS>::ElementType &
113 HeMatrix<FS>::operator()(IndexType row, IndexType col)
114 {
115 # ifndef NDEBUG
116 if (_upLo==Upper) {
117 ASSERT(col-firstCol()>=row-firstRow());
118 } else {
119 ASSERT(col-firstCol()<=row-firstRow());
120 }
121 # endif
122 return _engine(row, col);
123 }
124
125 // -- views --------------------------------------------------------------------
126
127 // general views
128 template <typename FS>
129 typename HeMatrix<FS>::ConstGeneralView
130 HeMatrix<FS>::general() const
131 {
132 return _engine;
133 }
134
135 template <typename FS>
136 typename HeMatrix<FS>::GeneralView
137 HeMatrix<FS>::general()
138 {
139 return _engine;
140 }
141
142 // -- methods ------------------------------------------------------------------
143
144 template <typename FS>
145 typename HeMatrix<FS>::IndexType
146 HeMatrix<FS>::dim() const
147 {
148 ASSERT(_engine.numRows()==_engine.numCols());
149
150 return _engine.numRows();
151 }
152
153 template <typename FS>
154 typename HeMatrix<FS>::IndexType
155 HeMatrix<FS>::firstRow() const
156 {
157 return _engine.firstRow();
158 }
159
160 template <typename FS>
161 typename HeMatrix<FS>::IndexType
162 HeMatrix<FS>::lastRow() const
163 {
164 return _engine.lastRow();
165 }
166
167 template <typename FS>
168 typename HeMatrix<FS>::IndexType
169 HeMatrix<FS>::firstCol() const
170 {
171 return _engine.firstCol();
172 }
173
174 template <typename FS>
175 typename HeMatrix<FS>::IndexType
176 HeMatrix<FS>::lastCol() const
177 {
178 return _engine.lastCol();
179 }
180
181 template <typename FS>
182 const typename HeMatrix<FS>::ElementType *
183 HeMatrix<FS>::data() const
184 {
185 return _engine.data();
186 }
187
188 template <typename FS>
189 typename HeMatrix<FS>::ElementType *
190 HeMatrix<FS>::data()
191 {
192 return _engine.data();
193 }
194
195 template <typename FS>
196 typename HeMatrix<FS>::IndexType
197 HeMatrix<FS>::leadingDimension() const
198 {
199 return _engine.leadingDimension();
200 }
201
202 // -- implementation -----------------------------------------------------------
203
204 template <typename FS>
205 const typename HeMatrix<FS>::Engine &
206 HeMatrix<FS>::engine() const
207 {
208 return _engine;
209 }
210
211 template <typename FS>
212 typename HeMatrix<FS>::Engine &
213 HeMatrix<FS>::engine()
214 {
215 return _engine;
216 }
217
218 template <typename FS>
219 StorageUpLo
220 HeMatrix<FS>::upLo() const
221 {
222 return _upLo;
223 }
224
225 template <typename FS>
226 StorageUpLo &
227 HeMatrix<FS>::upLo()
228 {
229 return _upLo;
230 }
231
232 } // namespace flens
233
234 #endif // FLENS_MATRIXTYPES_HERMITIAN_IMPL_HEMATRIX_TCC
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_HERMITIAN_IMPL_HEMATRIX_TCC
34 #define FLENS_MATRIXTYPES_HERMITIAN_IMPL_HEMATRIX_TCC 1
35
36 #include <flens/blas/level1/copy.h>
37 #include <flens/typedefs.h>
38
39 namespace flens {
40
41 template <typename FS>
42 HeMatrix<FS>::HeMatrix()
43 {
44 }
45
46 template <typename FS>
47 HeMatrix<FS>::HeMatrix(IndexType dim)
48 : _engine(dim, dim)
49 {
50 ASSERT(dim>=0);
51 }
52
53 template <typename FS>
54 HeMatrix<FS>::HeMatrix(IndexType dim, IndexType firstRow, IndexType firstCol)
55 : _engine(dim, dim, firstRow, firstCol)
56 {
57 ASSERT(dim>=0);
58 }
59
60 template <typename FS>
61 HeMatrix<FS>::HeMatrix(const Engine &engine, StorageUpLo upLo)
62 : _engine(engine), _upLo(upLo)
63 {
64 ASSERT(_engine.numRows()==_engine.numCols());
65 }
66
67 template <typename FS>
68 HeMatrix<FS>::HeMatrix(const HeMatrix &rhs)
69 : HermitianMatrix<HeMatrix<FS> >(),
70 _engine(rhs.engine()), _upLo(rhs.upLo())
71 {
72 }
73
74 template <typename FS>
75 template <typename RHS>
76 HeMatrix<FS>::HeMatrix(const HeMatrix<RHS> &rhs)
77 : _engine(rhs.engine()), _upLo(rhs.upLo())
78 {
79 }
80
81 template <typename FS>
82 template <typename RHS>
83 HeMatrix<FS>::HeMatrix(HeMatrix<RHS> &rhs)
84 : _engine(rhs.engine()), _upLo(rhs.upLo())
85 {
86 }
87
88 template <typename FS>
89 template <typename RHS>
90 HeMatrix<FS>::HeMatrix(const Matrix<RHS> &rhs)
91 {
92 blas::copy(rhs.impl(), *this);
93 }
94
95 // -- operators ----------------------------------------------------------------
96
97 template <typename FS>
98 const typename HeMatrix<FS>::ElementType &
99 HeMatrix<FS>::operator()(IndexType row, IndexType col) const
100 {
101 # ifndef NDEBUG
102 if (_upLo==Upper) {
103 ASSERT(col-firstCol()>=row-firstRow());
104 } else {
105 ASSERT(col-firstCol()<=row-firstRow());
106 }
107 # endif
108 return _engine(row, col);
109 }
110
111 template <typename FS>
112 typename HeMatrix<FS>::ElementType &
113 HeMatrix<FS>::operator()(IndexType row, IndexType col)
114 {
115 # ifndef NDEBUG
116 if (_upLo==Upper) {
117 ASSERT(col-firstCol()>=row-firstRow());
118 } else {
119 ASSERT(col-firstCol()<=row-firstRow());
120 }
121 # endif
122 return _engine(row, col);
123 }
124
125 // -- views --------------------------------------------------------------------
126
127 // general views
128 template <typename FS>
129 typename HeMatrix<FS>::ConstGeneralView
130 HeMatrix<FS>::general() const
131 {
132 return _engine;
133 }
134
135 template <typename FS>
136 typename HeMatrix<FS>::GeneralView
137 HeMatrix<FS>::general()
138 {
139 return _engine;
140 }
141
142 // -- methods ------------------------------------------------------------------
143
144 template <typename FS>
145 typename HeMatrix<FS>::IndexType
146 HeMatrix<FS>::dim() const
147 {
148 ASSERT(_engine.numRows()==_engine.numCols());
149
150 return _engine.numRows();
151 }
152
153 template <typename FS>
154 typename HeMatrix<FS>::IndexType
155 HeMatrix<FS>::firstRow() const
156 {
157 return _engine.firstRow();
158 }
159
160 template <typename FS>
161 typename HeMatrix<FS>::IndexType
162 HeMatrix<FS>::lastRow() const
163 {
164 return _engine.lastRow();
165 }
166
167 template <typename FS>
168 typename HeMatrix<FS>::IndexType
169 HeMatrix<FS>::firstCol() const
170 {
171 return _engine.firstCol();
172 }
173
174 template <typename FS>
175 typename HeMatrix<FS>::IndexType
176 HeMatrix<FS>::lastCol() const
177 {
178 return _engine.lastCol();
179 }
180
181 template <typename FS>
182 const typename HeMatrix<FS>::ElementType *
183 HeMatrix<FS>::data() const
184 {
185 return _engine.data();
186 }
187
188 template <typename FS>
189 typename HeMatrix<FS>::ElementType *
190 HeMatrix<FS>::data()
191 {
192 return _engine.data();
193 }
194
195 template <typename FS>
196 typename HeMatrix<FS>::IndexType
197 HeMatrix<FS>::leadingDimension() const
198 {
199 return _engine.leadingDimension();
200 }
201
202 // -- implementation -----------------------------------------------------------
203
204 template <typename FS>
205 const typename HeMatrix<FS>::Engine &
206 HeMatrix<FS>::engine() const
207 {
208 return _engine;
209 }
210
211 template <typename FS>
212 typename HeMatrix<FS>::Engine &
213 HeMatrix<FS>::engine()
214 {
215 return _engine;
216 }
217
218 template <typename FS>
219 StorageUpLo
220 HeMatrix<FS>::upLo() const
221 {
222 return _upLo;
223 }
224
225 template <typename FS>
226 StorageUpLo &
227 HeMatrix<FS>::upLo()
228 {
229 return _upLo;
230 }
231
232 } // namespace flens
233
234 #endif // FLENS_MATRIXTYPES_HERMITIAN_IMPL_HEMATRIX_TCC