From eda5bc26f44ee9a6f83dcf8c91f17296d7fc509d Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 12 Feb 2024 14:52:43 +0100 Subject: Move into version control --- src/armadillo/include/armadillo_bits/traits.hpp | 1315 +++++++++++++++++++++++ 1 file changed, 1315 insertions(+) create mode 100644 src/armadillo/include/armadillo_bits/traits.hpp (limited to 'src/armadillo/include/armadillo_bits/traits.hpp') diff --git a/src/armadillo/include/armadillo_bits/traits.hpp b/src/armadillo/include/armadillo_bits/traits.hpp new file mode 100644 index 0000000..bde2200 --- /dev/null +++ b/src/armadillo/include/armadillo_bits/traits.hpp @@ -0,0 +1,1315 @@ +// SPDX-License-Identifier: Apache-2.0 +// +// Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) +// Copyright 2008-2016 National ICT Australia (NICTA) +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + + +//! \addtogroup traits +//! @{ + + +template +struct get_pod_type + { typedef T1 result; }; + +template +struct get_pod_type< std::complex > + { typedef T2 result; }; + + + +template +struct is_Mat_fixed_only + { + typedef char yes[1]; + typedef char no[2]; + + template static yes& check(typename X::Mat_fixed_type*); + template static no& check(...); + + static constexpr bool value = ( sizeof(check(0)) == sizeof(yes) ); + }; + + + +template +struct is_Row_fixed_only + { + typedef char yes[1]; + typedef char no[2]; + + template static yes& check(typename X::Row_fixed_type*); + template static no& check(...); + + static constexpr bool value = ( sizeof(check(0)) == sizeof(yes) ); + }; + + + +template +struct is_Col_fixed_only + { + typedef char yes[1]; + typedef char no[2]; + + template static yes& check(typename X::Col_fixed_type*); + template static no& check(...); + + static constexpr bool value = ( sizeof(check(0)) == sizeof(yes) ); + }; + + + +template +struct is_Mat_fixed + { static constexpr bool value = ( is_Mat_fixed_only::value || is_Row_fixed_only::value || is_Col_fixed_only::value ); }; + + + +template +struct is_Mat_only + { static constexpr bool value = is_Mat_fixed_only::value; }; + +template +struct is_Mat_only< Mat > + { static constexpr bool value = true; }; + +template +struct is_Mat_only< const Mat > + { static constexpr bool value = true; }; + + + +template +struct is_Mat + { static constexpr bool value = ( is_Mat_fixed_only::value || is_Row_fixed_only::value || is_Col_fixed_only::value ); }; + +template +struct is_Mat< Mat > + { static constexpr bool value = true; }; + +template +struct is_Mat< const Mat > + { static constexpr bool value = true; }; + +template +struct is_Mat< Row > + { static constexpr bool value = true; }; + +template +struct is_Mat< const Row > + { static constexpr bool value = true; }; + +template +struct is_Mat< Col > + { static constexpr bool value = true; }; + +template +struct is_Mat< const Col > + { static constexpr bool value = true; }; + + + +template +struct is_Row + { static constexpr bool value = is_Row_fixed_only::value; }; + +template +struct is_Row< Row > + { static constexpr bool value = true; }; + +template +struct is_Row< const Row > + { static constexpr bool value = true; }; + + + +template +struct is_Col + { static constexpr bool value = is_Col_fixed_only::value; }; + +template +struct is_Col< Col > + { static constexpr bool value = true; }; + +template +struct is_Col< const Col > + { static constexpr bool value = true; }; + + + +template +struct is_diagview + { static constexpr bool value = false; }; + +template +struct is_diagview< diagview > + { static constexpr bool value = true; }; + +template +struct is_diagview< const diagview > + { static constexpr bool value = true; }; + + +template +struct is_subview + { static constexpr bool value = false; }; + +template +struct is_subview< subview > + { static constexpr bool value = true; }; + +template +struct is_subview< const subview > + { static constexpr bool value = true; }; + + +template +struct is_subview_row + { static constexpr bool value = false; }; + +template +struct is_subview_row< subview_row > + { static constexpr bool value = true; }; + +template +struct is_subview_row< const subview_row > + { static constexpr bool value = true; }; + + +template +struct is_subview_col + { static constexpr bool value = false; }; + +template +struct is_subview_col< subview_col > + { static constexpr bool value = true; }; + +template +struct is_subview_col< const subview_col > + { static constexpr bool value = true; }; + + +template +struct is_subview_cols + { static constexpr bool value = false; }; + +template +struct is_subview_cols< subview_cols > + { static constexpr bool value = true; }; + +template +struct is_subview_cols< const subview_cols > + { static constexpr bool value = true; }; + + +template +struct is_subview_elem1 + { static constexpr bool value = false; }; + +template +struct is_subview_elem1< subview_elem1 > + { static constexpr bool value = true; }; + +template +struct is_subview_elem1< const subview_elem1 > + { static constexpr bool value = true; }; + + +template +struct is_subview_elem2 + { static constexpr bool value = false; }; + +template +struct is_subview_elem2< subview_elem2 > + { static constexpr bool value = true; }; + +template +struct is_subview_elem2< const subview_elem2 > + { static constexpr bool value = true; }; + + + +// +// +// + + + +template +struct is_Cube + { static constexpr bool value = false; }; + +template +struct is_Cube< Cube > + { static constexpr bool value = true; }; + +template +struct is_Cube< const Cube > + { static constexpr bool value = true; }; + +template +struct is_subview_cube + { static constexpr bool value = false; }; + +template +struct is_subview_cube< subview_cube > + { static constexpr bool value = true; }; + +template +struct is_subview_cube< const subview_cube > + { static constexpr bool value = true; }; + +template +struct is_subview_cube_slices + { static constexpr bool value = false; }; + +template +struct is_subview_cube_slices< subview_cube_slices > + { static constexpr bool value = true; }; + +template +struct is_subview_cube_slices< const subview_cube_slices > + { static constexpr bool value = true; }; + + +// +// +// + + +template +struct is_Gen + { static constexpr bool value = false; }; + +template +struct is_Gen< Gen > + { static constexpr bool value = true; }; + +template +struct is_Gen< const Gen > + { static constexpr bool value = true; }; + + +template +struct is_Op + { static constexpr bool value = false; }; + +template +struct is_Op< Op > + { static constexpr bool value = true; }; + +template +struct is_Op< const Op > + { static constexpr bool value = true; }; + + +template +struct is_CubeToMatOp + { static constexpr bool value = false; }; + +template +struct is_CubeToMatOp< CubeToMatOp > + { static constexpr bool value = true; }; + +template +struct is_CubeToMatOp< const CubeToMatOp > + { static constexpr bool value = true; }; + + +template +struct is_SpToDOp + { static constexpr bool value = false; }; + +template +struct is_SpToDOp< SpToDOp > + { static constexpr bool value = true; }; + +template +struct is_SpToDOp< const SpToDOp > + { static constexpr bool value = true; }; + + +template +struct is_SpToDGlue + { static constexpr bool value = false; }; + +template +struct is_SpToDGlue< SpToDGlue > + { static constexpr bool value = true; }; + +template +struct is_SpToDGlue< const SpToDGlue > + { static constexpr bool value = true; }; + + +template +struct is_eOp + { static constexpr bool value = false; }; + +template +struct is_eOp< eOp > + { static constexpr bool value = true; }; + +template +struct is_eOp< const eOp > + { static constexpr bool value = true; }; + + +template +struct is_mtOp + { static constexpr bool value = false; }; + +template +struct is_mtOp< mtOp > + { static constexpr bool value = true; }; + +template +struct is_mtOp< const mtOp > + { static constexpr bool value = true; }; + + +template +struct is_Glue + { static constexpr bool value = false; }; + +template +struct is_Glue< Glue > + { static constexpr bool value = true; }; + +template +struct is_Glue< const Glue > + { static constexpr bool value = true; }; + + +template +struct is_eGlue + { static constexpr bool value = false; }; + +template +struct is_eGlue< eGlue > + { static constexpr bool value = true; }; + +template +struct is_eGlue< const eGlue > + { static constexpr bool value = true; }; + + +template +struct is_mtGlue + { static constexpr bool value = false; }; + +template +struct is_mtGlue< mtGlue > + { static constexpr bool value = true; }; + +template +struct is_mtGlue< const mtGlue > + { static constexpr bool value = true; }; + + +// +// + + +template +struct is_glue_times + { static constexpr bool value = false; }; + +template +struct is_glue_times< Glue > + { static constexpr bool value = true; }; + +template +struct is_glue_times< const Glue > + { static constexpr bool value = true; }; + + +template +struct is_glue_times_diag + { static constexpr bool value = false; }; + +template +struct is_glue_times_diag< Glue > + { static constexpr bool value = true; }; + +template +struct is_glue_times_diag< const Glue > + { static constexpr bool value = true; }; + + +template +struct is_op_diagmat + { static constexpr bool value = false; }; + +template +struct is_op_diagmat< Op > + { static constexpr bool value = true; }; + +template +struct is_op_diagmat< const Op > + { static constexpr bool value = true; }; + + +// +// + + +template +struct is_Mat_trans + { static constexpr bool value = false; }; + +template +struct is_Mat_trans< Op > + { static constexpr bool value = is_Mat::value; }; + +template +struct is_Mat_trans< Op > + { static constexpr bool value = is_Mat::value; }; + + +// +// + + +template +struct is_GenCube + { static constexpr bool value = false; }; + +template +struct is_GenCube< GenCube > + { static constexpr bool value = true; }; + + +template +struct is_OpCube + { static constexpr bool value = false; }; + +template +struct is_OpCube< OpCube > + { static constexpr bool value = true; }; + + +template +struct is_eOpCube + { static constexpr bool value = false; }; + +template +struct is_eOpCube< eOpCube > + { static constexpr bool value = true; }; + + +template +struct is_mtOpCube + { static constexpr bool value = false; }; + +template +struct is_mtOpCube< mtOpCube > + { static constexpr bool value = true; }; + + +template +struct is_GlueCube + { static constexpr bool value = false; }; + +template +struct is_GlueCube< GlueCube > + { static constexpr bool value = true; }; + + +template +struct is_eGlueCube + { static constexpr bool value = false; }; + +template +struct is_eGlueCube< eGlueCube > + { static constexpr bool value = true; }; + + +template +struct is_mtGlueCube + { static constexpr bool value = false; }; + +template +struct is_mtGlueCube< mtGlueCube > + { static constexpr bool value = true; }; + + +// +// +// + + +template +struct is_arma_type2 + { + static constexpr bool value + = is_Mat::value + || is_Gen::value + || is_Op::value + || is_Glue::value + || is_eOp::value + || is_eGlue::value + || is_mtOp::value + || is_mtGlue::value + || is_diagview::value + || is_subview::value + || is_subview_row::value + || is_subview_col::value + || is_subview_cols::value + || is_subview_elem1::value + || is_subview_elem2::value + || is_CubeToMatOp::value + || is_SpToDOp::value + || is_SpToDGlue::value + ; + }; + + + +// due to rather baroque C++ rules for proving constant expressions, +// certain compilers may get confused with the combination of conditional inheritance, nested classes and the shenanigans in is_Mat_fixed_only. +// below we explicitly ensure the type is forced to be const, which seems to eliminate the confusion. +template +struct is_arma_type + { + static constexpr bool value = is_arma_type2::value; + }; + + + +template +struct is_arma_cube_type + { + static constexpr bool value + = is_Cube::value + || is_GenCube::value + || is_OpCube::value + || is_eOpCube::value + || is_mtOpCube::value + || is_GlueCube::value + || is_eGlueCube::value + || is_mtGlueCube::value + || is_subview_cube::value + || is_subview_cube_slices::value + ; + }; + + + +// +// +// + + + +template +struct is_SpMat + { static constexpr bool value = false; }; + +template +struct is_SpMat< SpMat > + { static constexpr bool value = true; }; + +template +struct is_SpMat< SpCol > + { static constexpr bool value = true; }; + +template +struct is_SpMat< SpRow > + { static constexpr bool value = true; }; + + + +template +struct is_SpRow + { static constexpr bool value = false; }; + +template +struct is_SpRow< SpRow > + { static constexpr bool value = true; }; + + + +template +struct is_SpCol + { static constexpr bool value = false; }; + +template +struct is_SpCol< SpCol > + { static constexpr bool value = true; }; + + + +template +struct is_SpSubview + { static constexpr bool value = false; }; + +template +struct is_SpSubview< SpSubview > + { static constexpr bool value = true; }; + + +template +struct is_SpSubview_col + { static constexpr bool value = false; }; + +template +struct is_SpSubview_col< SpSubview_col > + { static constexpr bool value = true; }; + + +template +struct is_SpSubview_col_list + { static constexpr bool value = false; }; + +template +struct is_SpSubview_col_list< SpSubview_col_list > + { static constexpr bool value = true; }; + + +template +struct is_SpSubview_row + { static constexpr bool value = false; }; + +template +struct is_SpSubview_row< SpSubview_row > + { static constexpr bool value = true; }; + + +template +struct is_spdiagview + { static constexpr bool value = false; }; + +template +struct is_spdiagview< spdiagview > + { static constexpr bool value = true; }; + + +template +struct is_SpOp + { static constexpr bool value = false; }; + +template +struct is_SpOp< SpOp > + { static constexpr bool value = true; }; + + +template +struct is_SpGlue + { static constexpr bool value = false; }; + +template +struct is_SpGlue< SpGlue > + { static constexpr bool value = true; }; + + +template +struct is_mtSpOp + { static constexpr bool value = false; }; + +template +struct is_mtSpOp< mtSpOp > + { static constexpr bool value = true; }; + + +template +struct is_mtSpGlue + { static constexpr bool value = false; }; + +template +struct is_mtSpGlue< mtSpGlue > + { static constexpr bool value = true; }; + + + +template +struct is_arma_sparse_type + { + static constexpr bool value + = is_SpMat::value + || is_SpSubview::value + || is_SpSubview_col::value + || is_SpSubview_col_list::value + || is_SpSubview_row::value + || is_spdiagview::value + || is_SpOp::value + || is_SpGlue::value + || is_mtSpOp::value + || is_mtSpGlue::value + ; + }; + + + +// +// +// + + +template +struct is_same_type + { + static constexpr bool value = false; + static constexpr bool yes = false; + static constexpr bool no = true; + }; + + +template +struct is_same_type + { + static constexpr bool value = true; + static constexpr bool yes = true; + static constexpr bool no = false; + }; + + + +// +// +// + + +template +struct is_u8 + { static constexpr bool value = false; }; + +template<> +struct is_u8 + { static constexpr bool value = true; }; + + + +template +struct is_s8 + { static constexpr bool value = false; }; + +template<> +struct is_s8 + { static constexpr bool value = true; }; + + + +template +struct is_u16 + { static constexpr bool value = false; }; + +template<> +struct is_u16 + { static constexpr bool value = true; }; + + + +template +struct is_s16 + { static constexpr bool value = false; }; + +template<> +struct is_s16 + { static constexpr bool value = true; }; + + + +template +struct is_u32 + { static constexpr bool value = false; }; + +template<> +struct is_u32 + { static constexpr bool value = true; }; + + + +template +struct is_s32 + { static constexpr bool value = false; }; + +template<> +struct is_s32 + { static constexpr bool value = true; }; + + + +template +struct is_u64 + { static constexpr bool value = false; }; + +template<> +struct is_u64 + { static constexpr bool value = true; }; + + +template +struct is_s64 + { static constexpr bool value = false; }; + +template<> +struct is_s64 + { static constexpr bool value = true; }; + + + +template +struct is_ulng_t + { static constexpr bool value = false; }; + +template<> +struct is_ulng_t + { static constexpr bool value = true; }; + + + +template +struct is_slng_t + { static constexpr bool value = false; }; + +template<> +struct is_slng_t + { static constexpr bool value = true; }; + + + +template +struct is_ulng_t_32 + { static constexpr bool value = false; }; + +template<> +struct is_ulng_t_32 + { static constexpr bool value = (sizeof(ulng_t) == 4); }; + + + +template +struct is_slng_t_32 + { static constexpr bool value = false; }; + +template<> +struct is_slng_t_32 + { static constexpr bool value = (sizeof(slng_t) == 4); }; + + + +template +struct is_ulng_t_64 + { static constexpr bool value = false; }; + +template<> +struct is_ulng_t_64 + { static constexpr bool value = (sizeof(ulng_t) == 8); }; + + + +template +struct is_slng_t_64 + { static constexpr bool value = false; }; + +template<> +struct is_slng_t_64 + { static constexpr bool value = (sizeof(slng_t) == 8); }; + + + +template +struct is_uword + { static constexpr bool value = false; }; + +template<> +struct is_uword + { static constexpr bool value = true; }; + + + +template +struct is_sword + { static constexpr bool value = false; }; + +template<> +struct is_sword + { static constexpr bool value = true; }; + + + +template +struct is_float + { static constexpr bool value = false; }; + +template<> +struct is_float + { static constexpr bool value = true; }; + + + +template +struct is_double + { static constexpr bool value = false; }; + +template<> +struct is_double + { static constexpr bool value = true; }; + + + +template +struct is_real + { + static constexpr bool value = false; + static constexpr bool yes = false; + static constexpr bool no = true; + }; + +template<> +struct is_real + { + static constexpr bool value = true; + static constexpr bool yes = true; + static constexpr bool no = false; + }; + +template<> +struct is_real + { + static constexpr bool value = true; + static constexpr bool yes = true; + static constexpr bool no = false; + }; + + + + +template +struct is_cx + { + static constexpr bool value = false; + static constexpr bool yes = false; + static constexpr bool no = true; + }; + +// template<> +template +struct is_cx< std::complex > + { + static constexpr bool value = true; + static constexpr bool yes = true; + static constexpr bool no = false; + }; + + + +template +struct is_cx_float + { + static constexpr bool value = false; + static constexpr bool yes = false; + static constexpr bool no = true; + }; + +template<> +struct is_cx_float< std::complex > + { + static constexpr bool value = true; + static constexpr bool yes = true; + static constexpr bool no = false; + }; + + + +template +struct is_cx_double + { + static constexpr bool value = false; + static constexpr bool yes = false; + static constexpr bool no = true; + }; + +template<> +struct is_cx_double< std::complex > + { + static constexpr bool value = true; + static constexpr bool yes = true; + static constexpr bool no = false; + }; + + + +template +struct is_supported_elem_type + { + static constexpr bool value = \ + is_u8::value || + is_s8::value || + is_u16::value || + is_s16::value || + is_u32::value || + is_s32::value || + is_u64::value || + is_s64::value || + is_ulng_t::value || + is_slng_t::value || + is_float::value || + is_double::value || + is_cx_float::value || + is_cx_double::value; + }; + + + +template +struct is_supported_blas_type + { + static constexpr bool value = \ + is_float::value || + is_double::value || + is_cx_float::value || + is_cx_double::value; + }; + + + +template +struct has_blas_float_bug + { + #if defined(ARMA_BLAS_FLOAT_BUG) + static constexpr bool value = is_float::result>::value; + #else + static constexpr bool value = false; + #endif + }; + + + +template +struct is_signed + { + static constexpr bool value = true; + }; + + +template<> struct is_signed { static constexpr bool value = false; }; +template<> struct is_signed { static constexpr bool value = false; }; +template<> struct is_signed { static constexpr bool value = false; }; +template<> struct is_signed { static constexpr bool value = false; }; +template<> struct is_signed { static constexpr bool value = false; }; + + +template +struct is_non_integral + { + static constexpr bool value = false; + }; + + +template<> struct is_non_integral< float > { static constexpr bool value = true; }; +template<> struct is_non_integral< double > { static constexpr bool value = true; }; +template<> struct is_non_integral< std::complex > { static constexpr bool value = true; }; +template<> struct is_non_integral< std::complex > { static constexpr bool value = true; }; + + + + +// + +class arma_junk_class; + +template +struct force_different_type + { + typedef T1 T1_result; + typedef T2 T2_result; + }; + + +template +struct force_different_type + { + typedef T1 T1_result; + typedef arma_junk_class T2_result; + }; + + + +// + + +template +struct resolves_to_vector_default + { + static constexpr bool value = false; + static constexpr bool yes = false; + static constexpr bool no = true; + }; + +template +struct resolves_to_vector_test + { + static constexpr bool value = (T1::is_col || T1::is_row || T1::is_xvec); + static constexpr bool yes = (T1::is_col || T1::is_row || T1::is_xvec); + static constexpr bool no = ((T1::is_col || T1::is_row || T1::is_xvec) == false); + }; + + +template +struct resolves_to_vector_redirect {}; + +template +struct resolves_to_vector_redirect { typedef resolves_to_vector_default result; }; + +template +struct resolves_to_vector_redirect { typedef resolves_to_vector_test result; }; + + +template +struct resolves_to_vector : public resolves_to_vector_redirect::value>::result {}; + +template +struct resolves_to_sparse_vector : public resolves_to_vector_redirect::value>::result {}; + +// + +template +struct resolves_to_rowvector_default { static constexpr bool value = false; }; + +template +struct resolves_to_rowvector_test { static constexpr bool value = T1::is_row; }; + + +template +struct resolves_to_rowvector_redirect {}; + +template +struct resolves_to_rowvector_redirect { typedef resolves_to_rowvector_default result; }; + +template +struct resolves_to_rowvector_redirect { typedef resolves_to_rowvector_test result; }; + + +template +struct resolves_to_rowvector : public resolves_to_rowvector_redirect::value>::result {}; + +// + +template +struct resolves_to_colvector_default { static constexpr bool value = false; }; + +template +struct resolves_to_colvector_test { static constexpr bool value = T1::is_col; }; + + +template +struct resolves_to_colvector_redirect {}; + +template +struct resolves_to_colvector_redirect { typedef resolves_to_colvector_default result; }; + +template +struct resolves_to_colvector_redirect { typedef resolves_to_colvector_test result; }; + + +template +struct resolves_to_colvector : public resolves_to_colvector_redirect::value>::result {}; + + + +template +struct is_outer_product + { static constexpr bool value = false; }; + +template +struct is_outer_product< Glue > + { static constexpr bool value = (resolves_to_colvector::value && resolves_to_rowvector::value); }; + + + +template +struct has_op_inv_any + { static constexpr bool value = false; }; + +template +struct has_op_inv_any< Op > + { static constexpr bool value = true; }; + +template +struct has_op_inv_any< Op > + { static constexpr bool value = true; }; + +template +struct has_op_inv_any< Op > + { static constexpr bool value = true; }; + +template +struct has_op_inv_any< Op > + { static constexpr bool value = true; }; + +template +struct has_op_inv_any< Glue, T2, glue_times> > + { static constexpr bool value = true; }; + +template +struct has_op_inv_any< Glue, T2, glue_times> > + { static constexpr bool value = true; }; + +template +struct has_op_inv_any< Glue, T2, glue_times> > + { static constexpr bool value = true; }; + +template +struct has_op_inv_any< Glue, T2, glue_times> > + { static constexpr bool value = true; }; + +template +struct has_op_inv_any< Glue, glue_times> > + { static constexpr bool value = true; }; + +template +struct has_op_inv_any< Glue, glue_times> > + { static constexpr bool value = true; }; + +template +struct has_op_inv_any< Glue, glue_times> > + { static constexpr bool value = true; }; + +template +struct has_op_inv_any< Glue, glue_times> > + { static constexpr bool value = true; }; + + + + +template +struct has_nested_op_traits + { + typedef char yes[1]; + typedef char no[2]; + + template static yes& check(typename X::template traits*); + template static no& check(...); + + static constexpr bool value = ( sizeof(check(0)) == sizeof(yes) ); + }; + +template +struct has_nested_glue_traits + { + typedef char yes[1]; + typedef char no[2]; + + template static yes& check(typename X::template traits*); + template static no& check(...); + + static constexpr bool value = ( sizeof(check(0)) == sizeof(yes) ); + }; + + +//! @} -- cgit v1.2.1