1 #ifndef _fei_CSVec_hpp_
2 #define _fei_CSVec_hpp_
12 #include <fei_macros.hpp>
31 std::vector<int>& indices() {
return indices_;}
32 const std::vector<int>& indices()
const {
return indices_;}
33 std::vector<double>& coefs() {
return coefs_;}
34 const std::vector<double>& coefs()
const {
return coefs_;}
36 size_t size()
const {
return indices_.size();}
38 void clear() { indices_.clear(); coefs_.clear(); }
40 bool operator==(
const CSVec& rhs)
const {
41 return indices_==rhs.indices_ && coefs_==rhs.coefs_;
44 bool operator!=(
const CSVec& rhs)
const {
45 return indices_!=rhs.indices_ || coefs_!=rhs.coefs_;
48 void subtract(
const CSVec& rhs);
51 std::vector<int> indices_;
52 std::vector<double> coefs_;
56 void add_entry(
CSVec& vec,
int eqn,
double coef)
58 std::vector<int>& v_ind = vec.indices();
59 std::vector<double>& v_coef = vec.coefs();
61 std::vector<int>::iterator
62 iter = std::lower_bound(v_ind.begin(), v_ind.end(), eqn);
64 size_t offset = iter - v_ind.begin();
66 if (iter == v_ind.end() || *iter != eqn) {
67 v_ind.insert(iter, eqn);
68 v_coef.insert(v_coef.begin()+offset, coef);
71 v_coef[offset] += coef;
76 void add_entries(CSVec& vec,
int num,
const int* eqns,
const double* coefs);
78 void put_entry(CSVec& vec,
int eqn,
double coef);
80 double get_entry(
const CSVec& vec,
int eqn);
82 void remove_entry(CSVec& vec,
int eqn);
84 void set_values(CSVec& vec,
double scalar);
void add_CSVec_CSVec(const CSVec &u, CSVec &v)