comparison armadillo-2.4.4/include/armadillo_bits/fn_min.hpp @ 0:8b6102e2a9b0

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