C++ Mathematical Expression Library (ExprTk) https://www.partow.net/programming/exprtk/index.html
This commit is contained in:
parent
ee85192eb9
commit
061d61ecc9
73
exprtk.hpp
73
exprtk.hpp
|
@ -2436,7 +2436,7 @@ namespace exprtk
|
||||||
/*
|
/*
|
||||||
Permit symbols that contain a 'dot'
|
Permit symbols that contain a 'dot'
|
||||||
Allowed : abc.xyz, a123.xyz, abc.123, abc_.xyz a123_.xyz abc._123
|
Allowed : abc.xyz, a123.xyz, abc.123, abc_.xyz a123_.xyz abc._123
|
||||||
Disallowed: abc.<white-space>, abc.<eof>
|
Disallowed: abc.<white-space>, abc.<eof>, abc.<operator +,-,*,/...>
|
||||||
*/
|
*/
|
||||||
if (
|
if (
|
||||||
!is_end(s_itr_ + 1) &&
|
!is_end(s_itr_ + 1) &&
|
||||||
|
@ -4377,18 +4377,18 @@ namespace exprtk
|
||||||
namespace loop_unroll
|
namespace loop_unroll
|
||||||
{
|
{
|
||||||
#ifndef exprtk_disable_superscalar_unroll
|
#ifndef exprtk_disable_superscalar_unroll
|
||||||
const std::size_t global_loop_batch_size = 16;
|
const unsigned int global_loop_batch_size = 16;
|
||||||
#else
|
#else
|
||||||
const std::size_t global_loop_batch_size = 4;
|
const unsigned int global_loop_batch_size = 4;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct details
|
struct details
|
||||||
{
|
{
|
||||||
details(const std::size_t& vsize,
|
details(const std::size_t& vsize,
|
||||||
const std::size_t loop_batch_size = global_loop_batch_size)
|
const unsigned int loop_batch_size = global_loop_batch_size)
|
||||||
: batch_size(loop_batch_size),
|
: batch_size(loop_batch_size),
|
||||||
remainder (vsize % batch_size),
|
remainder (vsize % batch_size),
|
||||||
upper_bound(static_cast<int>(vsize - (remainder ? loop_batch_size : 0)))
|
upper_bound(static_cast<int>(vsize) - (remainder ? loop_batch_size : 0))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
int batch_size;
|
int batch_size;
|
||||||
|
@ -36286,6 +36286,11 @@ namespace exprtk
|
||||||
|
|
||||||
nthelement()
|
nthelement()
|
||||||
: exprtk::igeneric_function<T>("VT|VTTT")
|
: exprtk::igeneric_function<T>("VT|VTTT")
|
||||||
|
/*
|
||||||
|
Overloads:
|
||||||
|
0. VT - vector, nth-element
|
||||||
|
1. VTTT - vector, nth-element, r0, r1
|
||||||
|
*/
|
||||||
{}
|
{}
|
||||||
|
|
||||||
inline T operator()(const std::size_t& ps_index, parameter_list_t parameters)
|
inline T operator()(const std::size_t& ps_index, parameter_list_t parameters)
|
||||||
|
@ -36310,6 +36315,61 @@ namespace exprtk
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class iota : public exprtk::igeneric_function<T>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef typename exprtk::igeneric_function<T> igfun_t;
|
||||||
|
typedef typename igfun_t::parameter_list_t parameter_list_t;
|
||||||
|
typedef typename igfun_t::generic_type generic_type;
|
||||||
|
typedef typename generic_type::scalar_view scalar_t;
|
||||||
|
typedef typename generic_type::vector_view vector_t;
|
||||||
|
|
||||||
|
using exprtk::igeneric_function<T>::operator();
|
||||||
|
|
||||||
|
iota()
|
||||||
|
: exprtk::igeneric_function<T>("VT|VTT|VTTT|VTTTT")
|
||||||
|
/*
|
||||||
|
Overloads:
|
||||||
|
0. VT - vector, increment
|
||||||
|
1. VT - vector, increment, base
|
||||||
|
2. VT - vector, increment, r0, r1
|
||||||
|
3. VT - vector, increment, base, r0, r1
|
||||||
|
*/
|
||||||
|
{}
|
||||||
|
|
||||||
|
inline T operator()(const std::size_t& ps_index, parameter_list_t parameters)
|
||||||
|
{
|
||||||
|
vector_t vec(parameters[0]);
|
||||||
|
|
||||||
|
T increment = scalar_t(parameters[1])();
|
||||||
|
T base = ((1 == ps_index) || (3 == ps_index))? scalar_t(parameters[2])() : T(0);
|
||||||
|
|
||||||
|
std::size_t r0 = 0;
|
||||||
|
std::size_t r1 = vec.size() - 1;
|
||||||
|
|
||||||
|
if ((2 == ps_index) && !details::load_vector_range<T>::process(parameters,r0,r1,2,3))
|
||||||
|
return std::numeric_limits<T>::quiet_NaN();
|
||||||
|
else if ((3 == ps_index) && !details::load_vector_range<T>::process(parameters,r0,r1,3,4))
|
||||||
|
return std::numeric_limits<T>::quiet_NaN();
|
||||||
|
|
||||||
|
if (details::invalid_range(vec,r0,r1))
|
||||||
|
return std::numeric_limits<T>::quiet_NaN();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
long long j = 0;
|
||||||
|
|
||||||
|
for (std::size_t i = r0; i <= r1; ++i, ++j)
|
||||||
|
{
|
||||||
|
vec[i] = base + (increment * j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return T(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class sumk : public exprtk::igeneric_function<T>
|
class sumk : public exprtk::igeneric_function<T>
|
||||||
{
|
{
|
||||||
|
@ -36721,6 +36781,7 @@ namespace exprtk
|
||||||
shift_right<T> sr;
|
shift_right<T> sr;
|
||||||
sort <T> st;
|
sort <T> st;
|
||||||
nthelement <T> ne;
|
nthelement <T> ne;
|
||||||
|
iota <T> ia;
|
||||||
sumk <T> sk;
|
sumk <T> sk;
|
||||||
axpy <T> b1_axpy;
|
axpy <T> b1_axpy;
|
||||||
axpby <T> b1_axpby;
|
axpby <T> b1_axpby;
|
||||||
|
@ -36760,6 +36821,8 @@ namespace exprtk
|
||||||
return false;
|
return false;
|
||||||
else if (!symtab.add_function("nth_element" ,ne))
|
else if (!symtab.add_function("nth_element" ,ne))
|
||||||
return false;
|
return false;
|
||||||
|
else if (!symtab.add_function("iota" ,ia))
|
||||||
|
return false;
|
||||||
else if (!symtab.add_function("sumk" ,sk))
|
else if (!symtab.add_function("sumk" ,sk))
|
||||||
return false;
|
return false;
|
||||||
else if (!symtab.add_function("axpy" ,b1_axpy))
|
else if (!symtab.add_function("axpy" ,b1_axpy))
|
||||||
|
|
|
@ -6556,6 +6556,12 @@ inline bool run_test18()
|
||||||
"var v[9] := {7,8,9,1,2,3,4,5,6}; nth_element(v,trunc(v[] / 2)); sort(v,0,trunc(v[] / 2)); (v[v[] / 2] == 5) and (v[0] == 1)",
|
"var v[9] := {7,8,9,1,2,3,4,5,6}; nth_element(v,trunc(v[] / 2)); sort(v,0,trunc(v[] / 2)); (v[v[] / 2] == 5) and (v[0] == 1)",
|
||||||
"var v[9] := {7,8,9,1,2,3,4,5,6}; nth_element(v,trunc(v[] / 3)); sort(v,0,trunc(v[] / 3)); (v[v[] / 3] == 4) and (v[0] == 1)",
|
"var v[9] := {7,8,9,1,2,3,4,5,6}; nth_element(v,trunc(v[] / 3)); sort(v,0,trunc(v[] / 3)); (v[v[] / 3] == 4) and (v[0] == 1)",
|
||||||
|
|
||||||
|
"var v[5]; iota(v,2); var r[5] := {0,2,4,6,8}; sum(v == r) == v[]",
|
||||||
|
"var v[5]; iota(v,2,1); var r[5] := {1,3,5,7,9}; sum(v == r) == v[]",
|
||||||
|
"var v[5]; iota(v,1,1,3); var r[5] := {0,0,1,2,0}; sum(v == r) == v[]",
|
||||||
|
"var v[5]; iota(v,2,2,1,3);var r[5] := {0,2,4,6,0}; sum(v == r) == v[]",
|
||||||
|
"var v[5]; iota(v,2,1,1,3);var r[5] := {0,1,3,5,0}; sum(v == r) == v[]",
|
||||||
|
|
||||||
" var a := 2; var x[3] := {1,2,3}; var y[3] := {1,2,3}; var r[3] := [0]; r := a * x + y; axpy(a,x,y); sum(y == r) == y[]",
|
" var a := 2; var x[3] := {1,2,3}; var y[3] := {1,2,3}; var r[3] := [0]; r := a * x + y; axpy(a,x,y); sum(y == r) == y[]",
|
||||||
" var a := 2; var b := 3; var x[3] := {1,2,3}; var y[3] := {1,2,3}; var r[3] := [0]; r := a * x + b * y; axpby(a,x,b,y); sum(y == r) == y[]",
|
" var a := 2; var b := 3; var x[3] := {1,2,3}; var y[3] := {1,2,3}; var r[3] := [0]; r := a * x + b * y; axpby(a,x,b,y); sum(y == r) == y[]",
|
||||||
|
|
||||||
|
|
|
@ -2735,10 +2735,11 @@ file I/O package is made available for the given expression:
|
||||||
(g) rotate-left (h) rotate-right
|
(g) rotate-left (h) rotate-right
|
||||||
(i) shift-left (j) shift-right
|
(i) shift-left (j) shift-right
|
||||||
(k) sort (l) nth_element
|
(k) sort (l) nth_element
|
||||||
(m) sumk (n) axpy
|
(m) iota (n) sumk
|
||||||
(o) axpby (p) axpyz
|
(o) axpy (p) axpby
|
||||||
(q) axpbyz (r) axpbz
|
(q) axpyz (r) axpbyz
|
||||||
(s) dot (t) dotk
|
(s) axpbz (t) dot
|
||||||
|
(u) dotk
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue