X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2Fcml%2Fmatrix%2Fmatrix_promotions.h;h=8be57cb651af62a863f434f34b1627e5abbf5d21;hp=18e94bb2509cea057445c4081cf1100817e94013;hb=50c1239917f5e443b8ec91773c85ceb3db7da67b;hpb=1dd005530930657fd6216edc1dfcfa4c270a81c9 diff --git a/src/Moof/cml/matrix/matrix_promotions.h b/src/Moof/cml/matrix/matrix_promotions.h index 18e94bb..8be57cb 100644 --- a/src/Moof/cml/matrix/matrix_promotions.h +++ b/src/Moof/cml/matrix/matrix_promotions.h @@ -33,34 +33,102 @@ struct outer_promote_expects_properly_oriented_args_error; namespace cml { namespace et { -/* Default matrix type promotion template. */ -template struct MatrixPromote; - -/** Type promotion for two matrix types. - * - * @note This always uses the basis orientation of the left-hand matrix. - * @bug This always uses the basis orientation of the left-hand matrix, - * which is not always correct. - */ -template -struct MatrixPromote< cml::matrix, cml::matrix > +/** Promote two types to a matrixt type. */ +template struct MatrixPromote { - /* Promote the arrays: */ - typedef typename ArrayPromote< - typename cml::matrix::array_type, + /* Default matrix type promotion template. */ + template struct MatrixPromoteHelper; + + /** Type promotion for two matrix types. + * + * @note This always uses the basis orientation of the left-hand matrix. + * @bug This always uses the basis orientation of the left-hand matrix, + * which is not always correct. + */ + template + struct MatrixPromoteHelper< + cml::matrix, cml::matrix + > + { + /* Promote the arrays: */ + typedef typename ArrayPromote< + typename cml::matrix::array_type, typename cml::matrix::array_type - >::type promoted_array; + >::type promoted_array; + + /* The deduced matrix result type: */ + typedef cml::matrix< + typename promoted_array::value_type, + typename promoted_array::generator_type, + BO1, + typename promoted_array::layout + > type; + + /* The deduced temporary type: */ + typedef typename type::temporary_type temporary_type; + }; + + /** Type promotion for a matrix and a scalar. */ + template + struct MatrixPromoteHelper, S> + { + /* The deduced matrix result type (the array type is the same): */ + typedef cml::matrix::type, AT, BO, L> type; + + /* The deduced temporary type: */ + typedef typename type::temporary_type temporary_type; + }; + + /** Type promotion for a scalar and a matrix. */ + template + struct MatrixPromoteHelper > + { + /* The deduced matrix result type (the array type is the same): */ + typedef cml::matrix::type, AT, BO, L> type; - /* The deduced matrix result type: */ - typedef cml::matrix< - typename promoted_array::value_type, - typename promoted_array::generator_type, - BO1, - typename promoted_array::layout - > type; + /* The deduced temporary type: */ + typedef typename type::temporary_type temporary_type; + }; + + /** Type promotion for outer product. */ + template + struct MatrixPromoteHelper< cml::vector, cml::vector > + { + typedef cml::vector left_type; + typedef cml::vector right_type; + typedef CML_DEFAULT_BASIS_ORIENTATION basis_orient; + + /* Get matrix size: */ + enum { + array_rows = left_type::array_size, + array_cols = right_type::array_size + }; + + /* Deduce the corresponding matrix types for the vectors: */ + typedef CML_DEFAULT_ARRAY_LAYOUT layout; + typedef typename select_if< + array_rows == -1, dynamic<>, fixed + >::result left_storage; + typedef cml::matrix left_matrix; + + typedef typename select_if< + array_cols == -1, dynamic<>, fixed<1,array_cols> + >::result right_storage; + typedef cml::matrix right_matrix; + + /* Finally, promote the matrix types to get the result: */ + typedef typename et::MatrixPromote::type type; + typedef typename type::temporary_type temporary_type; + }; + + /** Remove const and & from the to-be-promoted types. */ + typedef typename remove_const< + typename remove_reference::type>::type LeftBaseT; + typedef typename remove_const< + typename remove_reference::type>::type RightBaseT; - /* The deduced temporary type: */ + typedef typename MatrixPromoteHelper::type type; typedef typename type::temporary_type temporary_type; }; @@ -75,7 +143,7 @@ struct MatrixPromote2 { typedef typename MatrixPromote< typename Mat1_T::temporary_type, typename Mat2_T::temporary_type - >::temporary_type temporary_type; + >::temporary_type temporary_type; typedef typename temporary_type::value_type value_type; }; @@ -86,9 +154,10 @@ struct MatrixPromote3 typedef typename MatrixPromote< typename Mat1_T::temporary_type, typename MatrixPromote< - typename Mat2_T::temporary_type, typename Mat3_T::temporary_type + typename Mat2_T::temporary_type, + typename Mat3_T::temporary_type >::temporary_type - >::temporary_type temporary_type; + >::temporary_type temporary_type; typedef typename temporary_type::value_type value_type; }; @@ -104,64 +173,11 @@ struct MatrixPromote4 typename Mat3_T::temporary_type, typename Mat4_T::temporary_type >::temporary_type - >::temporary_type - >::temporary_type temporary_type; + >::temporary_type + >::temporary_type temporary_type; typedef typename temporary_type::value_type value_type; }; -/** Type promotion for a matrix and a scalar. */ -template -struct MatrixPromote, S> -{ - /* The deduced matrix result type (the array type is the same): */ - typedef cml::matrix::type, AT, BO, L> type; - - /* The deduced temporary type: */ - typedef typename type::temporary_type temporary_type; -}; - -/** Type promotion for a scalar and a matrix. */ -template -struct MatrixPromote > -{ - /* The deduced matrix result type (the array type is the same): */ - typedef cml::matrix::type, AT, BO, L> type; - - /* The deduced temporary type: */ - typedef typename type::temporary_type temporary_type; -}; - -/** Type promotion for outer product. */ -template -struct MatrixPromote< cml::vector, cml::vector > -{ - typedef cml::vector left_type; - typedef cml::vector right_type; - typedef CML_DEFAULT_BASIS_ORIENTATION basis_orient; - - /* Get matrix size: */ - enum { - array_rows = left_type::array_size, - array_cols = right_type::array_size - }; - - /* Deduce the corresponding matrix types for the vectors: */ - typedef CML_DEFAULT_ARRAY_LAYOUT layout; - typedef typename select_if< - array_rows == -1, dynamic<>, fixed - >::result left_storage; - typedef cml::matrix left_matrix; - - typedef typename select_if< - array_cols == -1, dynamic<>, fixed<1,array_cols> - >::result right_storage; - typedef cml::matrix right_matrix; - - /* Finally, promote the matrix types to get the result: */ - typedef typename et::MatrixPromote::type type; - typedef typename type::temporary_type temporary_type; -}; - } // namespace et } // namespace cml