1 #ifndef VIENNACL_TRAITS_SIZE_HPP_
2 #define VIENNACL_TRAITS_SIZE_HPP_
30 #ifdef VIENNACL_HAVE_UBLAS
31 #include <boost/numeric/ublas/matrix_sparse.hpp>
32 #include <boost/numeric/ublas/matrix.hpp>
35 #ifdef VIENNACL_HAVE_EIGEN
37 #include <Eigen/Sparse>
40 #ifdef VIENNACL_HAVE_MTL4
41 #include <boost/numeric/mtl/mtl.hpp>
55 template <
typename MatrixType>
58 matrix.resize(rows, cols);
61 template <
typename VectorType>
62 void resize(VectorType & vec,
size_t new_size)
67 #ifdef VIENNACL_HAVE_UBLAS
69 template <
typename ScalarType>
70 void resize(boost::numeric::ublas::compressed_matrix<ScalarType> &
matrix,
74 matrix.resize(rows, cols,
false);
79 #ifdef VIENNACL_HAVE_MTL4
80 template <
typename ScalarType>
81 void resize(mtl::compressed2D<ScalarType> & matrix,
85 matrix.change_dim(rows, cols);
88 template <
typename ScalarType>
89 void resize(mtl::dense_vector<ScalarType> & vec,
92 vec.change_dim(new_size);
96 #ifdef VIENNACL_HAVE_EIGEN
97 inline void resize(Eigen::MatrixXf & m,
101 m.resize(new_rows, new_cols);
104 inline void resize(Eigen::MatrixXd & m,
105 std::size_t new_rows,
106 std::size_t new_cols)
108 m.resize(new_rows, new_cols);
111 template <
typename T,
int options>
112 inline void resize(Eigen::SparseMatrix<T, options> & m,
113 std::size_t new_rows,
114 std::size_t new_cols)
116 m.resize(new_rows, new_cols);
119 inline void resize(Eigen::VectorXf & v,
120 std::size_t new_size)
125 inline void resize(Eigen::VectorXd & v,
126 std::size_t new_size)
136 template <
typename VectorType>
142 #ifdef VIENNACL_HAVE_MTL4
143 template <
typename ScalarType>
145 size(mtl::dense_vector<ScalarType>
const & vec) {
return vec.used_memory(); }
148 #ifdef VIENNACL_HAVE_EIGEN
149 inline std::size_t
size(Eigen::VectorXf
const & v) {
return v.rows(); }
150 inline std::size_t
size(Eigen::VectorXd
const & v) {
return v.rows(); }
156 template <
typename MatrixType>
157 typename result_of::size_type<MatrixType>::type
158 size1(MatrixType
const & mat) {
return mat.size1(); }
160 #ifdef VIENNACL_HAVE_EIGEN
161 inline std::size_t
size1(Eigen::MatrixXf
const & m) {
return m.rows(); }
162 inline std::size_t
size1(Eigen::MatrixXd
const & m) {
return m.rows(); }
163 template <
typename T,
int options>
164 inline std::size_t
size1(Eigen::SparseMatrix<T, options> & m) {
return m.rows(); }
170 template <
typename MatrixType>
171 typename result_of::size_type<MatrixType>::type
172 size2(MatrixType
const & mat) {
return mat.size2(); }
174 #ifdef VIENNACL_HAVE_EIGEN
175 inline std::size_t
size2(Eigen::MatrixXf
const & m) {
return m.cols(); }
176 inline std::size_t
size2(Eigen::MatrixXd
const & m) {
return m.cols(); }
177 template <
typename T,
int options>
178 inline std::size_t
size2(Eigen::SparseMatrix<T, options> & m) {
return m.cols(); }
184 template <
typename VectorType>
185 typename result_of::size_type<VectorType>::type
188 return vec.internal_size();
191 template <
typename VectorType>
195 return vec.
get().internal_size();
201 template <
typename MatrixType>
205 template <
typename MatrixType>
212 template <
typename MatrixType>
216 template <
typename MatrixType>