36 for(
int i=0; i<num; ++i)
add_entry(vec, eqns[i], coefs[i]);
41 std::vector<int>& v_ind = vec.
indices();
42 std::vector<double>& v_coef = vec.
coefs();
44 std::vector<int>::iterator
45 iter = std::lower_bound(v_ind.begin(), v_ind.end(), eqn);
47 size_t offset = iter - v_ind.begin();
49 if (iter == v_ind.end() || *iter != eqn) {
50 v_ind.insert(iter, eqn);
51 v_coef.insert(v_coef.begin()+offset, coef);
54 v_coef[offset] = coef;
60 const std::vector<int>& v_ind = vec.
indices();
61 const std::vector<double>& v_coef = vec.
coefs();
63 if (vec.
size() == 0) {
64 throw std::runtime_error(
"get_entry error, CSVec is empty");
67 std::vector<int>::const_iterator
68 iter = std::lower_bound(v_ind.begin(), v_ind.end(), eqn);
70 if (iter == v_ind.end()) {
71 throw std::runtime_error(
"get_entry error, entry not found.");
74 return v_coef[iter - v_ind.begin()];
79 std::vector<int>& v_ind = vec.
indices();
80 std::vector<double>& v_coef = vec.
coefs();
82 std::vector<int>::iterator
83 iter = std::lower_bound(v_ind.begin(), v_ind.end(), eqn);
85 if (iter != v_ind.end() && *iter == eqn) {
86 size_t offset = iter - v_ind.begin();
89 std::vector<double>::iterator coef_iter = v_coef.begin()+offset;
90 v_coef.erase(coef_iter);
96 for(
size_t i=0; i<rhs.
coefs_.size(); ++i) {
103 std::fill(vec.
coefs().begin(), vec.
coefs().end(), scalar);
108 const std::vector<int>& indices = u.
indices();
109 const std::vector<double>& coefs = u.
coefs();
111 for(
size_t i=0; i<indices.size(); ++i) {
void remove_entry(CSVec &vec, int eqn)
void add_entries(CSVec &vec, int num, const int *eqns, const double *coefs)
void subtract(const CSVec &rhs)
std::vector< int > & indices()
void set_values(CSVec &vec, double scalar)
std::vector< int > indices_
std::vector< double > coefs_
void put_entry(CSVec &vec, int eqn, double coef)
CSVec & operator=(const CSVec &invec)
double get_entry(const CSVec &vec, int eqn)
void add_entry(CSVec &vec, int eqn, double coef)
void add_CSVec_CSVec(const CSVec &u, CSVec &v)
std::vector< double > & coefs()