max@0
|
1 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
|
max@0
|
2 // Copyright (C) 2008-2011 Conrad Sanderson
|
max@0
|
3 //
|
max@0
|
4 // This file is part of the Armadillo C++ library.
|
max@0
|
5 // It is provided without any warranty of fitness
|
max@0
|
6 // for any purpose. You can redistribute this file
|
max@0
|
7 // and/or modify it under the terms of the GNU
|
max@0
|
8 // Lesser General Public License (LGPL) as published
|
max@0
|
9 // by the Free Software Foundation, either version 3
|
max@0
|
10 // of the License or (at your option) any later version.
|
max@0
|
11 // (see http://www.opensource.org/licenses for more info)
|
max@0
|
12
|
max@0
|
13
|
max@0
|
14 //! \addtogroup fn_min
|
max@0
|
15 //! @{
|
max@0
|
16
|
max@0
|
17 //! \brief
|
max@0
|
18 //! Delayed 'minimum values' operation.
|
max@0
|
19 //! The dimension, along which the minima are found, is set via 'dim'.
|
max@0
|
20 //! For dim = 0, the minimum value of each column is found (i.e. searches by traversing across rows).
|
max@0
|
21 //! For dim = 1, the minimum value of each row is found (i.e. searches by traversing across columns).
|
max@0
|
22 //! The default is dim = 0.
|
max@0
|
23
|
max@0
|
24 template<typename T1>
|
max@0
|
25 arma_inline
|
max@0
|
26 const Op<T1, op_min>
|
max@0
|
27 min(const Base<typename T1::elem_type,T1>& X, const uword dim = 0)
|
max@0
|
28 {
|
max@0
|
29 arma_extra_debug_sigprint();
|
max@0
|
30
|
max@0
|
31 return Op<T1, op_min>(X.get_ref(), dim, 0);
|
max@0
|
32 }
|
max@0
|
33
|
max@0
|
34
|
max@0
|
35 //! Immediate 'find the minimum value in a row vector' operation
|
max@0
|
36 template<typename eT>
|
max@0
|
37 inline
|
max@0
|
38 arma_warn_unused
|
max@0
|
39 eT
|
max@0
|
40 min(const Row<eT>& A)
|
max@0
|
41 {
|
max@0
|
42 arma_extra_debug_sigprint();
|
max@0
|
43
|
max@0
|
44 const uword A_n_elem = A.n_elem;
|
max@0
|
45
|
max@0
|
46 arma_debug_check( (A_n_elem == 0), "min(): given object has no elements" );
|
max@0
|
47
|
max@0
|
48 return op_min::direct_min(A.mem, A_n_elem);
|
max@0
|
49 }
|
max@0
|
50
|
max@0
|
51
|
max@0
|
52
|
max@0
|
53 //! Immediate 'find the minimum value in a column vector'
|
max@0
|
54 template<typename eT>
|
max@0
|
55 inline
|
max@0
|
56 arma_warn_unused
|
max@0
|
57 eT
|
max@0
|
58 min(const Col<eT>& A)
|
max@0
|
59 {
|
max@0
|
60 arma_extra_debug_sigprint();
|
max@0
|
61
|
max@0
|
62 const uword A_n_elem = A.n_elem;
|
max@0
|
63
|
max@0
|
64 arma_debug_check( (A_n_elem == 0), "min(): given object has no elements" );
|
max@0
|
65
|
max@0
|
66 return op_min::direct_min(A.mem, A_n_elem);
|
max@0
|
67 }
|
max@0
|
68
|
max@0
|
69
|
max@0
|
70
|
max@0
|
71 //! \brief
|
max@0
|
72 //! Immediate 'find minimum value' operation,
|
max@0
|
73 //! invoked, for example, by: min(min(A))
|
max@0
|
74 template<typename T1>
|
max@0
|
75 inline
|
max@0
|
76 arma_warn_unused
|
max@0
|
77 typename T1::elem_type
|
max@0
|
78 min(const Op<T1, op_min>& in)
|
max@0
|
79 {
|
max@0
|
80 arma_extra_debug_sigprint();
|
max@0
|
81 arma_extra_debug_print("min(): two consecutive min() calls detected");
|
max@0
|
82
|
max@0
|
83 typedef typename T1::elem_type eT;
|
max@0
|
84
|
max@0
|
85 const unwrap<T1> tmp1(in.m);
|
max@0
|
86 const Mat<eT>& X = tmp1.M;
|
max@0
|
87
|
max@0
|
88 const uword X_n_elem = X.n_elem;
|
max@0
|
89
|
max@0
|
90 arma_debug_check( (X_n_elem == 0), "min(): given object has no elements" );
|
max@0
|
91
|
max@0
|
92 return op_min::direct_min(X.mem, X_n_elem);
|
max@0
|
93 }
|
max@0
|
94
|
max@0
|
95
|
max@0
|
96
|
max@0
|
97 template<typename T1>
|
max@0
|
98 inline
|
max@0
|
99 const Op< Op<T1, op_min>, op_min>
|
max@0
|
100 min(const Op<T1, op_min>& in, const uword dim)
|
max@0
|
101 {
|
max@0
|
102 arma_extra_debug_sigprint();
|
max@0
|
103
|
max@0
|
104 return Op< Op<T1, op_min>, op_min>(in, dim, 0);
|
max@0
|
105 }
|
max@0
|
106
|
max@0
|
107
|
max@0
|
108
|
max@0
|
109 template<typename eT>
|
max@0
|
110 inline
|
max@0
|
111 arma_warn_unused
|
max@0
|
112 eT
|
max@0
|
113 min(const subview_row<eT>& A)
|
max@0
|
114 {
|
max@0
|
115 arma_extra_debug_sigprint();
|
max@0
|
116
|
max@0
|
117 arma_debug_check( (A.n_elem == 0), "min(): given object has no elements" );
|
max@0
|
118
|
max@0
|
119 return op_min::direct_min(A);
|
max@0
|
120 }
|
max@0
|
121
|
max@0
|
122
|
max@0
|
123
|
max@0
|
124 template<typename eT>
|
max@0
|
125 inline
|
max@0
|
126 arma_warn_unused
|
max@0
|
127 eT
|
max@0
|
128 min(const subview_col<eT>& A)
|
max@0
|
129 {
|
max@0
|
130 arma_extra_debug_sigprint();
|
max@0
|
131
|
max@0
|
132 arma_debug_check( (A.n_elem == 0), "min(): given object has no elements" );
|
max@0
|
133
|
max@0
|
134 return op_min::direct_min(A.colptr(0), A.n_rows);
|
max@0
|
135 }
|
max@0
|
136
|
max@0
|
137
|
max@0
|
138
|
max@0
|
139 template<typename eT>
|
max@0
|
140 inline
|
max@0
|
141 arma_warn_unused
|
max@0
|
142 eT
|
max@0
|
143 min(const diagview<eT>& A)
|
max@0
|
144 {
|
max@0
|
145 arma_extra_debug_sigprint();
|
max@0
|
146
|
max@0
|
147 arma_debug_check( (A.n_elem == 0), "min(): given object has no elements" );
|
max@0
|
148
|
max@0
|
149 return op_min::direct_min(A);
|
max@0
|
150 }
|
max@0
|
151
|
max@0
|
152
|
max@0
|
153
|
max@0
|
154 template<typename eT>
|
max@0
|
155 inline
|
max@0
|
156 arma_warn_unused
|
max@0
|
157 eT
|
max@0
|
158 min(const Op<subview<eT>, op_min>& in)
|
max@0
|
159 {
|
max@0
|
160 arma_extra_debug_sigprint();
|
max@0
|
161 arma_extra_debug_print("min(): two consecutive min() calls detected");
|
max@0
|
162
|
max@0
|
163 const subview<eT>& X = in.m;
|
max@0
|
164
|
max@0
|
165 arma_debug_check( (X.n_elem == 0), "min(): given object has no elements" );
|
max@0
|
166
|
max@0
|
167 return op_min::direct_min(X);
|
max@0
|
168 }
|
max@0
|
169
|
max@0
|
170
|
max@0
|
171
|
max@0
|
172 template<typename eT, typename T1>
|
max@0
|
173 inline
|
max@0
|
174 arma_warn_unused
|
max@0
|
175 eT
|
max@0
|
176 min(const subview_elem1<eT,T1>& A)
|
max@0
|
177 {
|
max@0
|
178 arma_extra_debug_sigprint();
|
max@0
|
179
|
max@0
|
180 const Mat<eT> X(A);
|
max@0
|
181
|
max@0
|
182 const uword X_n_elem = X.n_elem;
|
max@0
|
183
|
max@0
|
184 arma_debug_check( (X_n_elem == 0), "min(): given object has no elements" );
|
max@0
|
185
|
max@0
|
186 return op_min::direct_min(X.mem, X_n_elem);
|
max@0
|
187 }
|
max@0
|
188
|
max@0
|
189
|
max@0
|
190
|
max@0
|
191 //! @}
|