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