inline lhs_rhs_element const & extract_representative_vector(statement const & s, lhs_rhs_element const & element) { switch (element.type_family) { case VECTOR_TYPE_FAMILY: return element; case COMPOSITE_OPERATION_FAMILY: { statement_node const & leaf = s.array()[element.node_index]; if (leaf.op.type_family == OPERATION_UNARY_TYPE_FAMILY) return extract_representative_vector(s, leaf.lhs); switch (leaf.op.type) { case OPERATION_BINARY_ADD_TYPE: case OPERATION_BINARY_SUB_TYPE: case OPERATION_BINARY_MULT_TYPE: case OPERATION_BINARY_DIV_TYPE: case OPERATION_BINARY_ELEMENT_PROD_TYPE: case OPERATION_BINARY_ELEMENT_DIV_TYPE: case OPERATION_BINARY_ELEMENT_POW_TYPE: return extract_representative_vector(s, leaf.lhs); case OPERATION_BINARY_MAT_VEC_PROD_TYPE: return extract_representative_vector(s, leaf.rhs); default: throw statement_not_supported_exception("Vector leaf encountered an invalid binary operation!"); } } default: throw statement_not_supported_exception("Vector leaf encountered an invalid node type!"); } }
/** @brief Dispatcher interface for computing s = norm_1(x) */ inline void norm_impl(lhs_rhs_element const & x, lhs_rhs_element const & s, operation_node_type op_type) { assert( x.type_family == VECTOR_TYPE_FAMILY && x.subtype == DENSE_VECTOR_TYPE && bool("Argument is not a dense vector type!")); assert( s.type_family == SCALAR_TYPE_FAMILY && s.subtype == DEVICE_SCALAR_TYPE && bool("Argument is not a scalar type!")); switch (x.numeric_type) { case FLOAT_TYPE: assert(s.numeric_type == FLOAT_TYPE && bool("Vector and scalar do not have the same numeric type")); if (op_type == OPERATION_UNARY_NORM_1_TYPE) viennacl::linalg::norm_1_impl(*x.vector_float, *s.scalar_float); else if (op_type == OPERATION_UNARY_NORM_2_TYPE) viennacl::linalg::norm_2_impl(*x.vector_float, *s.scalar_float); else if (op_type == OPERATION_UNARY_NORM_INF_TYPE) viennacl::linalg::norm_inf_impl(*x.vector_float, *s.scalar_float); else throw statement_not_supported_exception("Invalid norm type in scheduler::detail::norm_impl()"); break; case DOUBLE_TYPE: if (op_type == OPERATION_UNARY_NORM_1_TYPE) viennacl::linalg::norm_1_impl(*x.vector_double, *s.scalar_double); else if (op_type == OPERATION_UNARY_NORM_2_TYPE) viennacl::linalg::norm_2_impl(*x.vector_double, *s.scalar_double); else if (op_type == OPERATION_UNARY_NORM_INF_TYPE) viennacl::linalg::norm_inf_impl(*x.vector_double, *s.scalar_double); else throw statement_not_supported_exception("Invalid norm type in scheduler::detail::norm_impl()"); break; default: throw statement_not_supported_exception("Invalid numeric type in scheduler when calling norm_impl()"); } }
inline void delete_element(lhs_rhs_element & elem) { if (elem.type_family == SCALAR_TYPE_FAMILY) { switch (elem.numeric_type) { case FLOAT_TYPE: delete elem.scalar_float; return; case DOUBLE_TYPE: delete elem.scalar_double; return; default: throw statement_not_supported_exception("Invalid vector type for vector destruction"); } } else if (elem.type_family == VECTOR_TYPE_FAMILY) { switch (elem.numeric_type) { case FLOAT_TYPE: delete elem.vector_float; return; case DOUBLE_TYPE: delete elem.vector_double; return; default: throw statement_not_supported_exception("Invalid vector type for vector destruction"); } } else if (elem.type_family == MATRIX_TYPE_FAMILY) { if (elem.subtype == DENSE_MATRIX_TYPE) { switch (elem.numeric_type) { case FLOAT_TYPE: delete elem.matrix_float; return; case DOUBLE_TYPE: delete elem.matrix_double; return; default: throw statement_not_supported_exception("Invalid vector type for vector destruction"); } } else throw statement_not_supported_exception("Expected a dense matrix in root node when deleting temporary"); } else throw statement_not_supported_exception("Unknown type familty when deleting temporary object"); }
/** @brief Deals with x = y for a vector y */ inline void execute_vector_inplace_add_vector(statement const & s) { typedef statement::container_type StatementContainer; StatementContainer const & expr = s.array(); if (expr[0].lhs_type_ == VECTOR_FLOAT_TYPE && expr[0].rhs_type_ == VECTOR_FLOAT_TYPE) { viennacl::vector_base<float> & x = *(expr[0].lhs_.vector_float_); viennacl::vector_base<float> const & y = *(expr[0].rhs_.vector_float_); viennacl::linalg::avbv(x, x, 1.0, 1, false, false, y, 1.0, 1, false, false); } else if (expr[0].lhs_type_ == VECTOR_DOUBLE_TYPE && expr[0].rhs_type_ == VECTOR_DOUBLE_TYPE) { viennacl::vector_base<double> & x = *(expr[0].lhs_.vector_double_); viennacl::vector_base<double> const & y = *(expr[0].rhs_.vector_double_); viennacl::linalg::avbv(x, x, 1.0, 1, false, false, y, 1.0, 1, false, false); } else throw statement_not_supported_exception("Unsupported rvalue for inplace-add to vector"); }
void avbv_v(lhs_rhs_element & vec1, lhs_rhs_element const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, lhs_rhs_element const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta) { assert( vec1.type_family == VECTOR_TYPE_FAMILY && vec1.subtype == DENSE_VECTOR_TYPE && vec2.type_family == VECTOR_TYPE_FAMILY && vec2.subtype == DENSE_VECTOR_TYPE && vec3.type_family == VECTOR_TYPE_FAMILY && vec3.subtype == DENSE_VECTOR_TYPE && bool("Arguments are not vector types!")); switch (vec1.numeric_type) { case FLOAT_TYPE: assert(vec2.numeric_type == FLOAT_TYPE && vec3.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type")); viennacl::linalg::avbv_v(*vec1.vector_float, *vec2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha, *vec3.vector_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta); break; case DOUBLE_TYPE: assert(vec2.numeric_type == DOUBLE_TYPE && vec3.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type")); viennacl::linalg::avbv_v(*vec1.vector_double, *vec2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha, *vec3.vector_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta); break; default: throw statement_not_supported_exception("Invalid arguments in scheduler when calling avbv_v()"); } }
void axbx_x(lhs_rhs_element & x1, lhs_rhs_element const & x2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, lhs_rhs_element const & x3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta) { assert( x1.type_family == x2.type_family && x2.type_family == x3.type_family && bool("Arguments are not of the same type family!")); switch (x1.type_family) { case SCALAR_TYPE_FAMILY: detail::asbs_s(x1, x2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha, x3, beta, len_beta, reciprocal_beta, flip_sign_beta); break; case VECTOR_TYPE_FAMILY: detail::avbv_v(x1, x2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha, x3, beta, len_beta, reciprocal_beta, flip_sign_beta); break; case MATRIX_TYPE_FAMILY: detail::ambm_m(x1, x2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha, x3, beta, len_beta, reciprocal_beta, flip_sign_beta); break; default: throw statement_not_supported_exception("Invalid argument in scheduler ax() while dispatching."); } }
inline double convert_to_double(lhs_rhs_element const & el) { if (el.type_family == SCALAR_TYPE_FAMILY && el.subtype == HOST_SCALAR_TYPE && el.numeric_type == DOUBLE_TYPE) return el.host_double; if (el.type_family == SCALAR_TYPE_FAMILY && el.subtype == DEVICE_SCALAR_TYPE && el.numeric_type == DOUBLE_TYPE) return *el.scalar_double; throw statement_not_supported_exception("Cannot convert to double"); }
inline float convert_to_float(lhs_rhs_element const & el) { if (el.type_family == SCALAR_TYPE_FAMILY && el.subtype == HOST_SCALAR_TYPE && el.numeric_type == FLOAT_TYPE) return el.host_float; if (el.type_family == SCALAR_TYPE_FAMILY && el.subtype == DEVICE_SCALAR_TYPE && el.numeric_type == FLOAT_TYPE) return *el.scalar_float; throw statement_not_supported_exception("Cannot convert to float"); }
/** @brief Generic dispatcher */ inline void execute_scalar_assign(statement const & s) { typedef statement::container_type StatementContainer; StatementContainer const & expr = s.array(); switch (expr[0].rhs_type_family_) { case COMPOSITE_OPERATION_FAMILY: execute_scalar_assign_composite(s); break; default: throw statement_not_supported_exception("Unsupported rvalue on root node for operation on scalar."); } }
/** @brief Generic dispatcher */ inline void execute_matrix_row_assign(statement const & s) { typedef statement::container_type StatementContainer; StatementContainer const & expr = s.array(); switch (expr[0].rhs_type_family_) { case COMPOSITE_OPERATION_FAMILY: execute_matrix_row_assign_composite(s); break; case MATRIX_ROW_TYPE_FAMILY: execute_matrix_row_assign_matrix(s); break; default: throw statement_not_supported_exception("Invalid rvalue encountered in row-major matrix assignment"); } }
/** @brief Generic dispatcher */ inline void execute_vector_inplace_add(statement const & s) { typedef statement::container_type StatementContainer; StatementContainer const & expr = s.array(); switch (expr[0].rhs_type_family_) { case COMPOSITE_OPERATION_FAMILY: execute_vector_inplace_add_composite(s); break; case VECTOR_TYPE_FAMILY: execute_vector_inplace_add_vector(s); break; default: throw statement_not_supported_exception("Invalid rvalue encountered in vector inplace-add"); } }
/** @brief Dispatcher interface for computing s = inner_prod(x, y) */ inline void inner_prod_impl(lhs_rhs_element const & x, lhs_rhs_element const & y, lhs_rhs_element const & s) { assert( x.type_family == VECTOR_TYPE_FAMILY && x.subtype == DENSE_VECTOR_TYPE && bool("Argument is not a dense vector type!")); assert( y.type_family == VECTOR_TYPE_FAMILY && y.subtype == DENSE_VECTOR_TYPE && bool("Argument is not a dense vector type!")); assert( s.type_family == SCALAR_TYPE_FAMILY && s.subtype == DEVICE_SCALAR_TYPE && bool("Argument is not a scalar type!")); switch (x.numeric_type) { case FLOAT_TYPE: assert(y.numeric_type == FLOAT_TYPE && s.numeric_type == FLOAT_TYPE && bool("Vector and scalar do not have the same numeric type")); viennacl::linalg::inner_prod_impl(*x.vector_float, *y.vector_float, *s.scalar_float); break; case DOUBLE_TYPE: assert(y.numeric_type == DOUBLE_TYPE && s.numeric_type == DOUBLE_TYPE && bool("Vector and scalar do not have the same numeric type")); viennacl::linalg::inner_prod_impl(*x.vector_double, *y.vector_double, *s.scalar_double); break; default: throw statement_not_supported_exception("Invalid arguments in scheduler when calling av()"); } }
/** @brief Deals with A = B for a matrix B */ inline void execute_matrix_row_assign_matrix(statement const & s) { typedef statement::container_type StatementContainer; StatementContainer const & expr = s.array(); if (expr[0].lhs_type_ == MATRIX_ROW_FLOAT_TYPE && expr[0].rhs_type_ == MATRIX_ROW_FLOAT_TYPE) { viennacl::matrix_base<float, viennacl::row_major> & A = *(expr[0].lhs_.matrix_row_float_); viennacl::matrix_base<float, viennacl::row_major> const & B = *(expr[0].rhs_.matrix_row_float_); viennacl::linalg::am(A, B, 1.0, 1, false, false); } else if (expr[0].lhs_type_ == MATRIX_ROW_DOUBLE_TYPE && expr[0].rhs_type_ == MATRIX_ROW_DOUBLE_TYPE) { viennacl::matrix_base<double, viennacl::row_major> & A = *(expr[0].lhs_.matrix_row_double_); viennacl::matrix_base<double, viennacl::row_major> const & B = *(expr[0].rhs_.matrix_row_double_); viennacl::linalg::am(A, B, 1.0, 1, false, false); } else throw statement_not_supported_exception("Unsupported assignment to row-major matrix"); }
void as(lhs_rhs_element & s1, lhs_rhs_element const & s2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha) { assert( s1.type_family == SCALAR_TYPE_FAMILY && (s1.subtype == HOST_SCALAR_TYPE || s1.subtype == DEVICE_SCALAR_TYPE) && s2.type_family == SCALAR_TYPE_FAMILY && (s2.subtype == HOST_SCALAR_TYPE || s2.subtype == DEVICE_SCALAR_TYPE) && bool("Arguments are not vector types!")); switch (s1.numeric_type) { case FLOAT_TYPE: assert(s2.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type")); viennacl::linalg::av(*s1.vector_float, *s2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha); break; case DOUBLE_TYPE: assert(s2.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type")); viennacl::linalg::av(*s1.vector_double, *s2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha); break; default: throw statement_not_supported_exception("Invalid arguments in scheduler when calling av()"); } }
/** @brief Deals with x = RHS where RHS is a vector expression */ inline void execute_matrix_row_assign_composite(statement const & s) { statement::container_type const & expr = s.array(); if (expr[1].op_type_ == OPERATION_BINARY_ADD_TYPE) { if (expr[0].lhs_type_ == MATRIX_ROW_FLOAT_TYPE && expr[1].lhs_type_ == MATRIX_ROW_FLOAT_TYPE && expr[1].rhs_type_ == MATRIX_ROW_FLOAT_TYPE) { viennacl::matrix_base<float, viennacl::row_major> & A = *(expr[0].lhs_.matrix_row_float_); viennacl::matrix_base<float, viennacl::row_major> const & B = *(expr[1].lhs_.matrix_row_float_); viennacl::matrix_base<float, viennacl::row_major> const & C = *(expr[1].rhs_.matrix_row_float_); viennacl::linalg::ambm(A, B, 1.0, 1, false, false, C, 1.0, 1, false, false); } else if (expr[0].lhs_type_ == MATRIX_ROW_DOUBLE_TYPE && expr[1].lhs_type_ == MATRIX_ROW_DOUBLE_TYPE && expr[1].rhs_type_ == MATRIX_ROW_DOUBLE_TYPE) { viennacl::matrix_base<double, viennacl::row_major> & A = *(expr[0].lhs_.matrix_row_double_); viennacl::matrix_base<double, viennacl::row_major> const & B = *(expr[1].lhs_.matrix_row_double_); viennacl::matrix_base<double, viennacl::row_major> const & C = *(expr[1].rhs_.matrix_row_double_); viennacl::linalg::ambm(A, B, 1.0, 1, false, false, C, 1.0, 1, false, false); } else throw statement_not_supported_exception("Cannot deal with addition of row-major matrix"); } else if (expr[1].op_type_ == OPERATION_BINARY_SUB_TYPE) { if (expr[0].lhs_type_ == MATRIX_ROW_FLOAT_TYPE && expr[1].lhs_type_ == MATRIX_ROW_FLOAT_TYPE && expr[1].rhs_type_ == MATRIX_ROW_FLOAT_TYPE) { viennacl::matrix_base<float, viennacl::row_major> & A = *(expr[0].lhs_.matrix_row_float_); viennacl::matrix_base<float, viennacl::row_major> const & B = *(expr[1].lhs_.matrix_row_float_); viennacl::matrix_base<float, viennacl::row_major> const & C = *(expr[1].rhs_.matrix_row_float_); viennacl::linalg::ambm(A, B, 1.0, 1, false, false, C, -1.0, 1, false, false); } else if (expr[0].lhs_type_ == MATRIX_ROW_DOUBLE_TYPE && expr[1].lhs_type_ == MATRIX_ROW_DOUBLE_TYPE && expr[1].rhs_type_ == MATRIX_ROW_DOUBLE_TYPE) { viennacl::matrix_base<double, viennacl::row_major> & A = *(expr[0].lhs_.matrix_row_double_); viennacl::matrix_base<double, viennacl::row_major> const & B = *(expr[1].lhs_.matrix_row_double_); viennacl::matrix_base<double, viennacl::row_major> const & C = *(expr[1].rhs_.matrix_row_double_); viennacl::linalg::ambm(A, B, 1.0, 1, false, false, C, -1.0, 1, false, false); } else throw statement_not_supported_exception("Cannot deal with subtraction of row-major matrix"); } else throw statement_not_supported_exception("Unsupported binary operator for row-major matrix operations"); }
/** @brief Deals with x = RHS where RHS is a vector expression */ inline void execute_scalar_assign_composite(statement const & s) { statement::container_type const & expr = s.array(); if (expr[1].op_type_ == OPERATION_BINARY_INNER_PROD_TYPE) { if (expr[0].lhs_type_ == SCALAR_FLOAT_TYPE && expr[1].lhs_type_ == VECTOR_FLOAT_TYPE && expr[1].rhs_type_ == VECTOR_FLOAT_TYPE) { viennacl::scalar<float> & s = *(expr[0].lhs_.scalar_float_); viennacl::vector_base<float> const & y = *(expr[1].lhs_.vector_float_); viennacl::vector_base<float> const & z = *(expr[1].rhs_.vector_float_); viennacl::linalg::inner_prod_impl(y, z, s); } else if (expr[0].lhs_type_ == SCALAR_DOUBLE_TYPE && expr[1].lhs_type_ == VECTOR_DOUBLE_TYPE && expr[1].rhs_type_ == VECTOR_DOUBLE_TYPE) { viennacl::scalar<double> & s = *(expr[0].lhs_.scalar_double_); viennacl::vector_base<double> const & y = *(expr[1].lhs_.vector_double_); viennacl::vector_base<double> const & z = *(expr[1].rhs_.vector_double_); viennacl::linalg::inner_prod_impl(y, z, s); } else throw statement_not_supported_exception("Cannot deal with inner product of the provided arguments"); } else if (expr[1].op_type_ == OPERATION_UNARY_NORM_1_TYPE) { if (expr[0].lhs_type_ == SCALAR_FLOAT_TYPE && expr[1].lhs_type_ == VECTOR_FLOAT_TYPE) { viennacl::scalar<float> & s = *(expr[0].lhs_.scalar_float_); viennacl::vector_base<float> const & x = *(expr[1].lhs_.vector_float_); viennacl::linalg::norm_1_impl(x, s); } else if (expr[0].lhs_type_ == SCALAR_DOUBLE_TYPE && expr[1].lhs_type_ == VECTOR_DOUBLE_TYPE && expr[1].rhs_type_ == VECTOR_DOUBLE_TYPE) { viennacl::scalar<double> & s = *(expr[0].lhs_.scalar_double_); viennacl::vector_base<double> const & x = *(expr[1].lhs_.vector_double_); viennacl::linalg::norm_1_impl(x, s); } else throw statement_not_supported_exception("Cannot deal with norm_1 of the provided arguments"); } else if (expr[1].op_type_ == OPERATION_UNARY_NORM_2_TYPE) { if (expr[0].lhs_type_ == SCALAR_FLOAT_TYPE && expr[1].lhs_type_ == VECTOR_FLOAT_TYPE) { viennacl::scalar<float> & s = *(expr[0].lhs_.scalar_float_); viennacl::vector_base<float> const & x = *(expr[1].lhs_.vector_float_); viennacl::linalg::norm_2_impl(x, s); } else if (expr[0].lhs_type_ == SCALAR_DOUBLE_TYPE && expr[1].lhs_type_ == VECTOR_DOUBLE_TYPE && expr[1].rhs_type_ == VECTOR_DOUBLE_TYPE) { viennacl::scalar<double> & s = *(expr[0].lhs_.scalar_double_); viennacl::vector_base<double> const & x = *(expr[1].lhs_.vector_double_); viennacl::linalg::norm_2_impl(x, s); } else throw statement_not_supported_exception("Cannot deal with norm_2 of the provided arguments"); } else if (expr[1].op_type_ == OPERATION_UNARY_NORM_INF_TYPE) { if (expr[0].lhs_type_ == SCALAR_FLOAT_TYPE && expr[1].lhs_type_ == VECTOR_FLOAT_TYPE) { viennacl::scalar<float> & s = *(expr[0].lhs_.scalar_float_); viennacl::vector_base<float> const & x = *(expr[1].lhs_.vector_float_); viennacl::linalg::norm_inf_impl(x, s); } else if (expr[0].lhs_type_ == SCALAR_DOUBLE_TYPE && expr[1].lhs_type_ == VECTOR_DOUBLE_TYPE && expr[1].rhs_type_ == VECTOR_DOUBLE_TYPE) { viennacl::scalar<double> & s = *(expr[0].lhs_.scalar_double_); viennacl::vector_base<double> const & x = *(expr[1].lhs_.vector_double_); viennacl::linalg::norm_inf_impl(x, s); } else throw statement_not_supported_exception("Cannot deal with norm_inf of the provided arguments"); } else throw statement_not_supported_exception("Unsupported operation for scalar."); }
/** @brief Helper routine for extracting the context in which a statement is executed. * * As all statements are of the type x = EXPR, it is sufficient to extract the context from x. */ inline viennacl::context extract_context(statement_node const & root_node) { if (root_node.lhs.type_family == SCALAR_TYPE_FAMILY) { switch (root_node.lhs.numeric_type) { case CHAR_TYPE: return viennacl::traits::context(*root_node.lhs.scalar_char); case UCHAR_TYPE: return viennacl::traits::context(*root_node.lhs.scalar_char); case SHORT_TYPE: return viennacl::traits::context(*root_node.lhs.scalar_short); case USHORT_TYPE: return viennacl::traits::context(*root_node.lhs.scalar_ushort); case INT_TYPE: return viennacl::traits::context(*root_node.lhs.scalar_int); case UINT_TYPE: return viennacl::traits::context(*root_node.lhs.scalar_uint); case LONG_TYPE: return viennacl::traits::context(*root_node.lhs.scalar_long); case ULONG_TYPE: return viennacl::traits::context(*root_node.lhs.scalar_ulong); //case HALF_TYPE: //return viennacl::traits::context(*root_node.lhs.scalar_half); case FLOAT_TYPE: return viennacl::traits::context(*root_node.lhs.scalar_float); case DOUBLE_TYPE: return viennacl::traits::context(*root_node.lhs.scalar_double); default: throw statement_not_supported_exception("Invalid numeric type for extraction of context from scalar"); } } else if (root_node.lhs.type_family == VECTOR_TYPE_FAMILY) { switch (root_node.lhs.numeric_type) { case CHAR_TYPE: return viennacl::traits::context(*root_node.lhs.vector_char); case UCHAR_TYPE: return viennacl::traits::context(*root_node.lhs.vector_char); case SHORT_TYPE: return viennacl::traits::context(*root_node.lhs.vector_short); case USHORT_TYPE: return viennacl::traits::context(*root_node.lhs.vector_ushort); case INT_TYPE: return viennacl::traits::context(*root_node.lhs.vector_int); case UINT_TYPE: return viennacl::traits::context(*root_node.lhs.vector_uint); case LONG_TYPE: return viennacl::traits::context(*root_node.lhs.vector_long); case ULONG_TYPE: return viennacl::traits::context(*root_node.lhs.vector_ulong); //case HALF_TYPE: //return viennacl::traits::context(*root_node.lhs.vector_half); case FLOAT_TYPE: return viennacl::traits::context(*root_node.lhs.vector_float); case DOUBLE_TYPE: return viennacl::traits::context(*root_node.lhs.vector_double); default: throw statement_not_supported_exception("Invalid numeric type for extraction of context from vector"); } } else if (root_node.lhs.type_family == MATRIX_TYPE_FAMILY) { switch (root_node.lhs.numeric_type) { case CHAR_TYPE: return viennacl::traits::context(*root_node.lhs.matrix_char); case UCHAR_TYPE: return viennacl::traits::context(*root_node.lhs.matrix_char); case SHORT_TYPE: return viennacl::traits::context(*root_node.lhs.matrix_short); case USHORT_TYPE: return viennacl::traits::context(*root_node.lhs.matrix_ushort); case INT_TYPE: return viennacl::traits::context(*root_node.lhs.matrix_int); case UINT_TYPE: return viennacl::traits::context(*root_node.lhs.matrix_uint); case LONG_TYPE: return viennacl::traits::context(*root_node.lhs.matrix_long); case ULONG_TYPE: return viennacl::traits::context(*root_node.lhs.matrix_ulong); //case HALF_TYPE: //return viennacl::traits::context(*root_node.lhs.matrix_half); case FLOAT_TYPE: return viennacl::traits::context(*root_node.lhs.matrix_float); case DOUBLE_TYPE: return viennacl::traits::context(*root_node.lhs.matrix_double); default: throw statement_not_supported_exception("Invalid numeric type for extraction of context from matrix"); } } throw statement_not_supported_exception("Invalid type for context extraction"); }
/** @brief Deals with x = RHS where RHS is a vector expression */ inline void execute_vector_inplace_add_composite(statement const & s) { throw statement_not_supported_exception("Composite inplace-additions for vectors not supported yet"); }
inline void new_element(lhs_rhs_element & new_elem, lhs_rhs_element const & old_element, viennacl::context const & ctx) { new_elem.type_family = old_element.type_family; new_elem.subtype = old_element.subtype; new_elem.numeric_type = old_element.numeric_type; if (new_elem.type_family == SCALAR_TYPE_FAMILY) { assert(new_elem.subtype == DEVICE_SCALAR_TYPE && bool("Expected a device scalar in root node")); switch (new_elem.numeric_type) { case FLOAT_TYPE: new_elem.scalar_float = new viennacl::scalar<float>(0, ctx); return; case DOUBLE_TYPE: new_elem.scalar_double = new viennacl::scalar<double>(0, ctx); return; default: throw statement_not_supported_exception("Invalid vector type for vector construction"); } } else if (new_elem.type_family == VECTOR_TYPE_FAMILY) { assert(new_elem.subtype == DENSE_VECTOR_TYPE && bool("Expected a dense vector in root node")); switch (new_elem.numeric_type) { case FLOAT_TYPE: new_elem.vector_float = new viennacl::vector<float>((old_element.vector_float)->size(), ctx); return; case DOUBLE_TYPE: new_elem.vector_double = new viennacl::vector<double>((old_element.vector_float)->size(), ctx); return; default: throw statement_not_supported_exception("Invalid vector type for vector construction"); } } else if (new_elem.type_family == MATRIX_TYPE_FAMILY) { assert( (new_elem.subtype == DENSE_MATRIX_TYPE) && bool("Expected a dense matrix in root node")); if (new_elem.subtype == DENSE_MATRIX_TYPE) { switch (new_elem.numeric_type) { case FLOAT_TYPE: new_elem.matrix_float = new viennacl::matrix_base<float>((old_element.matrix_float)->size1(), (old_element.matrix_float)->size2(), (old_element.matrix_float)->row_major(), ctx); return; case DOUBLE_TYPE: new_elem.matrix_double = new viennacl::matrix_base<double>((old_element.matrix_double)->size1(), (old_element.matrix_double)->size2(), (old_element.matrix_double)->row_major(), ctx); return; default: throw statement_not_supported_exception("Invalid vector type for vector construction"); } } else throw statement_not_supported_exception("Expected a dense matrix in root node when creating a temporary"); } else throw statement_not_supported_exception("Unknown type familty when creating new temporary object"); }