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_sort_index
20 //! @{
21 
22 
23 
24 template<typename T1>
25 arma_warn_unused
26 arma_inline
27 const mtOp<uword,T1,op_sort_index>
sort_index(const Base<typename T1::elem_type,T1> & X)28 sort_index
29   (
30   const Base<typename T1::elem_type,T1>& X
31   )
32   {
33   arma_extra_debug_sigprint();
34 
35   return mtOp<uword,T1,op_sort_index>(X.get_ref(), uword(0), uword(0));
36   }
37 
38 
39 
40 template<typename T1, typename T2>
41 arma_warn_unused
42 inline
43 typename
44 enable_if2
45   <
46   ( (is_arma_type<T1>::value) && (is_same_type<T2, char>::value) ),
47   const mtOp<uword,T1,op_sort_index>
48   >::result
sort_index(const T1 & X,const T2 * sort_direction)49 sort_index
50   (
51   const T1& X,
52   const T2* sort_direction
53   )
54   {
55   arma_extra_debug_sigprint();
56 
57   const char sig = (sort_direction != nullptr) ? sort_direction[0] : char(0);
58 
59   arma_debug_check( ((sig != 'a') && (sig != 'd')), "sort_index(): unknown sort direction" );
60 
61   return mtOp<uword,T1,op_sort_index>(X, ((sig == 'a') ? uword(0) : uword(1)), uword(0));
62   }
63 
64 
65 
66 //
67 
68 
69 
70 template<typename T1>
71 arma_warn_unused
72 arma_inline
73 const mtOp<uword,T1,op_stable_sort_index>
stable_sort_index(const Base<typename T1::elem_type,T1> & X)74 stable_sort_index
75   (
76   const Base<typename T1::elem_type,T1>& X
77   )
78   {
79   arma_extra_debug_sigprint();
80 
81   return mtOp<uword,T1,op_stable_sort_index>(X.get_ref(), uword(0), uword(0));
82   }
83 
84 
85 
86 template<typename T1, typename T2>
87 arma_warn_unused
88 inline
89 typename
90 enable_if2
91   <
92   ( (is_arma_type<T1>::value) && (is_same_type<T2, char>::value) ),
93   const mtOp<uword,T1,op_stable_sort_index>
94   >::result
stable_sort_index(const T1 & X,const T2 * sort_direction)95 stable_sort_index
96   (
97   const T1& X,
98   const T2* sort_direction
99   )
100   {
101   arma_extra_debug_sigprint();
102 
103   const char sig = (sort_direction != nullptr) ? sort_direction[0] : char(0);
104 
105   arma_debug_check( ((sig != 'a') && (sig != 'd')), "stable_sort_index(): unknown sort direction" );
106 
107   return mtOp<uword,T1,op_stable_sort_index>(X, ((sig == 'a') ? uword(0) : uword(1)), uword(0));
108   }
109 
110 
111 
112 //! @}
113