Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
csr_cumul_trans_mult.h
Go to the documentation of this file.
1# ifndef _SKIT_CSR_CUMUL_TRANS_MULT_H
2# define _SKIT_CSR_CUMUL_TRANS_MULT_H
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*/
59namespace rheolef {
60
61template <
62 class InputIterator1,
63 class InputIterator3,
64 class SetOperator,
65 class RandomAccessMutableIterator>
66void
68 InputIterator1 ia,
69 InputIterator1 last_ia,
70 InputIterator3 x,
71 SetOperator set_op, // set_op: += or -= but not = because may cumul
72 RandomAccessMutableIterator y)
73{
74 typedef typename std::iterator_traits<InputIterator1>::value_type InputIterator2;
75 typedef typename std::iterator_traits<RandomAccessMutableIterator>::value_type T;
76 InputIterator2 a = (*ia++);
77 while (ia != last_ia) {
78 T xi = *x++;
79 InputIterator2 last_a = (*ia++);
80 while (a != last_a) {
81 set_op (y [(*a).first], (*a).second * xi);
82 ++a;
83 }
84 }
85}
86//@!\vfill
87}// namespace rheolef
88# endif // _SKIT_CSR_CUMUL_TRANS_MULT_H
Expr1::float_type T
Definition field_expr.h:230
This file is part of Rheolef.
void csr_cumul_trans_mult(InputIterator1 ia, InputIterator1 last_ia, InputIterator3 x, SetOperator set_op, RandomAccessMutableIterator y)