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
<doc  53
      54
      55
      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
<doc  90
      91
<doc  92
      93
<doc  94
      95
<doc  96
      97

      98
<doc  99
     100

     101
<doc 102
     103

     104
     105
     106
<doc 107
     108

     109
<doc 110
     111

     112
<doc 113
     114
     115

     116
<doc 117
     118
     119

     120
<doc 121
     122
     123

     124
<doc 125
     126

     127
<doc 128
     129

     130
<doc 131
     132

     133
<doc 134
     135

     136
<doc 137
     138

     139
<doc 140
     141

     142
     143
     144
<doc 145
     146

     147
<doc 148
     149

     150
<doc 151
     152

     153
<doc 154
     155

     156
<doc 157
     158

     159
<doc 160
     161

     162
<doc 163
     164

     165
<doc 166
     167

     168
<doc 169
     170

     171
<doc 172
     173

     174
<doc 175
     176

     177
<doc 178
     179

     180
<doc 181
     182

     183
<doc 184
     185

     186
<doc 187
     188
     189
     190

     191
<doc 192
     193
     194
     195

     196
     197
     198
     199
<doc 200
     201

     202
<doc 203
     204

     205
     206
<doc 207
     208

     209
<doc 210
     211

     212
     213
<doc 214
     215

     216
<doc 217
     218

     219
     220
     221
<doc 222
     223

     224
<doc 225
     226

     227
     228
     229
     230
     231
     232
     233
     234
     235
     236
<doc 237
     238

     239
<doc 240
     241
     242
     243
     244
     245
     246
     247
     248
     249
     250
     251
     252
<doc 253
     254
     255

     256
     257
     258
     259
     260
     261
     262
/*
 *   Copyright (c) 2012, Michael Lehn, Klaus Pototzky
 *
 *   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_HPMATRIX_H
#define FLENS_MATRIXTYPES_HERMITIAN_IMPL_HPMATRIX_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 PS>
    class SpMatrix;

template <typename PS>
    class TpMatrix;

template <typename PS>
class HpMatrix
    : public HermitianMatrix<HpMatrix<PS> >
{
    public:
        typedef PS                                  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 HpMatrix<EngineConstView>           ConstView;
        typedef HpMatrix<EngineView>                View;
        typedef HpMatrix<EngineNoView>              NoView;

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

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

        //-- Constructors ------------------------------------------------------

        HpMatrix(IndexType dim, StorageUpLo upLo = Upper);

        HpMatrix(const Engine &engine, StorageUpLo upLo);

        HpMatrix(const HpMatrix &rhs);

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

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

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

        //-- Operators ---------------------------------------------------------

        void
        operator=(const ElementType &alpha);

        HpMatrix &
        operator=(const HpMatrix &rhs);

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

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

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

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

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

        HpMatrix &
        operator+=(const ElementType &alpha);

        HpMatrix &
        operator-=(const ElementType &alpha);

        HpMatrix &
        operator*=(const ElementType &alpha);

        HpMatrix &
        operator/=(const ElementType &alpha);

        //-- Methods -----------------------------------------------------------

        IndexType
        numRows() const;

        IndexType
        numCols() const;

        IndexType
        dim() const;

        IndexType
        firstRow() const;

        IndexType
        lastRow() const;

        IndexType
        firstCol() const;

        IndexType
        lastCol() const;

        IndexType
        indexBase() const;

        StorageUpLo
        upLo() const;

        StorageUpLo &
        upLo();

        const ElementType *
        data() const;

        ElementType *
        data();

        StorageOrder
        order() const;

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

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

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

        //-- Views -------------------------------------------------------------

        // hermitian views
        const ConstView
        hermitian() const;

        View
        hermitian();

        // symmetric view
        const ConstSymmetricView
        symmetric() const;

        SymmetricView
        symmetric();

        // triangular view
        const ConstTriangularView
        triangular() const;

        TriangularView
        triangular();

        //-- Implementation ----------------------------------------------------

        const Engine &
        engine() const;

        Engine &
        engine();

    private:
        Engine       _engine;
        StorageUpLo  _upLo;
};

//-- Traits --------------------------------------------------------------------
//
//  IsHpMatrix
//
struct _HpMatrixChecker
{

    struct Two {
        char x;
        char y;
    };

    static Two
    check(_AnyConversion);

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

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

// namespace flens

#endif // FLENS_MATRIXTYPES_HERMITIAN_IMPL_HPMATRIX_H