1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
<doc  56
      57
      58
      59

      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
<doc  96
      97
<doc  98
      99
<doc 100
     101
<doc 102
     103

     104
<doc 105
     106
<doc 107
     108
<doc 109
     110

     111
<doc 112
     113

     114
<doc 115
     116

     117
     118
<doc 119
     120

     121
<doc 122
     123

     124
<doc 125
     126
     127

     128
<doc 129
     130
     131

     132
<doc 133
     134
     135

     136
<doc 137
     138

     139
<doc 140
     141

     142
     143
<doc 144
     145
     146

     147
<doc 148
     149
     150

     151
     152
<doc 153
     154
     155

     156
<doc 157
     158
     159

     160
     161
<doc 162
     163
     164

     165
<doc 166
     167
     168

     169
     170
<doc 171
     172

     173
<doc 174
     175

     176
<doc 177
     178

     179
<doc 180
     181

     182
     183
<doc 184
     185

     186
<doc 187
     188

     189
<doc 190
     191

     192
<doc 193
     194

     195
     196
<doc 197
     198

     199
<doc 200
     201

     202
<doc 203
     204

     205
<doc 206
     207

     208
<doc 209
     210

     211
<doc 212
     213

     214
<doc 215
     216

     217
<doc 218
     219

     220
<doc 221
     222

     223
<doc 224
     225

     226
<doc 227
     228

     229
<doc 230
     231

     232
<doc 233
     234
     235
     236

     237
<doc 238
     239
     240
     241

     242
<doc 243
     244
     245
     246
     247

     248
     249
     250
<doc 251
     252

     253
<doc 254
     255

     256
     257
<doc 258
     259

     260
<doc 261
     262

     263
     264
<doc 265
     266

     267
<doc 268
     269

     270
     271
<doc 272
     273

     274
<doc 275
     276

     277
     278
<doc 279
     280

     281
<doc 282
     283

     284
<doc 285
     286

     287
<doc 288
     289

     290
     291
     292
     293
     294
     295
     296
     297
     298
     299
<doc 300
     301

     302
<doc 303
     304
     305
     306
     307
     308
     309
     310
     311
     312
     313
     314
     315
<doc 316
     317
     318

     319
     320
     321
     322
     323
     324
     325
     326
     327
     328
<doc 329
     330
     331
     332

     333
     334
     335
     336
     337
/*
 *   Copyright (c) 2007, Michael Lehn
 *
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
 *   are met:
 *
 *   1) Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *   2) Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in
 *      the documentation and/or other materials provided with the
 *      distribution.
 *   3) Neither the name of the FLENS development group nor the names of
 *      its contributors may be used to endorse or promote products derived
 *      from this software without specific prior written permission.
 *
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef FLENS_MATRIXTYPES_HERMITIAN_IMPL_HEMATRIX_H
#define FLENS_MATRIXTYPES_HERMITIAN_IMPL_HEMATRIX_H 1

#include <cxxblas/typedefs.h>
#include <flens/auxiliary/auxiliary.h>
#include <flens/typedefs.h>
#include <flens/matrixtypes/hermitian/hermitianmatrix.h>

namespace flens {

// forward declarations
template <typename A>
    class DenseVector;

template <typename FS>
    class GeMatrix;

template <typename FS>
    class SyMatrix;

template <typename FS>
    class TrMatrix;

template <typename FS>
class HeMatrix
    : public HermitianMatrix<HeMatrix<FS> >
{
    public:
        typedef FS                                  Engine;
        typedef typename Engine::ElementType        ElementType;
        typedef typename Engine::IndexType          IndexType;

        // view types from Engine
        typedef typename Engine::ConstView          EngineConstView;
        typedef typename Engine::View               EngineView;
        typedef typename Engine::NoView             EngineNoView;

        typedef typename Engine::ConstArrayView     ConstArrayView;
        typedef typename Engine::ArrayView          ArrayView;
        typedef typename Engine::Array              Array;

        // view types
        typedef DenseVector<ConstArrayView>         ConstVectorView;
        typedef DenseVector<ArrayView>              VectorView;
        typedef DenseVector<Array>                  Vector;

        typedef GeMatrix<EngineConstView>           ConstGeneralView;
        typedef GeMatrix<EngineView>                GeneralView;
        typedef GeMatrix<EngineNoView>              GeneralNoView;

        typedef HeMatrix<EngineConstView>           ConstView;
        typedef HeMatrix<EngineView>                View;
        typedef HeMatrix<EngineNoView>              NoView;

        typedef SyMatrix<EngineConstView>           ConstSymmetricView;
        typedef SyMatrix<EngineView>                SymmetricView;
        typedef SyMatrix<EngineNoView>              SymmetricNoView;

        typedef TrMatrix<EngineConstView>           ConstTriangularView;
        typedef TrMatrix<EngineView>                TriangularView;
        typedef TrMatrix<EngineNoView>              TriangularNoView;

        // -- constructors -----------------------------------------------------
        HeMatrix(StorageUpLo upLo=Upper);

        HeMatrix(IndexType dim, StorageUpLo upLo);

        HeMatrix(IndexType dim, IndexType firstIndex, StorageUpLo upLo);

        HeMatrix(IndexType dim, IndexType firstRow, IndexType firstCol,
                 StorageUpLo upLo);

        HeMatrix(const Engine &engine, StorageUpLo upLo);

        HeMatrix(const HeMatrix &rhs);

        template <typename RHS>
            HeMatrix(const HeMatrix<RHS> &rhs);

        template <typename RHS>
            HeMatrix(HeMatrix<RHS> &rhs);

        template <typename RHS>
            HeMatrix(const Matrix<RHS> &rhs);

        // -- operators --------------------------------------------------------
        void
        operator=(const ElementType &value);

        HeMatrix &
        operator=(const HeMatrix &rhs);

        template <typename RHS>
            HeMatrix &
            operator=(const Matrix<RHS> &rhs);

        template <typename RHS>
            HeMatrix &
            operator+=(const Matrix<RHS> &rhs);

        template <typename RHS>
            HeMatrix &
            operator-=(const Matrix<RHS> &rhs);

        const ElementType &
        operator()(IndexType row, IndexType col) const;

        ElementType &
        operator()(IndexType row, IndexType col);

        // rectangular views
        const ConstGeneralView
        operator()(const Range<IndexType> &rows,
                   const Range<IndexType> &cols) const;

        GeneralView
        operator()(const Range<IndexType> &rows,
                   const Range<IndexType> &cols);

        // rectangular views (all rows selected)
        const ConstGeneralView
        operator()(const Underscore<IndexType> &,
                   const Range<IndexType> &cols) const;

        GeneralView
        operator()(const Underscore<IndexType> &,
                   const Range<IndexType> &cols);

        // rectangular views (all columns selected)
        const ConstGeneralView
        operator()(const Range<IndexType> &rows,
                   const Underscore<IndexType> &) const;

        GeneralView
        operator()(const Range<IndexType> &rows,
                   const Underscore<IndexType> &);

        // row view (vector view)
        const ConstVectorView
        operator()(IndexType row, const Underscore<IndexType> &) const;

        VectorView
        operator()(IndexType row, const Underscore<IndexType> &);

        const ConstVectorView
        operator()(IndexType row, const Range<IndexType> &cols) const;

        VectorView
        operator()(IndexType row, const Range<IndexType> &cols);

        // column view (vector view)
        const ConstVectorView
        operator()(const Underscore<IndexType> &, IndexType col) const;

        VectorView
        operator()(const Underscore<IndexType> &, IndexType col);

        const ConstVectorView
        operator()(const Range<IndexType> &rows, IndexType col) const;

        VectorView
        operator()(const Range<IndexType> &rows, IndexType col);

        // -- methods ----------------------------------------------------------
        IndexType
        dim() const;

        IndexType
        numRows() const;

        IndexType
        numCols() const;

        IndexType
        firstRow() const;

        IndexType
        lastRow() const;

        IndexType
        firstCol() const;

        IndexType
        lastCol() const;

        const ElementType *
        data() const;

        ElementType *
        data();

        IndexType
        leadingDimension() const;

        StorageOrder
        order() const;

        bool
        fill(const ElementType &value = ElementType(0));

        template <typename RHS>
            bool
            resize(const HeMatrix<RHS> &rhs,
                   const ElementType &value = ElementType());

        bool
        resize(IndexType dim,
               IndexType firstIndex = Engine::defaultIndexBase,
               const ElementType &value = ElementType());

        bool
        resize(IndexType dim,
               StorageUpLo upLo,
               IndexType firstIndex = Engine::defaultIndexBase,
               const ElementType &value = ElementType());

        // -- views ------------------------------------------------------------
        // general views
        ConstGeneralView
        general() const;

        GeneralView
        general();

        // symmetric views
        const ConstSymmetricView
        symmetric() const;

        SymmetricView
        symmetric();

        // triangular views
        const ConstTriangularView
        triangular() const;

        TriangularView
        triangular();

        // diag views
        const ConstVectorView
        diag(IndexType d) const;

        VectorView
        diag(IndexType d);

        // -- implementation ---------------------------------------------------
        const Engine &
        engine() const;

        Engine &
        engine();

        StorageUpLo
        upLo() const;

        StorageUpLo &
        upLo();

    private:
        Engine      _engine;
        StorageUpLo _upLo;
};

//-- Traits --------------------------------------------------------------------
//
//  IsHeMatrix
//
struct _HeMatrixChecker
{

    struct Two {
        char x;
        char y;
    };

    static Two
    check(_AnyConversion);

    template <typename Any>
        static char
        check(HeMatrix<Any>);
};

template <typename T>
struct IsHeMatrix
{
    static T var;
    static const bool value = sizeof(_HeMatrixChecker::check(var))==1;
};

//-- HeMatrix specific functions -----------------------------------------------

//
//  fillRandom
//

template <typename MA>
    typename RestrictTo<IsHeMatrix<MA>::value,
             bool>::Type
    fillRandom(MA &&A);


// namespace flens

#endif // FLENS_MATRIXTYPES_HERMITIAN_IMPL_HEMATRIX_H