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

      99
<doc 100
     101
<doc 102
     103
<doc 104
     105

     106
<doc 107
     108

     109
<doc 110
     111

     112
     113
     114
<doc 115
     116

     117
<doc 118
     119
     120

     121
<doc 122
     123
     124

     125
<doc 126
     127
     128

     129
<doc 130
     131

     132
<doc 133
     134

     135
<doc 136
     137

     138
<doc 139
     140

     141
<doc 142
     143

     144
<doc 145
     146

     147
<doc 148
     149

     150
     151
     152
     153
     154
     155
<doc 156
     157

     158
<doc 159
     160

     161
<doc 162
     163

     164
<doc 165
     166

     167
     168
<doc 169
     170

     171
<doc 172
     173

     174
<doc 175
     176

     177
<doc 178
     179

     180
     181
     182
<doc 183
     184

     185
<doc 186
     187

     188
<doc 189
     190

     191
<doc 192
     193

     194
     195
<doc 196
     197

     198
<doc 199
     200

     201
<doc 202
     203

     204
<doc 205
     206

     207
     208
<doc 209
     210

     211
<doc 212
     213

     214
<doc 215
     216

     217
<doc 218
     219

     220
     221
<doc 222
     223

     224
<doc 225
     226

     227
     228
     229
<doc 230
     231

     232
<doc 233
     234

     235
<doc 236
     237

     238
<doc 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
<doc 260
     261

     262
<doc 263
     264

     265
<doc 266
     267

     268
<doc 269
     270

     271
<doc 272
     273
     274
     275

     276
<doc 277
     278
     279
     280
     281

     282
<doc 283
     284

     285
<doc 286
     287

     288
     289
     290
<doc 291
     292

     293
<doc 294
     295

     296
     297
     298
     299
     300
     301
     302
     303
     304
<doc 305
     306

     307
<doc 308
     309
     310
     311
     312
     313
     314
     315
     316
     317
     318
     319
     320
<doc 321
     322
     323

     324
     325
     326
     327
     328
     329
     330
<doc 331
     332
     333

     334
     335
     336
     337
     338
     339
     340
     341
     342
<doc 343
     344
     345

     346
     347
     348
     349
     350
     351
     352
     353
     354
/*
 *   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_GENERAL_IMPL_GBMATRIX_H
#define FLENS_MATRIXTYPES_GENERAL_IMPL_GBMATRIX_H 1

#include <flens/auxiliary/auxiliary.h>
#include <flens/typedefs.h>
#include <flens/matrixtypes/general/generalmatrix.h>
#include <flens/typedefs.h>
#include <ulmblas/cxxblas.h>

namespace flens {

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

template <typename FS>
    class TbMatrix;

template <typename FS>
    class GeMatrix;

template <typename FS>
class GbMatrix
    : public GeneralMatrix<GbMatrix<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;

        typedef typename Engine::ConstFullStorageView   ConstFullStorageView;
        typedef typename Engine::FullStorageView        FullStorageView;
        typedef typename Engine::FullStorage            FullStorage;

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

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

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

        typedef GeMatrix<ConstFullStorageView>      ConstGeView;
        typedef GeMatrix<FullStorageView>           GeView;
        typedef GeMatrix<FullStorage>               GeNoView;

        GbMatrix();

        explicit
        GbMatrix(IndexType m, IndexType n,
                 IndexType numSubDiags, IndexType numSuperDiags,
                 IndexType firstIndex = Engine::defaultIndexBase);

        GbMatrix(const Engine &engine);

        GbMatrix(const GbMatrix &rhs);

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

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

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

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

        GbMatrix &
        operator=(const GbMatrix &rhs);

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

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

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

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

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

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

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

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

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

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

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

        // triangular views

        // upper
        const ConstTriangularView
        upper(Diag diag = NonUnit) const;

        TriangularView
        upper(Diag diag = NonUnit);

        const ConstView
        strictUpper() const;

        View
        strictUpper();

        // triangular view
        const ConstTriangularView
        lower(Diag diag = NonUnit) const;

        TriangularView
        lower(Diag diag = NonUnit);

        const ConstView
        strictLower() const;

        View
        strictLower();

        // Diagonals

        const ConstVectorView
        diag(IndexType diag) const;

        VectorView
        diag(IndexType diag);

        const ConstView
        diags(IndexType fromDiag, IndexType toDiag) const;

        View
        diags(IndexType fromDiag, IndexType toDiag);

        // 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);

        // view to the underlying Storage Matrix
        const ConstGeView
        viewStorageGeMatrix() const;

        GeView
        viewStorageGeMatrix();

        // -- methods ----------------------------------------------------------

        IndexType
        numCols() const;

        IndexType
        numRows() const;

        IndexType
        firstCol() const;

        IndexType
        lastCol() const;

        IndexType
        firstRow() const;

        IndexType
        lastRow() const;

        IndexType
        firstIndex() const;

        IndexType
        lastIndex() const;

        IndexType
        numSubDiags() const;

        IndexType
        numSuperDiags() const;

        IndexType
        leadingDimension() const;

        StorageOrder
        order() const;

        const ElementType *
        data() const;

        ElementType *
        data();

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

        bool
        resize(IndexType numRow, IndexType numCols,
               IndexType numSubDiags, IndexType numSuperDiags,
               IndexType firstIndex = Engine::defaultIndexBase,
               const ElementType &value = ElementType());

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

        bool
        fillRandom();

        // -- implementation ---------------------------------------------------

        const Engine &
        engine() const;

        Engine &
        engine();

    private:
        Engine       engine_;
};

//-- Traits --------------------------------------------------------------------
//
//  IsGbMatrix
//
struct GbMatrixChecker_
{

    struct Two {
        char x;
        char y;
    };

    static Two
    check(AnyConversion_);

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

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

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

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

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

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

// namespace flens

#endif // FLENS_MATRIXTYPES_GENERAL_IMPL_GBMATRIX_H