IT++
4.3.1
Toggle main menu visibility
itpp
base
math
log_exp.cpp
Go to the documentation of this file.
1
28
29
#include <
itpp/base/math/log_exp.h
>
30
#include <
itpp/base/itcompat.h
>
31
32
namespace
itpp
33
{
34
35
// log-2 of the elements
36
vec
log2
(
const
vec &x) {
return
apply_function<double>
(
::log2
, x); }
37
mat
log2
(
const
mat &x) {
return
apply_function<double>
(
::log2
, x); }
38
39
// Safe substitute for <tt>log(exp(log_a) + exp(log_b))</tt>
40
double
log_add
(
double
log_a,
double
log_b)
41
{
42
if
(log_a < log_b) {
43
double
tmp = log_a;
44
log_a = log_b;
45
log_b = tmp;
46
}
47
double
negdelta = log_b - log_a;
48
if
((negdelta <
log_double_min
) || std::isnan(negdelta))
49
return
log_a;
50
else
51
return
(log_a + log1p(std::exp(negdelta)));
52
}
53
54
}
itpp::log_add
double log_add(double log_a, double log_b)
Safe substitute for log(exp(log_a) + exp(log_b)).
Definition
log_exp.cpp:40
itpp::log_double_min
const double log_double_min
Constant definition to speed up trunc_log(), trunc_exp() and log_add().
Definition
log_exp.h:101
itpp::log2
vec log2(const vec &x)
log-2 of the elements
Definition
log_exp.cpp:36
itpp::apply_function
Vec< T > apply_function(T(*f)(T), const Vec< T > &v)
Help function to call for a function: Vec<T> function(Vec<T>).
Definition
help_functions.h:124
itcompat.h
IT++ compatibility types and functions.
log_exp.h
Logarithmic and exponenential functions - header file.
itpp
itpp namespace
Definition
itmex.h:37
Generated by
1.17.0