While using the it++ library, I realized there is no concat() functionality for sparse vectors. This would be very helpful in my situation.
Suggestion for implementation: (Warning: I'm new to C++) to include in base/svec.h
template <class T> Sparse_Vec<T> concat(const Sparse_Vec<T>& v1, const Sparse_Vec<T>& v2) { int vs1 = v1.v_size; int vs2 = v2.v_size; int ds1 = v1.data_size; int ds2 = v2.data_size; int us1 = v1.used_size; int us2 = v2.used_size; // create new vector Sparse_Vec<T> temp(vs1+vs2,ds1+ds2); // copy data copy_vector(us1, v1.data, temp.data); copy_vector(us2, v2.data, &temp.data[us1]); // adjust indices copy_vector(us1, v1.index, temp.index); // update used size temp.used_size = us1+us2; // append indices for(int i=0;i<us2;i++){ temp.index[us1+i] = vs1 + v2.index[i]; } return temp; }
Log in to post a comment.
Suggestion for implementation: (Warning: I'm new to C++) to include in base/svec.h