In the current implementation of sparse vectors, it is difficult to use the svec class using constant references which is a problem if you write code that try to comply with the const correctness coding style.
The problem arise because of the lack of const versions of the member functions:
void get_nz_data(int p, T& data_out);
T get_nz_data(int p);
That is, the lack of:
double Sparse_Vec<T>::density() const;
int nnz() const;
void get_nz_data(int p, const T& data_out) const;
T get_nz_data(int p) const;
ivec get_nz_indices() const;
I get that the problem arise because each of these functions call the non-const function remove_small_elements() in case the check_small_elems_flag is set.
In the end I guess it's all about how to interprete elements less then epsilon. In my (humble) opinion, elements less than epsilon should allways be interpreted as zero - thus, the objective state is unchanged when the remove_small_elementes() function is called. This off-cource has the implication that an output function must ensure that an element less than epsilon is never returned...
With this mindset, remove_small_elements(), can be interpreted as a const function, and the affected member variables should be mutable... (including data, check_small_elems_flag, and used_size)
Log in to post a comment.