~ubuntu-branches/ubuntu/trusty/rheolef/trusty-proposed

« back to all changes in this revision

Viewing changes to skit/lib/csr-algo-trans-mult.h

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2010-06-12 09:08:59 UTC
  • Revision ID: james.westby@ubuntu.com-20100612090859-8gpm2gc7j3ab43et
Tags: upstream-5.89
ImportĀ upstreamĀ versionĀ 5.89

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ifndef _SKIT_CSR_ALGO_TRANS_MULT_H
 
2
# define _SKIT_CSR_ALGO_TRANS_MULT_H
 
3
///
 
4
/// This file is part of Rheolef.
 
5
///
 
6
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
 
7
///
 
8
/// Rheolef is free software; you can redistribute it and/or modify
 
9
/// it under the terms of the GNU General Public License as published by
 
10
/// the Free Software Foundation; either version 2 of the License, or
 
11
/// (at your option) any later version.
 
12
///
 
13
/// Rheolef is distributed in the hope that it will be useful,
 
14
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
/// GNU General Public License for more details.
 
17
///
 
18
/// You should have received a copy of the GNU General Public License
 
19
/// along with Rheolef; if not, write to the Free Software
 
20
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
/// 
 
22
/// =========================================================================
 
23
//
 
24
// CSR: Compressed Sparse Row format
 
25
//
 
26
// algorithm-oriented generic library
 
27
// inspired from sparskit2 fortran library
 
28
//  
 
29
// author: Pierre.Saramito@imag.fr
 
30
//  
 
31
// date: 12 november 1997
 
32
//  
 
33
//@!\vfill\listofalgorithms
 
34
/*@! 
 
35
 \vfill \pagebreak \mbox{} \vfill \begin{algorithm}[h]
 
36
  \caption{{\tt trans\_mult}: sparse matrix $y += a^T*x$, where $x,y$ are dense vectors.}
 
37
  \begin{algorithmic}
 
38
    \INPUT {sparse matrix a and dense vector x}
 
39
      ia(0:nrowa), ja(0:nnza-1), a(0:nnza-1),
 
40
      x(0:nrowa)
 
41
    \ENDINPUT
 
42
    \OUTPUT {number of non-null elements in $z=x\pm y$}
 
43
      y(0:ncola)
 
44
    \ENDOUTPUT
 
45
    \NOTE {}
 
46
      The $y$ vector may be set to zero before the call in order to 
 
47
      compute $y := a^T*x$
 
48
    \ENDNOTE
 
49
    \BEGIN 
 
50
      \FORTO {i := 0}{nrowa-1}
 
51
          \FORTO {p := ia(i)}{ia(i+1)-1}
 
52
              y(ja(p)) += a(p) * x(i)
 
53
          \ENDFOR
 
54
      \ENDFOR
 
55
    \END
 
56
 \end{algorithmic} \end{algorithm}
 
57
 \vfill \pagebreak \mbox{} \vfill
 
58
*/
 
59
template <
 
60
    class InputIterator1,
 
61
    class InputIterator2,
 
62
    class InputIterator3,
 
63
    class InputIterator4,
 
64
    class RandomAccessMutableIterator,
 
65
    class T>
 
66
void
 
67
csr_cumul_trans_mult (
 
68
    InputIterator1 ia,
 
69
    InputIterator1 last_ia,
 
70
    InputIterator2 first_ja,
 
71
    InputIterator3 a,
 
72
    InputIterator4 x,
 
73
    RandomAccessMutableIterator y,
 
74
    const T& dummy)
 
75
{
 
76
    InputIterator2 ja = first_ja + (*ia++);
 
77
    while (ia != last_ia) {
 
78
 
 
79
        T lambda = *x++;
 
80
        InputIterator2 last_ja = first_ja + (*ia++);
 
81
        while (ja != last_ja)
 
82
 
 
83
            y [(*ja++)] += (*a++) * lambda;
 
84
    }
 
85
}
 
86
//@!\vfill
 
87
# endif // _SKIT_CSR_ALGO_TRANS_MULT_H