#ifndef EXPRESSION_TRAITS_H #define EXPRESSION_TRAITS_H #include "Fastor/config/config.h" #include "Fastor/meta/meta.h" #include namespace Fastor { //------------------------------------------------------------------------------------------------// template struct is_expression { static constexpr bool value = false; }; template class UnaryExpr, typename Expr, size_t DIM> struct is_expression> { static constexpr bool value = true; }; template class BinaryExpr, typename TLhs, typename TRhs, size_t DIMS> struct is_expression> { static constexpr bool value = true; }; template static constexpr bool is_expression_v = is_expression::value; //------------------------------------------------------------------------------------------------// // Expression binder - by value or ref //------------------------------------------------------------------------------------------------// template struct expression_binder_type { #ifndef FASTOR_COPY_EXPR using type = conditional_t_ || is_arithmetic_v_, const T, const T&>; #else using type = const T; #endif }; template using expression_t = typename expression_binder_type::type; //------------------------------------------------------------------------------------------------// template class Tensor; template class TensorMap; template class SingleValueTensor; // traits //----------------------------------------------------------------------------------------------------------// template struct is_unary_bool_op { static constexpr bool value = false; }; template struct is_unary_bool_op> { static constexpr bool value = true; }; template struct is_unary_bool_op> { static constexpr bool value = true; }; template struct is_unary_bool_op> { static constexpr bool value = true; }; template struct is_unary_bool_op> { static constexpr bool value = true; }; template struct is_unary_bool_op> { static constexpr bool value = true; }; template struct is_unary_bool_op> { static constexpr bool value = true; }; template struct is_unary_bool_op> { static constexpr bool value = true; }; template static constexpr bool is_unary_bool_op_v = is_unary_bool_op::value; //----------------------------------------------------------------------------------------------------------// //----------------------------------------------------------------------------------------------------------// template struct is_binary_cmp_op { static constexpr bool value = false; }; #define FASTOR_MAKE_IS_BINARY_CMP_OP(NAME) \ template\ struct is_binary_cmp_op> {\ static constexpr bool value = true;\ };\ FASTOR_MAKE_IS_BINARY_CMP_OP(EQ) FASTOR_MAKE_IS_BINARY_CMP_OP(NEQ) FASTOR_MAKE_IS_BINARY_CMP_OP(LT) FASTOR_MAKE_IS_BINARY_CMP_OP(GT) FASTOR_MAKE_IS_BINARY_CMP_OP(LE) FASTOR_MAKE_IS_BINARY_CMP_OP(GE) FASTOR_MAKE_IS_BINARY_CMP_OP(AND) FASTOR_MAKE_IS_BINARY_CMP_OP(OR) template struct is_binary_cmp_op> { static constexpr bool value = true; }; template struct is_binary_cmp_op> { static constexpr bool value = true; }; template struct is_binary_cmp_op> { static constexpr bool value = true; }; template static constexpr bool is_binary_cmp_op_v = is_binary_cmp_op::value; //----------------------------------------------------------------------------------------------------------// /* Is boolean expresssion */ //----------------------------------------------------------------------------------------------------------// template struct is_boolean_expression { static constexpr bool value = is_unary_bool_op::value || is_binary_cmp_op::value; }; template static constexpr bool is_boolean_expression_v = is_boolean_expression::value; //----------------------------------------------------------------------------------------------------------// //----------------------------------------------------------------------------------------------------------// template struct is_tensor_view { static constexpr bool value = false; }; template struct is_tensor_view,DIMS>> { static constexpr bool value = true; }; template struct is_tensor_view,DIMS>> { static constexpr bool value = true; }; template struct has_tensor_view { static constexpr bool value = is_tensor_view::value ? true : false; }; template struct has_tensor_view,DIMS>> { static constexpr bool value = true; }; template struct has_tensor_view,DIMS>> { static constexpr bool value = true; }; template class UnaryExpr, typename Expr, size_t DIM> struct has_tensor_view> { static constexpr bool value = has_tensor_view::value; }; template class BinaryExpr, typename TLhs, typename TRhs, size_t DIMS> struct has_tensor_view> { static constexpr bool value = has_tensor_view::value || has_tensor_view::value; }; template static constexpr bool has_tensor_view_v = has_tensor_view::value; //----------------------------------------------------------------------------------------------------------// //----------------------------------------------------------------------------------------------------------// template struct is_tensor_fixed_view_2d { static constexpr bool value = false; }; template struct is_tensor_fixed_view_2d,Seq0,Seq1,2>> { static constexpr bool value = true; }; template struct is_tensor_fixed_view_2d,Seq0,Seq1,2>> { static constexpr bool value = true; }; template struct has_tensor_fixed_view_2d { static constexpr bool value = is_tensor_fixed_view_2d::value ? true : false; }; template struct has_tensor_fixed_view_2d,Seq0,Seq1,2>> { static constexpr bool value = true; }; template struct has_tensor_fixed_view_2d,Seq0,Seq1,2>> { static constexpr bool value = true; }; template class UnaryExpr, typename Expr, size_t DIM> struct has_tensor_fixed_view_2d> { static constexpr bool value = has_tensor_fixed_view_2d::value; }; template class BinaryExpr, typename TLhs, typename TRhs, size_t DIMS> struct has_tensor_fixed_view_2d> { static constexpr bool value = has_tensor_fixed_view_2d::value || has_tensor_fixed_view_2d::value; }; template static constexpr bool has_tensor_fixed_view_2d_v = has_tensor_fixed_view_2d::value; //----------------------------------------------------------------------------------------------------------// //----------------------------------------------------------------------------------------------------------// template struct is_tensor_fixed_view_nd { static constexpr bool value = false; }; template struct is_tensor_fixed_view_nd,Fseq...>> { static constexpr bool value = true; }; template struct is_tensor_fixed_view_nd,Fseq...>> { static constexpr bool value = true; }; template struct has_tensor_fixed_view_nd { static constexpr bool value = is_tensor_fixed_view_nd::value ? true : false; }; template struct has_tensor_fixed_view_nd,Fseq...>> { static constexpr bool value = true; }; template struct has_tensor_fixed_view_nd,Fseq...>> { static constexpr bool value = true; }; template class UnaryExpr, typename Expr, size_t DIM> struct has_tensor_fixed_view_nd> { static constexpr bool value = has_tensor_fixed_view_nd::value; }; template class BinaryExpr, typename TLhs, typename TRhs, size_t DIMS> struct has_tensor_fixed_view_nd> { static constexpr bool value = has_tensor_fixed_view_nd::value || has_tensor_fixed_view_nd::value; }; template static constexpr bool has_tensor_fixed_view_nd_v = has_tensor_fixed_view_nd::value; //----------------------------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------------------// template struct get_binary_arithmetic_result_type; template struct get_binary_arithmetic_result_type > > { using type = T; }; template struct get_binary_arithmetic_result_type > > { using type = typename T::result_type; }; template struct binary_arithmetic_result_type; template class BinaryExpr, typename TLhs, typename TRhs, size_t DIM0> struct binary_arithmetic_result_type< BinaryExpr > { using type = conditional_t_, typename get_binary_arithmetic_result_type::type, typename get_binary_arithmetic_result_type::type >; }; template using binary_arithmetic_result_t = typename binary_arithmetic_result_type::type; //------------------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------------------// template struct get_binary_op_simd_vector_type; template struct get_binary_op_simd_vector_type > > { using type = T; }; template struct get_binary_op_simd_vector_type > > { using type = typename T::simd_vector_type; }; template struct binary_op_simd_vector_type; template class BinaryExpr, typename TLhs, typename TRhs, size_t DIM0> struct binary_op_simd_vector_type< BinaryExpr > { using type = conditional_t_, typename get_binary_op_simd_vector_type::type, typename get_binary_op_simd_vector_type::type >; }; template using binary_op_simd_vector_t = typename binary_op_simd_vector_type::type; //------------------------------------------------------------------------------------------------// template struct scalar_type_finder; } // end of namespace Fastor #endif // EXPRESSION_TRAITS_H