In my application,I need to specialize some of my routines for ViennaCL, and therefore, I need to know
EITHER: a base class of all vector/matrix expressions so that I can test against std::is_base_of<???,Expr>::value
OR: a common type/attribute of all vector/matrix expressions, so that I can specialize using the presence of that type/attribute
AND: the optimal return type (here: vector and double)
Best regads,
Matthias
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
the following is for ViennaCL 1.x.y:
For vector expressions (including operations where the operands may not be vectors, but the result is a vector) such as v1 + v2, the return type is viennacl::vector_expression<LHS, RHS, OP>
For matrix expressions the respective type is viennacl::matrix_expression<LHS, RHS, OP>.
In a few cases there are also scalar expressions used (e.g. dot products), where the return type is viennacl::scalar_expression<LHS, RHS, OP>.
The common base class for vectors and vector proxy objects is viennacl::vector_base<T>, for dense matrices it is viennacl::matrix_base<T>. Currently there is no common type for sparse matrices, but this may change.
ViennaCL 2.0.0 with see a complete redesign (second half of 2016), so don't expect these types to be still in use then.
Best regards,
Karli
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
the return type deduction (following your definition of a return type above) is as follows: For vector_expression<> it is always a vector<>, for matrix_expression it is always a matrix<>. Same for scalar_expression and scalar<>.
Dear all,
is it possible to deduce the optimal return type from a vector or matrix expression?
Please consider the following demo code:
In my application,I need to specialize some of my routines for ViennaCL, and therefore, I need to know
EITHER: a base class of all vector/matrix expressions so that I can test against std::is_base_of<???,Expr>::value
OR: a common type/attribute of all vector/matrix expressions, so that I can specialize using the presence of that type/attribute
AND: the optimal return type (here: vector and double)
Best regads,
Matthias
Hi,
the following is for ViennaCL 1.x.y:
For vector expressions (including operations where the operands may not be vectors, but the result is a vector) such as v1 + v2, the return type is
viennacl::vector_expression<LHS, RHS, OP>
For matrix expressions the respective type is
viennacl::matrix_expression<LHS, RHS, OP>
.In a few cases there are also scalar expressions used (e.g. dot products), where the return type is
viennacl::scalar_expression<LHS, RHS, OP>
.The common base class for vectors and vector proxy objects is
viennacl::vector_base<T>
, for dense matrices it isviennacl::matrix_base<T>
. Currently there is no common type for sparse matrices, but this may change.ViennaCL 2.0.0 with see a complete redesign (second half of 2016), so don't expect these types to be still in use then.
Best regards,
Karli
Hi,
thank you very much for this information. What I would need is a mechanism to deduce the return type from an expression, e.g.
It would also suffice if I can extract the type (matrix/vector) and the data type (float/double) separately.
Best regards,
Matthias
Hi,
the return type deduction (following your definition of a return type above) is as follows: For vector_expression<> it is always a vector<>, for matrix_expression it is always a matrix<>. Same for scalar_expression and scalar<>.
You can obtain the data type via
(I think this is what you were asking for. Please let me know if that does not answer your question.)
Best regards,
Karli