Tomographer
v1.0a
Tomographer C++ Framework Documentation
|
Various useful tools. More...
Classes | |
class | bad_fmts_format |
Exception for bad printf format. More... | |
struct | complex_real_scalar |
The Real scalar type corresponding to a std::complex type. More... | |
struct | complex_real_scalar< std::complex< RealScalar > > |
Implementation of complex_real_scalar for complex types. More... | |
class | conststr |
A constexpr string type. More... | |
class | eigen_assert_exception |
Exception that is thrown upon failed eigen_assert . More... | |
struct | eigen_std_vector |
Use this if you need an std::vector of any Eigen type. More... | |
struct | is_complex |
statically determine whether a type is complex More... | |
struct | SigHandlerTaskDispatcherStatusReporter |
A generic handler which requests a status report from an OMPTaskDispatcher. More... | |
struct | SignalHandler |
An abstract signal handler, in class form. More... | |
class | static_or_dynamic |
A type which stores a value possibly known at compile-time. More... | |
class | static_or_dynamic< T_, Eigen::Dynamic > |
Template Specialization – see static_or_dynamic<T_,Value> More... | |
struct | store_if_enabled |
Utility that stores a data type if a compile-time flag is enabled. More... | |
struct | store_if_enabled< T_, true > |
Specialization of store_if_enabled<T_,enabled> for if we're storing a value. More... | |
Functions | |
template<typename VectorType > | |
void | force_pos_vec_keepsum (Eigen::Ref< VectorType > vec, const typename Eigen::NumTraits< typename VectorType::Scalar >::Real tolerance=1e-8) |
Make sure that the given vector is numerically positive. More... | |
template<typename MatrixType , typename Der > | |
MatrixType | force_pos_semidef (const Eigen::MatrixBase< Der > &rho, const typename Eigen::NumTraits< typename MatrixType::Scalar >::Real tolerance=1e-8) |
Make sure that rho is numerically positive semidefinite. More... | |
template<typename MatrixType > | |
MatrixType | safe_operator_sqrt (const Eigen::Ref< const MatrixType > &A, const typename Eigen::NumTraits< typename MatrixType::Scalar >::Real tolerance=1e-8) |
Safe version of operator square root for positive semidefinite matrices. More... | |
template<typename MatrixType > | |
MatrixType | safe_operator_inv_sqrt (const Eigen::Ref< const MatrixType > &A, const typename Eigen::NumTraits< typename MatrixType::Scalar >::Real tolerance=1e-8) |
Safe version of operator inverse square root for positive semidefinite matrices. More... | |
template<typename X > | |
std::enable_if< std::is_unsigned< X >::value, bool >::type | is_positive (const X) |
Test whether the given value is positive or zero. More... | |
template<typename X > | |
std::enable_if<!std::is_unsigned< X >::value, bool >::type | is_positive (const X val) |
See is_positive() | |
template<typename Der1 , typename Der2 , typename fnType , typename ErrorStream > | |
bool | check_derivatives (const Eigen::ArrayBase< Der1 > &derivatives, const Eigen::MatrixBase< Der2 > &point, fnType fn, std::size_t valdims, typename Eigen::MatrixBase< Der2 >::Scalar delta=1e-6, typename Eigen::MatrixBase< Der1 >::Scalar tol=1e-6, ErrorStream &error_stream=std::cerr) |
Check given derivatives against numerically-calculated finite differences. More... | |
std::string | vfmts (const char *fmt, va_list vl) |
printf- formatting to a std::string , with va_list pointer More... | |
std::string | fmts (const char *fmt,...) |
printf- format to a std::string More... | |
std::string | fmt_duration (double seconds) |
Format a number of seconds into a human-readable string. More... | |
template<typename Rep , typename Period > | |
std::string | fmt_duration (std::chrono::duration< Rep, Period > dt) |
Format a std::chrono::duration into a human-readable string. More... | |
template<typename TaskDispatcher , typename LoggerT > | |
SigHandlerTaskDispatcherStatusReporter< TaskDispatcher, LoggerT > | makeSigHandlerTaskDispatcherStatusReporter (TaskDispatcher *tasks, LoggerT &logger) |
template<typename SigHandler > | |
void | installSignalStatusReportHandler (int signum, SigHandler *sobj) |
Installs the given signal handler to catch the signal signum. More... | |
template<typename F > | |
tomo_internal::FinalAction< F > | finally (F f) |
implementation of a finally clause, somewhat like in Python More... | |
template<typename T > | |
std::ostream & | operator<< (std::ostream &str, store_if_enabled< T, false >) |
C++ Stream operators for store_if_enabled<T,enabled> More... | |
template<typename T > | |
std::ostream & | operator<< (std::ostream &str, store_if_enabled< T, true > val) |
C++ Stream operators for store_if_enabled<T,enabled> More... | |
constexpr bool | is_power_of_two (int N) |
Return true if the argument is a power of two, false otherwise. | |
constexpr conststr | extractFuncName (const conststr &funcname) |
Extract the function name from its signature. More... | |
Various useful tools.
bool Tomographer::Tools::check_derivatives | ( | const Eigen::ArrayBase< Der1 > & | derivatives, |
const Eigen::MatrixBase< Der2 > & | point, | ||
fnType | fn, | ||
std::size_t | valdims, | ||
typename Eigen::MatrixBase< Der2 >::Scalar | delta = 1e-6 , |
||
typename Eigen::MatrixBase< Der1 >::Scalar | tol = 1e-6 , |
||
ErrorStream & | error_stream = std::cerr |
||
) |
Check given derivatives against numerically-calculated finite differences.
This debugging utility is useful for making sure an analytical expression for the derivatives of a function is correct.
The function may be any general vector function, i.e.
\[ f : \mathbb{R}^{\texttt{xdims}} \rightarrow \mathbb{R}^{\texttt{valdims}} , \]
where we denote by \( f_i \) the i -th component of the value calculated by \( f \).
derivatives | the values claimed to be the derivatives of fn at the given point, and which are to be checked against numerically-calculated finite differences. derivatives is an Eigen Array type such that \[ \texttt{derivatives(i,k)} = \frac{\partial f_i}{\partial x_k} \] |
point | the point at which to calculate the function derivatives. It should be a column vector; the number of items in this vector (xdims above) should match the number of columns in derivatives. |
fn | a callable which calculates the values of the function at given points. The first argument is a reference to a vector which should be filled with the function values, the second argument is the point at which to evaluate the function. The object or function fn will be called as Eigen::VectorXd x(xdims) = ...;
Eigen::VectorXd val(valdims);
fn(val, x);
// val[i] should now store the value of f_i(x)
|
valdims | the number of values calculated by fn, or, equivalently, the dimension of the output space of \( f \). |
delta | the step to deviate from point to calculate a finite difference derivative in a particular direction. |
tol | the tolerance we should accept for the difference between the numerically calculated derivative with finite differences, and the given value in derivatives. |
error_stream | If the derivatives don't match, a report is also written to the given stream error_stream, which defaults to std::cerr. |
true
if all checked derivatives were within the given tolerance, or false
if a failure was detected. Definition at line 98 of file check_derivatives.h.
|
inline |
|
inline |
|
inline |
Format a std::chrono::duration into a human-readable string.
This formats the duration into a human-readable string with hours, minutes seconds and milliseconds.
dt | the duration, a std::chrono::duration |
See also fmt_duration(double)
|
inline |
|
inline |
Make sure that rho is numerically positive semidefinite.
This function replaces all eigenvalues that are less than tolerance by the value tolerance, in such a way that the trace of the matrix is preserved.
The original object rho is untouched, and the fixed version is returned.
Definition at line 93 of file pos_semidef_util.h.
|
inline |
Make sure that the given vector is numerically positive.
This function replaces all values in vec that are less than tolerance by the value tolerance, in such a way that the sum of all the elements of the vector is preserved.
The original vector vec is modified.
Definition at line 54 of file pos_semidef_util.h.
void Tomographer::Tools::installSignalStatusReportHandler | ( | int | signum, |
SigHandler * | sobj | ||
) |
Installs the given signal handler to catch the signal signum.
Definition at line 178 of file signal_status_report.h.
|
inline |
|
inline |
|
inline |
|
inline |
Safe version of operator inverse square root for positive semidefinite matrices.
This function first makes sure that the object A is positive semidefinite (à la force_pos_semidef()), before taking the operator inverse square root.
A must be hermitian.
Definition at line 142 of file pos_semidef_util.h.
|
inline |
Safe version of operator square root for positive semidefinite matrices.
This function first makes sure that the object A is positive semidefinite (à la force_pos_semidef()), before taking the operator square root.
A must be hermitian.
Definition at line 118 of file pos_semidef_util.h.
|
inline |
printf-
formatting to a std::string
, with va_list
pointer
Does safe allocation, etc.