00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_MATRIX_MULTI_VECTOR_INCLUDE
00013 #define MTL_MATRIX_MULTI_VECTOR_INCLUDE
00014
00015
00016 #include <boost/numeric/mtl/mtl_fwd.hpp>
00017 #include <boost/numeric/mtl/concept/collection.hpp>
00018 #include <boost/numeric/mtl/matrix/parameter.hpp>
00019 #include <boost/numeric/mtl/matrix/crtp_base_matrix.hpp>
00020 #include <boost/numeric/mtl/matrix/mat_expr.hpp>
00021
00022
00023
00024
00025 namespace mtl { namespace matrix {
00026
00027
00028
00029 struct multi_vector_key {};
00030
00032 template <typename Vector>
00033 class multi_vector
00034 : public base_matrix<typename mtl::Collection<Vector>::value_type, parameters<> >,
00035 public crtp_base_matrix< multi_vector<Vector>, typename Collection<Vector>::value_type,
00036 typename Collection<Vector>::size_type>,
00037 public mat_expr< multi_vector<Vector> >
00038 {
00039 typedef base_matrix<typename Collection<Vector>::value_type, parameters<> > super;
00040
00041
00042 BOOST_STATIC_ASSERT((boost::is_same<typename OrientedCollection<Vector>::orientation,
00043 tag::col_major>::value));
00044 public:
00045 typedef multi_vector self;
00046
00047 typedef tag::col_major orientation;
00048 typedef typename Collection<Vector>::value_type value_type;
00049 typedef typename Collection<Vector>::size_type size_type;
00050 typedef const value_type& const_reference;
00051 typedef value_type& reference;
00052 typedef multi_vector_key key_type;
00053 typedef crtp_matrix_assign< self, value_type, size_type > assign_base;
00054
00056 multi_vector(size_type num_rows, size_type num_cols)
00057 : super(non_fixed::dimensions(num_rows, num_cols)),
00058 data(num_cols, Vector(num_rows))
00059 {
00060 this->my_nnz= num_rows * num_cols;
00061 }
00062
00064 multi_vector(size_type num_cols, const Vector& v)
00065 : super(non_fixed::dimensions(size(v), num_cols)),
00066 data(num_cols, v)
00067 {
00068 this->my_nnz= num_cols * size(v);
00069 }
00070
00072 self& operator=(self src)
00073 {
00074
00075 assert(this != &src);
00076
00077 check_dim(src.num_rows(), src.num_cols());
00078 swap(*this, src);
00079 return *this;
00080 }
00081
00082 using assign_base::operator=;
00083
00084 const_reference operator() (size_type i, size_type j) const { return data[j][i]; }
00085 reference operator() (size_type i, size_type j) { return data[j][i]; }
00086
00087 Vector& vector(size_type i) { return data[i]; }
00088 const Vector& vector(size_type i) const { return data[i]; }
00089
00090
00091
00092
00093
00094
00096 friend size_type num_rows(const self& A) { return A.num_rows(); }
00097
00099 friend size_type num_cols(const self& A) { return A.num_cols(); }
00100 protected:
00101
00102 dense_vector<Vector> data;
00103
00104 };
00105
00106
00107 }}
00108
00109
00110 #endif // MTL_MATRIX_MULTI_VECTOR_INCLUDE