72# define POSITION_TRACE (std::string(__FILE__) + ":" + std::to_string(__LINE__))
83 template <
class T,
class Compare = Aleph::less<T>>
84 inline const T *
median(
const T & a,
const T & b,
const T & c,
const Compare &
cmp = Compare())
88 if (
cmp(b, c))
return &b;
89 if (
cmp(a, c))
return &c;
92 if (
cmp(a, c))
return &a;
93 if (
cmp(b, c))
return &c;
126 const char ret = i < 10 ? i +
'0' : i - 10 +
'A';
141 const int ret = c <
'A' ? c -
'0' : c -
'A' + 10;
159# define DERIVATE_ITERATOR(container_name, base_it_name, it_name) \
160 struct it_name : public base_it_name \
164 it_name(container_name & c) : base_it_name(c) \
169 it_name(const it_name & it) : base_it_name(it) \
174 it_name & operator = (const it_name & it) \
176 return base_it_name::operator = (it); \
226 return x && ! (x & (x - 1UL));
239 unsigned long ret = 1;
256 {abi::__cxa_demangle(name,
nullptr,
nullptr, &status), std::free};
257 return (status == 0) ?
res.
get() : name;
264# define CLASSNAME_TO_STRING(class_ptr) ::Aleph::demangle(typeid(*class_ptr).name())
272 std::cerr << msg <<
'\n';
283 return (
stat(name.c_str(), &buffer) == 0);
292 inline std::string
Rvector(
const std::string & name,
const C & c)
294 std::ostringstream s;
295 s << name <<
" <- c(";
297 for (
auto it = c.get_it(); it.has_curr(); it.next())
299 auto & v = it.get_curr();
320 std::ostringstream s;
321 s << c.get_first() <<
" <- c(";
323 for (
auto it = c.get_it(1); it.has_curr(); it.next())
325 auto & v = it.get_curr();
351 const double y1,
const double y2,
const double x)
354 return y1 + (y2 -
y1) * (x - x1) / (x2 - x1);
373 const double y1,
const double y2,
const double x)
376 return y1 - (y2 -
y1) * (x1 - x) / (x2 - x1);
382 inline double pow2(
const double x) {
return x * x; }
387 inline double pow3(
const double x) {
return x *
pow2(x); }
405 const double y1,
const double y2,
const double x)
408 return y2 + (y2 -
y1) * (x - x2) / (x2 - x1);
417 return nextafter(val, std::numeric_limits<double>::max());
427 return nextafter(val, std::numeric_limits<double>::min());
434 [[
nodiscard]]
constexpr bool are_near(
const double v1,
const double v2,
const double e)
noexcept {
return std::fabs(v1 - v2) <= e; }
447 std::ofstream
tmp(file_name);
448 tmp <<
"#!/usr/bin/Rscript" <<
'\n'
452 <<
"message(\"Press Return To Continue\")" <<
'\n'
453 <<
"invisible(readLines(\"stdin\", n=1))" <<
'\n';
454 const std::string
cmd =
"Rscript " + file_name;
471 if constexpr (std::numeric_limits<double>::is_iec559 &&
472 sizeof(
double) ==
sizeof(std::uint64_t))
475 std::uint64_t bits = 0;
476 std::memcpy(&bits, &n,
sizeof(bits));
478 constexpr std::uint64_t
exp_mask = 0x7ff0000000000000ULL;
479 constexpr std::uint64_t
frac_mask = 0x000fffffffffffffULL;
493 if (
not std::isfinite(n))
496 const int status = std::fpclassify(n);
Standard functor implementations and comparison objects.
T & get_last() const
Return the last item of the list.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_y1_function > > y1(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_frac_function > > frac(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_exp_function > > exp(const __gmp_expr< T, U > &expr)
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Main namespace for Aleph-w library functions.
size_t l_index(const size_t i)
Map a binary heap index to the index of its left child.
double next_value(const double val)
Return the next representable floating-point value to val
unsigned long next_power_of_2(unsigned long x)
In x is not exact power of 2, it returns the next power of 2.
void error_msg(const std::string &msg)
Display message and abort program execution.
const T * median(const T &a, const T &b, const T &c, const Compare &cmp=Compare())
Return a pointer to the median value among three elements.
constexpr bool are_near(const double v1, const double v2, const double e) noexcept
Return true if v1 is within absolute distance e of v2.
double extrapolate_right(const double x1, const double x2, const double y1, const double y2, const double x)
Basic linear extrapolation.
std::decay_t< typename HeadC::Item_Type > T
size_t u_index(const size_t &i)
Map a binary heap index to the index of its parent.
double interpolate(const double x1, const double x2, const double y1, const double y2, const double x)
Basic linear interpolation.
double prev_value(const double val)
Return the next representable floating-point value of val towards the smallest positive normal number...
bool is_even(const long n)
Return true if n is even.
double pow2(const double x)
Return x^2.
char nibble_to_char(const int i)
Convert a 4-bit nibble stored in an int to its hex character.
bool exists_file(const std::string &name)
Return true if it exists a file of name
bool resize_process_stack(size_t new_size)
Resize the process stack to new_size.
int char_to_nibble(const char c)
Convert a hex character in 0..9A..F to its 4-bit nibble value.
std::string Rvector(const std::string &name, const C &c)
Return a string with R specification of a vector with name and data stored in container c
bool is_normal_number(const double n)
Return true if a floating-point number is normal or zero.
std::string demangle(const char *name)
Given a linker symbol name generated by a c++ compiler, this functions decodes it into a user level n...
double extrapolate_left(const double x1, const double x2, const double y1, const double y2, const double x)
Basic linear extrapolation.
double pow3(const double x)
Return x^3.
bool is_power_of_2(unsigned long x)
Taken from http://stackoverflow.com/questions/3638431/determine-if-an-int-is-a-power-of-2-or-not-in-a...
DynList< T > maps(const C &c, Op op)
Classic map operation.
void execute_R_script(const std::string &scr, const std::string &file_name="tmp.R")
Generate and execute a R script from a string (containing the script)