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
<doc  95
      96

      97
<doc  98
      99
<doc 100
     101
<doc 102
     103

     104
<doc 105
     106

     107
<doc 108
     109

     110
     111
     112
<doc 113
     114

     115
<doc 116
     117
     118

     119
<doc 120
     121
     122

     123
<doc 124
     125
     126

     127
<doc 128
     129

     130
<doc 131
     132

     133
<doc 134
     135

     136
<doc 137
     138

     139
<doc 140
     141

     142
<doc 143
     144

     145
<doc 146
     147

     148
     149
<doc 150
     151

     152
<doc 153
     154

     155
     156
<doc 157
     158

     159
<doc 160
     161

     162
     163
<doc 164
     165

     166
<doc 167
     168

     169
     170
<doc 171
     172

     173
<doc 174
     175

     176
<doc 177
     178

     179
<doc 180
     181

     182
     183
     184
     185
     186
<doc 187
     188

     189
<doc 190
     191

     192
<doc 193
     194

     195
<doc 196
     197

     198
<doc 199
     200

     201
<doc 202
     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
     227

     228
<doc 229
     230
     231
     232
     233

     234
<doc 235
     236

     237
<doc 238
     239

     240
     241
<doc 242
     243

     244
<doc 245
     246

     247
<doc 248
     249

     250
<doc 251
     252

     253
<doc 254
     255

     256
<doc 257
     258

     259
     260
     261
     262
     263
     264
     265
     266
     267
     268
     269
<doc 270
     271

     272
<doc 273
     274
     275
     276
     277
     278
     279
     280
     281
     282
     283
     284
     285
<doc 286
     287
     288

     289
     290
     291
     292
     293
     294
     295
<doc 296
     297
     298

     299
     300
     301
     302
     303
     304
     305
     306
     307
<doc 308
     309
     310

     311
     312
     313
     314
     315
     316
     317
     318
     319
     320
/*
 *   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_TRIANGULAR_IMPL_TBMATRIX_H
#define FLENS_MATRIXTYPES_TRIANGULAR_IMPL_TBMATRIX_H 1

#include <cxxblas/typedefs.h>
#include <flens/auxiliary/auxiliary.h>
#include <flens/matrixtypes/triangular/triangularmatrix.h>
#include <flens/typedefs.h>

namespace flens {

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

template <typename FS>
    class GbMatrix;

template <typename FS>
    class HbMatrix;

template <typename FS>
    class SbMatrix;

template <typename FS>
class TbMatrix
    : public TriangularMatrix<TbMatrix<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 for
        typedef DenseVector<ConstArrayView>         ConstVectorView;
        typedef DenseVector<ArrayView>              VectorView;
        typedef DenseVector<Array>                  Vector;

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

        typedef HbMatrix<EngineConstView>           ConstHermitianView;
        typedef HbMatrix<EngineView>                HermitianView;
        typedef HbMatrix<EngineNoView>              HermitianNoView;

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

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

        TbMatrix(IndexType dim, StorageUpLo upLo, IndexType numOffDiags,
                 Diag diag = NonUnit);

        TbMatrix(const Engine &engine, StorageUpLo upLo, Diag diag = NonUnit);

        TbMatrix(const TbMatrix &rhs);

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

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

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

        // -- operators --------------------------------------------------------

        TbMatrix &
        operator=(const TbMatrix &rhs);

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

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

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

        TbMatrix<FS> &
        operator=(const ElementType &alpha);

        TbMatrix<FS> &
        operator+=(const ElementType &alpha);

        TbMatrix<FS> &
        operator-=(const ElementType &alpha);

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

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

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

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

        // general views
        const ConstGeneralView
        general() const;

        GeneralView
        general();

        // hermitian views
        const ConstHermitianView
        hermitian() const;

        HermitianView
        hermitian();

        // symmetric views
        const ConstSymmetricView
        symmetric() const;

        SymmetricView
        symmetric();

        // triangular view
        const ConstView
        triangular() const;

        View
        triangular();

        VectorView
        viewDiag(IndexType diag = IndexType(0));

        const ConstVectorView
        viewDiag(IndexType diag = IndexType(0)) const;

        // -- views ------------------------------------------------------------


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

        IndexType
        numCols() const;

        IndexType
        numRows() const;

        IndexType
        numOffDiags() const;

        IndexType
        numSubDiags() const;

        IndexType
        numSuperDiags() const;

        // for element access
        IndexType
        firstIndex() const;

        IndexType
        lastIndex() const;

        IndexType
        leadingDimension() const;

        StorageOrder
        order() const;

        const ElementType *
        data() const;

        ElementType *
        data();

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

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

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

        bool
        fillRandom();

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

        Engine &
        engine();

        StorageUpLo
        upLo() const;

        StorageUpLo &
        upLo();

        Diag
        diag() const;

        Diag &
        diag();

    private:
        Engine       _engine;
        StorageUpLo  _upLo;
        Diag         _diag;
};

//-- Traits --------------------------------------------------------------------
//
//  IsTbMatrix
//
struct _TbMatrixChecker
{

    struct Two {
        char x;
        char y;
    };

    static Two
    check(_AnyConversion);

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

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

//
//  IsRealTbMatrix
//
template <typename T>
struct IsRealTbMatrix
{
    typedef typename std::remove_reference<T>::type  TT;

    static const bool value = IsTbMatrix<TT>::value
                           && IsNotComplex<typename TT::ElementType>::value;
};

//
//  IsComplexTbMatrix
//
template <typename T>
struct IsComplexTbMatrix
{
    typedef typename std::remove_reference<T>::type  TT;

    static const bool value = IsTbMatrix<TT>::value
                           && IsComplex<typename TT::ElementType>::value;
};


// namespace flens

#endif // FLENS_MATRIXTYPES_TRIANGULAR_IMPL_TBMATRIX_H