Mercurial > hg > segmenter-vamp-plugin
comparison armadillo-2.4.4/include/armadillo_bits/fn_misc.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_misc | |
15 //! @{ | |
16 | |
17 | |
18 | |
19 //! \brief | |
20 //! Generate a vector with 'num' elements. | |
21 //! The values of the elements linearly increase from 'start' upto (and including) 'end'. | |
22 | |
23 template<typename vec_type> | |
24 inline | |
25 vec_type | |
26 linspace | |
27 ( | |
28 const typename vec_type::pod_type start, | |
29 const typename vec_type::pod_type end, | |
30 const uword num = 100u, | |
31 const typename arma_Mat_Col_Row_only<vec_type>::result* junk = 0 | |
32 ) | |
33 { | |
34 arma_extra_debug_sigprint(); | |
35 arma_ignore(junk); | |
36 | |
37 typedef typename vec_type::elem_type eT; | |
38 typedef typename vec_type::pod_type T; | |
39 | |
40 vec_type x; | |
41 | |
42 if(num >= 2) | |
43 { | |
44 x.set_size(num); | |
45 | |
46 eT* x_mem = x.memptr(); | |
47 | |
48 const uword num_m1 = num - 1; | |
49 | |
50 if(is_non_integral<T>::value == true) | |
51 { | |
52 const T delta = (end-start)/T(num_m1); | |
53 | |
54 for(uword i=0; i<num_m1; ++i) | |
55 { | |
56 x_mem[i] = eT(start + i*delta); | |
57 } | |
58 | |
59 x_mem[num_m1] = eT(end); | |
60 } | |
61 else | |
62 { | |
63 const double delta = (end >= start) ? double(end-start)/double(num_m1) : -double(start-end)/double(num_m1); | |
64 | |
65 for(uword i=0; i<num_m1; ++i) | |
66 { | |
67 x_mem[i] = eT(double(start) + i*delta); | |
68 } | |
69 | |
70 x_mem[num_m1] = eT(end); | |
71 } | |
72 | |
73 return x; | |
74 } | |
75 else | |
76 { | |
77 x.set_size(1); | |
78 | |
79 x[0] = eT(end); | |
80 } | |
81 | |
82 return x; | |
83 } | |
84 | |
85 | |
86 | |
87 inline | |
88 mat | |
89 linspace(const double start, const double end, const uword num = 100u) | |
90 { | |
91 arma_extra_debug_sigprint(); | |
92 return linspace<mat>(start, end, num); | |
93 } | |
94 | |
95 | |
96 | |
97 // | |
98 // log_add | |
99 | |
100 template<typename eT> | |
101 inline | |
102 typename arma_float_only<eT>::result | |
103 log_add(eT log_a, eT log_b) | |
104 { | |
105 if(log_a < log_b) | |
106 { | |
107 std::swap(log_a, log_b); | |
108 } | |
109 | |
110 const eT negdelta = log_b - log_a; | |
111 | |
112 if( (negdelta < Math<eT>::log_min()) || (arma_isfinite(negdelta) == false) ) | |
113 { | |
114 return log_a; | |
115 } | |
116 else | |
117 { | |
118 #if defined(ARMA_HAVE_LOG1P) | |
119 return (log_a + log1p(std::exp(negdelta))); | |
120 #else | |
121 return (log_a + std::log(1.0 + std::exp(negdelta))); | |
122 #endif | |
123 } | |
124 } | |
125 | |
126 | |
127 | |
128 template<typename eT> | |
129 arma_inline | |
130 arma_warn_unused | |
131 bool | |
132 is_finite(const eT x, const typename arma_scalar_only<eT>::result* junk = 0) | |
133 { | |
134 arma_ignore(junk); | |
135 | |
136 return arma_isfinite(x); | |
137 } | |
138 | |
139 | |
140 | |
141 template<typename T1> | |
142 inline | |
143 arma_warn_unused | |
144 bool | |
145 is_finite(const Base<typename T1::elem_type,T1>& X) | |
146 { | |
147 arma_extra_debug_sigprint(); | |
148 | |
149 typedef typename T1::elem_type eT; | |
150 | |
151 const unwrap<T1> tmp(X.get_ref()); | |
152 const Mat<eT>& A = tmp.M; | |
153 | |
154 return A.is_finite(); | |
155 } | |
156 | |
157 | |
158 | |
159 template<typename T1> | |
160 inline | |
161 arma_warn_unused | |
162 bool | |
163 is_finite(const BaseCube<typename T1::elem_type,T1>& X) | |
164 { | |
165 arma_extra_debug_sigprint(); | |
166 | |
167 typedef typename T1::elem_type eT; | |
168 | |
169 const unwrap_cube<T1> tmp(X.get_ref()); | |
170 const Cube<eT>& A = tmp.M; | |
171 | |
172 return A.is_finite(); | |
173 } | |
174 | |
175 | |
176 | |
177 template<typename T1> | |
178 arma_inline | |
179 Op<T1, op_sympd> | |
180 sympd(const Base<typename T1::elem_type,T1>& X) | |
181 { | |
182 arma_extra_debug_sigprint(); | |
183 | |
184 return Op<T1, op_sympd>(X.get_ref()); | |
185 } | |
186 | |
187 | |
188 | |
189 //! @} |