1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
<doc 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
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
#include <flens/flens.h>

namespace flens {


///
/// This is a minimalistic user-defined matrix type:
///  - It's a *symmetric type* as we derive it from *SymmetricMatrix*
///  - A FLENS matrix type needs to define at least the two typedefs
///    *IndexType* and *ElementType*
///  - Otherwise this matrix type is pretty useless so far.
///
struct MySyMatrix
    : public SymmetricMatrix<MySyMatrix>
{
    typedef double ElementType;
    typedef int    IndexType;
};

// namespace flens


namespace flens { namespace blas {

///
/// Now we give it some meaning.  We define a matrix-vector product for it
/// where the vector is of type *DenseVector*.  The Operation we define has
/// the form $y \leftarrow \beta y + \alpha A x$.
///
/// *We define this product as if the matrix $A$ has the special tridiagonal
/// form:*
///
///  *--[LATEX]---------------------------------------------*
///  |                                                      |
///  |   \begin{pmatrix}                                    |
///  |    2  & -1     & 0      &        & 0      &  0 \\    |
///  |   -1  & \ddots & \ddots & \ddots &        &  0 \\    |
///  |    0  & \ddots & \ddots & \ddots & \ddots &    \\    |
///  |       & \ddots & \ddots & \ddots & \ddots &  0 \\    |
///  |    0  &        & \ddots & \ddots & \ddots & -1 \\    |
///  |    0  & 0      &        &      0 & -1     &  2       |
///  |   \end{pmatrix}                                      |
///  |                                                      |
///  *------------------------------------------------------*
///
/// The matrix-vector product gets computed by this function.
///
template <typename ALPHA, typename VX, typename BETA, typename VY>
void
mv(const ALPHA &alpha, const MySyMatrix &A, const DenseVector<VX> &x,
   const BETA &beta, DenseVector<VY> &y)
///-
{
    typedef typename DenseVector<VX>::IndexType  IndexType;
    const IndexType n = x.length();

    // we only resize empty left hand sides
    if (y.length()==0) {
        y.resize(n);
    }
    ASSERT(y.length()==n);


    for (IndexType i=1; i<=n; ++i) {
        y(i) = beta*y(i) + alpha*2*x(i);
        if (i>1) {
            y(i) -= alpha*x(i-1);
        }
        if (i<n) {
            y(i) -= alpha*x(i+1);
        }
    }
}

} } // namespace blas, flens