22#include "rheolef/csr.h"
23#include "rheolef/asr.h"
24#include "rheolef/asr_to_csr.h"
25#include "rheolef/msg_util.h"
26#include "rheolef/csr_amux.h"
27#include "rheolef/csr_cumul_trans_mult.h"
74 _data.resize (loc_nnz1);
91 ia[0] =
_data.begin().operator->();
92 for (
size_type i = 0, n = b.nrow(); i < n; i++) {
93 ia [i+1] = ia[0] + (ib[i+1] - ib[0]);
101 resize (a.row_ownership(), a.col_ownership(), a.nnz());
102 typedef std::pair<size_type,T>
pair_type;
103 typedef std::pair<size_type,T> const_pair_type;
117 std::ostream& os = ods.
os();
118 os << setprecision (std::numeric_limits<T>::digits10)
119 <<
"%%MatrixMarket matrix coordinate real general" << std::endl
120 <<
nrow() <<
" " <<
ncol() <<
" " <<
nnz() << endl;
125 os << i+first_dis_i+base <<
" "
126 << (*iter).first+base <<
" "
127 << (*iter).second << endl;
136 std::ostream& os = ods.
os();
137 std::string name = iorheo::getbasename(ods.
os());
138 if (name ==
"") name =
"a";
139 os << setprecision (std::numeric_limits<T>::digits10)
140 << name <<
" = spalloc(" <<
nrow() <<
"," <<
ncol() <<
"," <<
nnz() <<
");" << endl;
145 os << name <<
"(" << i+first_dis_i+base <<
"," << (*iter).first+base <<
") = "
146 << (*iter).second <<
";" << endl;
165 std::ofstream os (name.c_str());
166 std::cerr <<
"! file \"" << name <<
"\" created." << std::endl;
181 check_macro (x.size() ==
ncol(),
"csr*vec: incompatible csr("<<
nrow()<<
","<<
ncol()<<
") and vec("<<x.size()<<
")");
186 details::generic_set_op(),
197 check_macro (x.size() ==
nrow(),
"csr.trans_mult(vec): incompatible csr("<<
nrow()<<
","<<
ncol()<<
") and vec("<<x.size()<<
")");
198 std::fill (y.begin(), y.end(),
T(0));
203 details::generic_set_plus_op(),
220template<
class BinaryOp>
227 check_macro (a.nrow() == b.nrow() && a.ncol() == b.ncol(),
228 "incompatible csr add(a,b): a("<<a.nrow()<<
":"<<a.ncol()<<
") and "
229 "b("<<b.nrow()<<
":"<<b.ncol()<<
")");
234 const size_type infty = std::numeric_limits<size_type>::max();
237 for (
size_type i = 0, n = a.nrow(); i < n; i++) {
239 iter_jvb = ib[i], last_jvb = ib[i+1];
240 iter_jva != last_jva || iter_jvb != last_jvb; ) {
242 size_type ja = iter_jva == last_jva ? infty : (*iter_jva).first;
243 size_type jb = iter_jvb == last_jvb ? infty : (*iter_jvb).first;
247 }
else if (ja < jb) {
255 resize (a.row_ownership(), b.col_ownership(), nnz_c);
262 for (
size_type i = 0, n = a.nrow(); i < n; i++) {
264 iter_jvb = ib[i], last_jvb = ib[i+1];
265 iter_jva != last_jva || iter_jvb != last_jvb; ) {
267 size_type ja = iter_jva == last_jva ? infty : (*iter_jva).first;
268 size_type jb = iter_jvb == last_jvb ? infty : (*iter_jvb).first;
270 *iter_jvc++ = std::pair<size_type,T> (ja, binop((*iter_jva).second, (*iter_jvb).second));
273 }
else if (ja < jb) {
274 *iter_jvc++ = std::pair<size_type,T> (ja, binop((*iter_jva).second,
T(0)));
277 *iter_jvc++ = std::pair<size_type,T> (jb, binop(
T(0), (*iter_jvb).second));
350 for (
size_type j = 0, m = b.nrow(); j < m; j++) {
362 for (
size_type j = 0, m = b.nrow(); j < m; j++) {
363 ib [j+1] += (ib[j]-ib[0]);
372 (*q).second = (*p).second;
377 for (
long int j = b.nrow()-1; j >= 0; j--) {
396 d.assign_add (*
this, at, std::minus<T>());
412 for (size_type i = 0, n = a.nrow(); i < n; i++) {
413 std::set<size_type> y;
415 size_type j = (*ap).first;
416 typename std::set<size_type>::iterator iter_y = y.begin();
418 size_type k = (*bp).first;
419 iter_y = y.insert(iter_y, k);
431 const csr_rep<T,sequential>& a,
432 const csr_rep<T,sequential>& b,
433 csr_rep<T,sequential>& c)
438 for (size_type i = 0, n = a.nrow(); i < n; i++) {
439 std::map<size_type,T> y;
440 for (
typename csr<T>::const_data_iterator ap = ia[i], last_ap = ia[i+1]; ap != last_ap; ++ap) {
441 size_type j = (*ap).first;
442 const T& a_ij = (*ap).second;
443 typename std::map<size_type,T>::iterator prev_y = y.begin();
444 for (
typename csr<T>::const_data_iterator bp = ib[j], last_bp = ib[j+1]; bp != last_bp; ++bp) {
445 size_type k = (*bp).first;
446 const T& b_jk = (*bp).second;
448 typename std::map<size_type,T>::iterator curr_y = y.find(k);
449 if (curr_y == y.end()) {
451 y.insert (prev_y, std::pair<size_type,T>(k, value));
454 (*curr_y).second += value;
459 ic[i+1] = ic[i] + y.size();
461 typename std::map<size_type,T>::const_iterator iter_y = y.begin();
467 c.set_pattern_dimension (std::max(
a.pattern_dimension(),
b.pattern_dimension()));
476 resize (a.row_ownership(), b.col_ownership(), nnz_c);
477 csr_csr_mult (a, b, *
this);
482#ifndef _RHEOLEF_USE_HEAP_ALLOCATOR
483#define _RHEOLEF_instanciate_class(T) \
484template void csr_rep<T,sequential>::build_from_asr (const asr<T,sequential,std::allocator<T> >&);
486#define _RHEOLEF_instanciate_class(T) \
487template void csr_rep<T,sequential>::build_from_asr (const asr<T,sequential,std::allocator<T> >&); \
488template void csr_rep<T,sequential>::build_from_asr (const asr<T,sequential,heap_allocator<T> >&);
491#define _RHEOLEF_instanciate(T) \
492template class csr_rep<T,sequential>; \
493template void csr_rep<T,sequential>::assign_add ( \
494 const csr_rep<T,sequential>&, \
495 const csr_rep<T,sequential>&, \
497template void csr_rep<T,sequential>::assign_add ( \
498 const csr_rep<T,sequential>&, \
499 const csr_rep<T,sequential>&, \
501_RHEOLEF_instanciate_class(T)
see the Float page for the full documentation
see the communicator page for the full documentation
size_type _pattern_dimension
vector_of_iterator< pair_type >::const_value_type const_data_iterator
void resize(size_type loc_nrow1=0, size_type loc_ncol1=0, size_type loc_nnz1=0)
const_iterator begin() const
vector_of_iterator< pair_type >::iterator iterator
void set_pattern_dimension(size_type dim) const
odiststream & put_sparse_matlab(odiststream &, size_type istart=0) const
std::vector< std::pair< typename std::vector< T >::size_type, T > > _data
const distributor & col_ownership() const
void set_symmetry(bool is_symm) const
distributor _row_ownership
std::pair< size_type, T > pair_type
std::vector< T >::size_type size_type
void build_transpose(csr_rep< T, sequential > &b) const
vector_of_iterator< pair_type >::value_type data_iterator
bool _is_definite_positive
const distributor & row_ownership() const
void set_definite_positive(bool is_defpos) const
vector_of_iterator< pair_type >::const_iterator const_iterator
distributor _col_ownership
csr_rep(size_type loc_nrow1=0, size_type loc_ncol1=0, size_type loc_nnz1=0)
see the csr page for the full documentation
see the distributor page for the full documentation
static const size_type decide
std::bitset< last > flag_type
static flag_type flags(std::ios &s)
static flag_type format_field
odiststream: see the diststream page for the full documentation
see the vec page for the full documentation
const_reference operator[](size_type i) const
vector_of_iterator(size_type n=0, const value_type &value=value_type())
const_iterator end() const
#define _RHEOLEF_instanciate(T)
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
This file is part of Rheolef.
void csr_amux(InputIterator ia, InputIterator last_ia, InputRandomAcessIterator x, SetOperator set_op, OutputIterator y)
void put(std::ostream &out, std::string name, const tiny_matrix< T > &a)
csr_rep< T, sequential >::size_type csr_csr_mult_size(const csr_rep< T, sequential > &a, const csr_rep< T, sequential > &b)
void put_matrix_market(std::ostream &out, const Eigen::SparseMatrix< T, Eigen::RowMajor > &a)
void csr_cumul_trans_mult(InputIterator1 ia, InputIterator1 last_ia, InputIterator3 x, SetOperator set_op, RandomAccessMutableIterator y)
OutputPtrIterator asr_to_csr(InputPtrIterator iter_ptr_a, InputPtrIterator last_ptr_a, Predicate pred, Operation op, OutputPtrIterator iter_ptr_b, OutputDataIterator iter_data_b)