1 /* 2 * Copyright (c) 2006 Michael Stevens 3 * Use, modification and distribution are subject to the 4 * Boost Software License, Version 1.0. (See accompanying file 5 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 */ 7 8 #include <iostream> 9 10 #include <boost/numeric/ublas/vector_sparse.hpp> 11 12 typedef double Real; 13 14 template <class V> printV(const V & v)15void printV(const V& v) { 16 std::cout << "size: " << v.size() << " nnz_capacity: " << v.nnz_capacity() << " nnz: " << v.nnz() << std::endl; 17 for (typename V::const_iterator i = v.begin(); i != v.end(); i++) { 18 std::cout << i.index() << ":" << (*i) << " "; 19 } 20 std::cout << std::endl; 21 } 22 23 template <class V> run_test()24void run_test() 25 { 26 V v(10); 27 28 v[0] = 1; 29 v[5] = 1; 30 v[8] = 1; 31 v[9] = 1; 32 33 printV(v); 34 35 v.resize(9); printV(v); 36 v.resize(12); printV(v); 37 v.resize(2); printV(v); 38 v.resize(0); printV(v); 39 40 v.resize(5); v[0] = 1; printV(v); 41 v.resize(5,false); printV(v); 42 } 43 main(int,char **)44int main(int, char **) { 45 46 std::cout << "---- MAPPED ----\n"; 47 run_test< boost::numeric::ublas::mapped_vector<Real> >(); 48 std::cout << "---- COMPRESSED ----\n"; 49 run_test< boost::numeric::ublas::compressed_vector<Real> >(); 50 std::cout << "---- COORDINATE ----\n"; 51 run_test< boost::numeric::ublas::coordinate_vector<Real> >(); 52 53 return 0; 54 } 55 56