Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
asr_to_csr.h
Go to the documentation of this file.
1#ifndef _ASR_TO_CSR_H
2#define _ASR_TO_CSR_H
23
25namespace rheolef {
26/*F:
27NAME: asr_to_csr -- sequential sparse matrix convertion (@PACKAGE@ @VERSION@)
28DESCRIPTION:
29 Convert sequential "asr" to sequential "csr" sparse matrix format.
30ALGORITHM:
31 asr_to_csr
32
33 "input": the sparse asr matrix, predicate and operator
34 | ia(0:2*nrow+1), a(0:nnz-1),
35 | pred(.), op(.)
36 "output": the sparse csr matrix
37 | ib(0:nrow-1), b(0:nnz-1)
38 begin
39 | ib(0) := q := 0
40 | for i := 0 to nrow-1 do
41 | for p := ia(2*i) to ia(2*i+1)-1 do
42 | if pred(a(p)) then
43 | b(q) := op(a(p))
44 | q := q + 1
45 | endif
46 | endfor
47 | ib(i+1) := q
48 | endfor
49 end
50COMPLEXITY:
51 Time and memory complexity is O(nnz).
52NOTE:
53 The output arrays are supposed to be coorectly allocated,
54 i.e. large enough.
55METHODS: @asr_to_csr
56AUTHORS:
57 LMC-IMAG, 38041 Grenoble cedex 9, France
58 | Pierre.Saramito@imag.fr
59DATE: 22 march 1999
60END:
61*/
62//<asr_to_csr:
63template<
64 class InputPtrIterator,
65 class Predicate,
66 class Operation,
67 class OutputPtrIterator,
68 class OutputDataIterator>
69OutputPtrIterator
71 InputPtrIterator iter_ptr_a,
72 InputPtrIterator last_ptr_a,
73 Predicate pred,
74 Operation op,
75 OutputPtrIterator iter_ptr_b,
76 OutputDataIterator iter_data_b)
77{
78 typedef typename std::iterator_traits<InputPtrIterator>::value_type Row;
79 typedef typename Row::const_iterator DataIterator;
80
81 (*iter_ptr_b++) = get_pointer_from_iterator(iter_data_b);
82 while (iter_ptr_a != last_ptr_a) {
83 const Row& row_i = *iter_ptr_a;
84 DataIterator iter_data_a = row_i.begin();
85 DataIterator last_data_a = row_i.end();
86 while (iter_data_a != last_data_a) {
87 if (pred(*iter_data_a))
88 (*iter_data_b++) = op(*iter_data_a);
89 iter_data_a++;
90 }
91 (*iter_ptr_b++) = get_pointer_from_iterator(iter_data_b);
92 iter_ptr_a++;
93 }
94 return iter_ptr_b;
95}
96//>asr_to_csr:
97} // namespace rheolef
98#endif // _ASR_TO_CSR_H
This file is part of Rheolef.
std::iterator_traits< Iterator >::pointer get_pointer_from_iterator(Iterator iter)
OutputPtrIterator asr_to_csr(InputPtrIterator iter_ptr_a, InputPtrIterator last_ptr_a, Predicate pred, Operation op, OutputPtrIterator iter_ptr_b, OutputDataIterator iter_data_b)
Definition asr_to_csr.h:70