fn_misc.hpp
Go to the documentation of this file.
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 
16 
17 
18 
22 
23 template<typename vec_type>
24 inline
25 vec_type
27  (
28  const typename vec_type::pod_type start,
29  const typename vec_type::pod_type end,
30  const uword num = 100u,
32  )
33  {
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  {
92  return linspace<mat>(start, end, num);
93  }
94 
95 
96 
97 //
98 // log_add
99 
100 template<typename eT>
101 inline
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>
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
144 bool
146  {
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
162 bool
164  {
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>
181  {
183 
184  return Op<T1, op_sympd>(X.get_ref());
185  }
186 
187 
188 
arma_float_only< eT >::result log_add(eT log_a, eT log_b)
Definition: fn_misc.hpp:103
arma_inline const eOp< T1, eop_exp > exp(const Base< typename T1::elem_type, T1 > &A)
Definition: fn_elem.hpp:237
arma_inline const derived & get_ref() const
Definition: Base_meat.hpp:22
arma_inline arma_warn_unused bool is_finite(const eT x, const typename arma_scalar_only< eT >::result *junk=0)
Definition: fn_misc.hpp:132
vec_type linspace(const typename vec_type::pod_type start, const typename vec_type::pod_type end, const uword num=100u, const typename arma_Mat_Col_Row_only< vec_type >::result *junk=0)
Generate a vector with &#39;num&#39; elements. The values of the elements linearly increase from &#39;start&#39; upto...
Definition: fn_misc.hpp:27
u32 uword
Definition: typedef.hpp:85
#define arma_ignore(variable)
Dense cube class.
Definition: Cube_bones.hpp:30
arma_inline Op< T1, op_sympd > sympd(const Base< typename T1::elem_type, T1 > &X)
Definition: fn_misc.hpp:180
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
Analog of the Base class, intended for cubes.
#define arma_warn_unused
Dense matrix class.
#define arma_inline
arma_inline const derived & get_ref() const
arma_inline const eOp< T1, eop_log > log(const Base< typename T1::elem_type, T1 > &A)
Definition: fn_elem.hpp:156
arma_inline bool arma_isfinite(eT val)
Definition: cmath_wrap.hpp:29


armadillo_matrix
Author(s):
autogenerated on Fri Apr 16 2021 02:31:57