1 #ifndef VIENNACL_TRAITS_SIZE_HPP_
2 #define VIENNACL_TRAITS_SIZE_HPP_
32 #ifdef VIENNACL_WITH_UBLAS
33 #include <boost/numeric/ublas/matrix_sparse.hpp>
34 #include <boost/numeric/ublas/matrix.hpp>
37 #ifdef VIENNACL_WITH_EIGEN
39 #include <Eigen/Sparse>
42 #ifdef VIENNACL_WITH_MTL4
43 #include <boost/numeric/mtl/mtl.hpp>
58 template <
typename MatrixType>
61 matrix.resize(rows, cols);
65 template <
typename VectorType>
72 #ifdef VIENNACL_WITH_UBLAS
74 template <
typename ScalarType>
75 void resize(boost::numeric::ublas::compressed_matrix<ScalarType> &
matrix,
79 matrix.resize(rows, cols,
false);
84 #ifdef VIENNACL_WITH_MTL4
85 template <
typename ScalarType>
86 void resize(mtl::compressed2D<ScalarType> & matrix,
90 matrix.change_dim(rows, cols);
93 template <
typename ScalarType>
94 void resize(mtl::dense_vector<ScalarType> & vec,
97 vec.change_dim(new_size);
101 #ifdef VIENNACL_WITH_EIGEN
102 inline void resize(Eigen::MatrixXf & m,
106 m.resize(new_rows, new_cols);
109 inline void resize(Eigen::MatrixXd & m,
113 m.resize(new_rows, new_cols);
116 template <
typename T,
int options>
117 inline void resize(Eigen::SparseMatrix<T, options> & m,
121 m.resize(new_rows, new_cols);
124 inline void resize(Eigen::VectorXf & v,
130 inline void resize(Eigen::VectorXd & v,
143 template <
typename VectorType>
150 template <
typename SparseMatrixType,
typename VectorType>
155 return proxy.
lhs().size1();
158 template <
typename T,
unsigned int A,
typename VectorType>
159 vcl_size_t size(vector_expression<
const circulant_matrix<T, A>,
const VectorType, op_prod>
const & proxy) {
return proxy.
lhs().size1(); }
161 template <
typename T,
unsigned int A,
typename VectorType>
162 vcl_size_t size(vector_expression<
const hankel_matrix<T, A>,
const VectorType, op_prod>
const & proxy) {
return proxy.
lhs().size1(); }
164 template <
typename T,
unsigned int A,
typename VectorType>
165 vcl_size_t size(vector_expression<
const toeplitz_matrix<T, A>,
const VectorType, op_prod>
const & proxy) {
return proxy.
lhs().size1(); }
167 template <
typename T,
unsigned int A,
typename VectorType>
168 vcl_size_t size(vector_expression<
const vandermonde_matrix<T, A>,
const VectorType, op_prod>
const & proxy) {
return proxy.
lhs().size1(); }
170 template <
typename NumericT,
typename F>
171 vcl_size_t size(vector_expression<
const matrix_base<NumericT, F>,
const vector_base<NumericT>, op_prod>
const & proxy)
173 return proxy.
lhs().size1();
176 template <
typename NumericT,
typename F>
177 vcl_size_t size(vector_expression<
const matrix_expression<
const matrix_base<NumericT, F>,
const matrix_base<NumericT, F>, op_trans>,
178 const vector_base<NumericT>,
179 op_prod>
const & proxy)
181 return proxy.
lhs().lhs().size2();
185 #ifdef VIENNACL_WITH_MTL4
186 template <
typename ScalarType>
187 vcl_size_t size(mtl::dense_vector<ScalarType>
const & vec) {
return vec.used_memory(); }
190 #ifdef VIENNACL_WITH_EIGEN
191 inline vcl_size_t size(Eigen::VectorXf
const & v) {
return v.rows(); }
192 inline vcl_size_t size(Eigen::VectorXd
const & v) {
return v.rows(); }
195 template <
typename LHS,
typename RHS,
typename OP>
198 return size(proxy.lhs());
201 template <
typename LHS,
typename RHS>
202 vcl_size_t size(vector_expression<LHS,
const vector_tuple<RHS>, op_inner_prod>
const & proxy)
204 return proxy.rhs().const_size();
214 template <
typename MatrixType>
216 size1(MatrixType
const & mat) {
return mat.size1(); }
219 template <
typename RowType>
221 size1(std::vector< RowType >
const & mat) {
return mat.size(); }
223 #ifdef VIENNACL_WITH_EIGEN
226 template <
typename T,
int options>
230 #ifdef VIENNACL_WITH_MTL4
231 template <
typename SCALARTYPE,
typename T>
233 template <
typename SCALARTYPE>
243 template <
typename MatrixType>
244 typename result_of::size_type<MatrixType>::type
245 size2(MatrixType
const & mat) {
return mat.size2(); }
248 #ifdef VIENNACL_WITH_EIGEN
249 inline vcl_size_t size2(Eigen::MatrixXf
const & m) {
return m.cols(); }
250 inline vcl_size_t size2(Eigen::MatrixXd
const & m) {
return m.cols(); }
251 template <
typename T,
int options>
252 inline vcl_size_t size2(Eigen::SparseMatrix<T, options> & m) {
return m.cols(); }
255 #ifdef VIENNACL_WITH_MTL4
256 template <
typename SCALARTYPE,
typename T>
258 template <
typename SCALARTYPE>
267 template <
typename NumericT>
278 template <
typename NumericT,
typename F>
286 template <
typename NumericT,
typename F>
290 template <
typename LHS>
294 int A_size1 =
static_cast<int>(
size1(proxy.
lhs()));
295 int A_size2 =
static_cast<int>(
size2(proxy.
lhs()));
297 int row_depth = std::min(A_size1, A_size1 + k);
298 int col_depth = std::min(A_size2, A_size2 - k);
300 return std::min(row_depth, col_depth);
303 template <
typename LHS>
309 template <
typename LHS>
Simple enable-if variant that uses the SFINAE pattern.
Definition: enable_if.hpp:29
std::size_t vcl_size_t
Definition: forwards.h:58
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
Definition: size.hpp:216
lhs_reference_type lhs() const
Get left hand side operand.
Definition: vector.hpp:181
A dense matrix class.
Definition: forwards.h:293
Common base class for dense vectors, vector ranges, and vector slices.
Definition: forwards.h:205
This file provides the forward declarations for the main types used within ViennaCL.
vcl_size_t internal_size(vector_base< NumericT > const &vec)
Helper routine for obtaining the buffer length of a ViennaCL vector.
Definition: size.hpp:268
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
Definition: size.hpp:245
size_type internal_size2() const
Returns the internal number of columns. Usually required for launching OpenCL kernels only...
Definition: matrix.hpp:649
A dense matrix class.
Definition: forwards.h:290
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:29
size_type internal_size() const
Returns the internal length of the vector, which is given by size() plus the extra memory due to padd...
Definition: vector.hpp:841
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:144
void resize(MatrixType &matrix, vcl_size_t rows, vcl_size_t cols)
Generic resize routine for resizing a matrix (ViennaCL, uBLAS, etc.) to a new size/dimension.
Definition: size.hpp:59
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:181
vcl_size_t internal_size2(matrix_base< NumericT, F > const &mat)
Helper routine for obtaining the internal number of entries per column of a ViennaCL matrix...
Definition: size.hpp:287
All the predicates used within ViennaCL. Checks for expressions to be vectors, etc.
rhs_reference_type rhs() const
Get right hand side operand.
Definition: vector.hpp:184
vcl_size_t internal_size1(matrix_base< NumericT, F > const &mat)
Helper routine for obtaining the internal number of entries per row of a ViennaCL matrix...
Definition: size.hpp:279
size_type internal_size1() const
Returns the internal number of rows. Usually required for launching OpenCL kernels only...
Definition: matrix.hpp:647
A collection of compile time type deductions.