fn_index_max.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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_index_max
  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, uword>::result
  21. index_max(const T1& X)
  22. {
  23. arma_extra_debug_sigprint();
  24. return X.index_max();
  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 mtOp<uword, T1, op_index_max> >::result
  30. index_max(const T1& X)
  31. {
  32. arma_extra_debug_sigprint();
  33. return mtOp<uword, T1, op_index_max>(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 mtOp<uword, T1, op_index_max> >::result
  39. index_max(const T1& X, const uword dim)
  40. {
  41. arma_extra_debug_sigprint();
  42. return mtOp<uword, T1, op_index_max>(X, dim, 0);
  43. }
  44. template<typename T1>
  45. arma_warn_unused
  46. arma_inline
  47. const mtOpCube<uword, T1, op_index_max>
  48. index_max
  49. (
  50. const BaseCube<typename T1::elem_type, T1>& X,
  51. const uword dim = 0
  52. )
  53. {
  54. arma_extra_debug_sigprint();
  55. return mtOpCube<uword, T1, op_index_max>(X.get_ref(), dim, 0, 0);
  56. }
  57. template<typename T1>
  58. arma_warn_unused
  59. inline
  60. typename
  61. enable_if2
  62. <
  63. is_arma_sparse_type<T1>::value && resolves_to_sparse_vector<T1>::yes,
  64. typename T1::elem_type
  65. >::result
  66. index_max(const T1& x)
  67. {
  68. arma_extra_debug_sigprint();
  69. return x.index_max();
  70. }
  71. template<typename T1>
  72. arma_warn_unused
  73. inline
  74. typename
  75. enable_if2
  76. <
  77. is_arma_sparse_type<T1>::value && resolves_to_sparse_vector<T1>::no,
  78. Mat<uword>
  79. >::result
  80. index_max(const T1& X)
  81. {
  82. arma_extra_debug_sigprint();
  83. Mat<uword> out;
  84. op_index_max::apply(out, X, 0);
  85. return out;
  86. }
  87. template<typename T1>
  88. arma_warn_unused
  89. inline
  90. typename
  91. enable_if2
  92. <
  93. is_arma_sparse_type<T1>::value,
  94. Mat<uword>
  95. >::result
  96. index_max(const T1& X, const uword dim)
  97. {
  98. arma_extra_debug_sigprint();
  99. Mat<uword> out;
  100. op_index_max::apply(out, X, dim);
  101. return out;
  102. }
  103. arma_warn_unused
  104. inline
  105. uword
  106. index_max(const SizeMat& s)
  107. {
  108. return (s.n_rows >= s.n_cols) ? uword(0) : uword(1);
  109. }
  110. arma_warn_unused
  111. inline
  112. uword
  113. index_max(const SizeCube& s)
  114. {
  115. const uword tmp_val = (s.n_rows >= s.n_cols) ? s.n_rows : s.n_cols;
  116. const uword tmp_index = (s.n_rows >= s.n_cols) ? uword(0) : uword(1);
  117. return (tmp_val >= s.n_slices) ? tmp_index : uword(2);
  118. }
  119. //! @}