fn_mean.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 fn_mean
  16. //! @{
  17. template<typename T1>
  18. arma_warn_unused
  19. inline
  20. typename enable_if2< is_arma_type<T1>::value && resolves_to_vector<T1>::yes, typename T1::elem_type >::result
  21. mean(const T1& X)
  22. {
  23. arma_extra_debug_sigprint();
  24. return op_mean::mean_all(X);
  25. }
  26. template<typename T1>
  27. arma_warn_unused
  28. arma_inline
  29. typename enable_if2< is_arma_type<T1>::value && resolves_to_vector<T1>::no, const Op<T1, op_mean> >::result
  30. mean(const T1& X)
  31. {
  32. arma_extra_debug_sigprint();
  33. return Op<T1, op_mean>(X, 0, 0);
  34. }
  35. template<typename T1>
  36. arma_warn_unused
  37. arma_inline
  38. typename enable_if2< is_arma_type<T1>::value, const Op<T1, op_mean> >::result
  39. mean(const T1& X, const uword dim)
  40. {
  41. arma_extra_debug_sigprint();
  42. return Op<T1, op_mean>(X, dim, 0);
  43. }
  44. template<typename T>
  45. arma_warn_unused
  46. arma_inline
  47. typename arma_scalar_only<T>::result
  48. mean(const T& x)
  49. {
  50. return x;
  51. }
  52. template<typename T1>
  53. arma_warn_unused
  54. arma_inline
  55. const OpCube<T1, op_mean>
  56. mean
  57. (
  58. const BaseCube<typename T1::elem_type,T1>& X,
  59. const uword dim = 0
  60. )
  61. {
  62. arma_extra_debug_sigprint();
  63. return OpCube<T1, op_mean>(X.get_ref(), dim, 0);
  64. }
  65. template<typename T1>
  66. arma_warn_unused
  67. inline
  68. typename
  69. enable_if2
  70. <
  71. is_arma_sparse_type<T1>::value && resolves_to_sparse_vector<T1>::yes,
  72. typename T1::elem_type
  73. >::result
  74. mean(const T1& x)
  75. {
  76. arma_extra_debug_sigprint();
  77. return spop_mean::mean_all(x);
  78. }
  79. template<typename T1>
  80. arma_warn_unused
  81. inline
  82. typename
  83. enable_if2
  84. <
  85. is_arma_sparse_type<T1>::value && resolves_to_sparse_vector<T1>::no,
  86. const SpOp<T1,spop_mean>
  87. >::result
  88. mean(const T1& x)
  89. {
  90. arma_extra_debug_sigprint();
  91. return SpOp<T1,spop_mean>(x, 0, 0);
  92. }
  93. template<typename T1>
  94. arma_warn_unused
  95. inline
  96. typename
  97. enable_if2
  98. <
  99. is_arma_sparse_type<T1>::value,
  100. const SpOp<T1,spop_mean>
  101. >::result
  102. mean(const T1& x, const uword dim)
  103. {
  104. arma_extra_debug_sigprint();
  105. return SpOp<T1,spop_mean>(x, dim, 0);
  106. }
  107. //! @}