1 // SPDX-License-Identifier: Apache-2.0
2 //
3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
4 // Copyright 2008-2016 National ICT Australia (NICTA)
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // ------------------------------------------------------------------------
17 
18 
19 //! \addtogroup fn_index_max
20 //! @{
21 
22 
23 template<typename T1>
24 arma_warn_unused
25 inline
26 typename enable_if2< is_arma_type<T1>::value && resolves_to_vector<T1>::yes, uword>::result
index_max(const T1 & X)27 index_max(const T1& X)
28   {
29   arma_extra_debug_sigprint();
30 
31   return X.index_max();
32   }
33 
34 
35 
36 template<typename T1>
37 arma_warn_unused
38 arma_inline
39 typename enable_if2< is_arma_type<T1>::value && resolves_to_vector<T1>::no, const mtOp<uword, T1, op_index_max> >::result
index_max(const T1 & X)40 index_max(const T1& X)
41   {
42   arma_extra_debug_sigprint();
43 
44   return mtOp<uword, T1, op_index_max>(X, 0, 0);
45   }
46 
47 
48 
49 template<typename T1>
50 arma_warn_unused
51 arma_inline
52 typename enable_if2< is_arma_type<T1>::value, const mtOp<uword, T1, op_index_max> >::result
index_max(const T1 & X,const uword dim)53 index_max(const T1& X, const uword dim)
54   {
55   arma_extra_debug_sigprint();
56 
57   return mtOp<uword, T1, op_index_max>(X, dim, 0);
58   }
59 
60 
61 
62 template<typename T1>
63 arma_warn_unused
64 arma_inline
65 const mtOpCube<uword, T1, op_index_max>
index_max(const BaseCube<typename T1::elem_type,T1> & X,const uword dim=0)66 index_max
67   (
68   const BaseCube<typename T1::elem_type, T1>& X,
69   const uword dim = 0
70   )
71   {
72   arma_extra_debug_sigprint();
73 
74   return mtOpCube<uword, T1, op_index_max>(X.get_ref(), dim, 0, 0);
75   }
76 
77 
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>::yes,
86   typename T1::elem_type
87   >::result
index_max(const T1 & x)88 index_max(const T1& x)
89   {
90   arma_extra_debug_sigprint();
91 
92   return x.index_max();
93   }
94 
95 
96 
97 template<typename T1>
98 arma_warn_unused
99 inline
100 typename
101 enable_if2
102   <
103   is_arma_sparse_type<T1>::value && resolves_to_sparse_vector<T1>::no,
104   Mat<uword>
105   >::result
index_max(const T1 & X)106 index_max(const T1& X)
107   {
108   arma_extra_debug_sigprint();
109 
110   Mat<uword> out;
111 
112   op_index_max::apply(out, X, 0);
113 
114   return out;
115   }
116 
117 
118 
119 template<typename T1>
120 arma_warn_unused
121 inline
122 typename
123 enable_if2
124   <
125   is_arma_sparse_type<T1>::value,
126   Mat<uword>
127   >::result
index_max(const T1 & X,const uword dim)128 index_max(const T1& X, const uword dim)
129   {
130   arma_extra_debug_sigprint();
131 
132   Mat<uword> out;
133 
134   op_index_max::apply(out, X, dim);
135 
136   return out;
137   }
138 
139 
140 
141 arma_warn_unused
142 inline
143 uword
index_max(const SizeMat & s)144 index_max(const SizeMat& s)
145   {
146   return (s.n_rows >= s.n_cols) ? uword(0) : uword(1);
147   }
148 
149 
150 
151 arma_warn_unused
152 inline
153 uword
index_max(const SizeCube & s)154 index_max(const SizeCube& s)
155   {
156   const uword tmp_val   = (s.n_rows >= s.n_cols) ? s.n_rows : s.n_cols;
157   const uword tmp_index = (s.n_rows >= s.n_cols) ? uword(0) : uword(1);
158 
159   return (tmp_val >= s.n_slices) ? tmp_index : uword(2);
160   }
161 
162 
163 
164 //! @}
165