Base_bones.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup Base
  16. //! @{
  17. template<typename elem_type, typename derived>
  18. struct Base_extra_yes
  19. {
  20. inline arma_warn_unused const Op<derived,op_inv> i() const; //!< matrix inverse
  21. arma_deprecated inline const Op<derived,op_inv> i(const bool ) const; //!< kept only for compatibility with old user code
  22. arma_deprecated inline const Op<derived,op_inv> i(const char*) const; //!< kept only for compatibility with old user code
  23. inline arma_warn_unused bool is_sympd() const;
  24. inline arma_warn_unused bool is_sympd(typename get_pod_type<elem_type>::result tol) const;
  25. };
  26. template<typename elem_type, typename derived>
  27. struct Base_extra_no
  28. {
  29. };
  30. template<typename elem_type, typename derived, bool condition>
  31. struct Base_extra {};
  32. template<typename elem_type, typename derived>
  33. struct Base_extra<elem_type, derived, true> { typedef Base_extra_yes<elem_type, derived> result; };
  34. template<typename elem_type, typename derived>
  35. struct Base_extra<elem_type, derived, false> { typedef Base_extra_no<elem_type, derived> result; };
  36. template<typename elem_type, typename derived>
  37. struct Base_eval_Mat
  38. {
  39. arma_inline const derived& eval() const;
  40. };
  41. template<typename elem_type, typename derived>
  42. struct Base_eval_expr
  43. {
  44. arma_inline Mat<elem_type> eval() const; //!< force the immediate evaluation of a delayed expression
  45. };
  46. template<typename elem_type, typename derived, bool condition>
  47. struct Base_eval {};
  48. template<typename elem_type, typename derived>
  49. struct Base_eval<elem_type, derived, true> { typedef Base_eval_Mat<elem_type, derived> result; };
  50. template<typename elem_type, typename derived>
  51. struct Base_eval<elem_type, derived, false> { typedef Base_eval_expr<elem_type, derived> result; };
  52. template<typename derived>
  53. struct Base_trans_cx
  54. {
  55. arma_inline const Op<derived,op_htrans> t() const;
  56. arma_inline const Op<derived,op_htrans> ht() const;
  57. arma_inline const Op<derived,op_strans> st() const; // simple transpose: no complex conjugates
  58. };
  59. template<typename derived>
  60. struct Base_trans_default
  61. {
  62. arma_inline const Op<derived,op_htrans> t() const;
  63. arma_inline const Op<derived,op_htrans> ht() const;
  64. arma_inline const Op<derived,op_htrans> st() const; // return op_htrans instead of op_strans, as it's handled better by matrix multiplication code
  65. };
  66. template<typename derived, bool condition>
  67. struct Base_trans {};
  68. template<typename derived>
  69. struct Base_trans<derived, true> { typedef Base_trans_cx<derived> result; };
  70. template<typename derived>
  71. struct Base_trans<derived, false> { typedef Base_trans_default<derived> result; };
  72. //! Class for static polymorphism, modelled after the "Curiously Recurring Template Pattern" (CRTP).
  73. //! Used for type-safe downcasting in functions that restrict their input(s) to be classes that are
  74. //! derived from Base (e.g. Mat, Op, Glue, diagview, subview).
  75. //! A Base object can be converted to a Mat object by the unwrap class.
  76. template<typename elem_type, typename derived>
  77. struct Base
  78. : public Base_extra<elem_type, derived, is_supported_blas_type<elem_type>::value>::result
  79. , public Base_eval<elem_type, derived, is_Mat<derived>::value>::result
  80. , public Base_trans<derived, is_cx<elem_type>::value>::result
  81. {
  82. arma_inline const derived& get_ref() const;
  83. arma_cold inline void print( const std::string extra_text = "") const;
  84. arma_cold inline void print(std::ostream& user_stream, const std::string extra_text = "") const;
  85. arma_cold inline void raw_print( const std::string extra_text = "") const;
  86. arma_cold inline void raw_print(std::ostream& user_stream, const std::string extra_text = "") const;
  87. inline arma_warn_unused elem_type min() const;
  88. inline arma_warn_unused elem_type max() const;
  89. inline elem_type min(uword& index_of_min_val) const;
  90. inline elem_type max(uword& index_of_max_val) const;
  91. inline elem_type min(uword& row_of_min_val, uword& col_of_min_val) const;
  92. inline elem_type max(uword& row_of_max_val, uword& col_of_max_val) const;
  93. inline arma_warn_unused uword index_min() const;
  94. inline arma_warn_unused uword index_max() const;
  95. inline arma_warn_unused bool is_symmetric() const;
  96. inline arma_warn_unused bool is_symmetric(const typename get_pod_type<elem_type>::result tol) const;
  97. inline arma_warn_unused bool is_hermitian() const;
  98. inline arma_warn_unused bool is_hermitian(const typename get_pod_type<elem_type>::result tol) const;
  99. inline arma_warn_unused bool is_zero(const typename get_pod_type<elem_type>::result tol = 0) const;
  100. inline arma_warn_unused bool is_trimatu() const;
  101. inline arma_warn_unused bool is_trimatl() const;
  102. inline arma_warn_unused bool is_diagmat() const;
  103. inline arma_warn_unused bool is_empty() const;
  104. inline arma_warn_unused bool is_square() const;
  105. inline arma_warn_unused bool is_vec() const;
  106. inline arma_warn_unused bool is_colvec() const;
  107. inline arma_warn_unused bool is_rowvec() const;
  108. inline arma_warn_unused bool is_finite() const;
  109. inline arma_warn_unused bool has_inf() const;
  110. inline arma_warn_unused bool has_nan() const;
  111. inline arma_warn_unused const Op<derived,op_vectorise_col> as_col() const;
  112. inline arma_warn_unused const Op<derived,op_vectorise_row> as_row() const;
  113. };
  114. //! @}