16#if __cplusplus > 201402L
17#define R__RVEC_NODISCARD [[nodiscard]]
19#define R__RVEC_NODISCARD
24 #ifndef _USE_MATH_DEFINES
25 #define _USE_MATH_DEFINES
29 #undef _USE_MATH_DEFINES
31 #define _VECOPS_USE_EXTERN_TEMPLATES false
33 #define _VECOPS_USE_EXTERN_TEMPLATES true
56#include <vdt/vdtMath.h>
81constexpr bool All(
const bool *vals, std::size_t
size)
83 for (
auto i = 0u; i <
size; ++i)
89template <
typename... T>
92 constexpr const auto nArgs =
sizeof...(T);
93 const std::size_t sizes[] = {vs.
size()...};
95 for (
auto i = 1UL; i < nArgs; i++) {
96 if (sizes[0] == sizes[i])
99 msg +=
": input RVec instances have different lengths!";
100 throw std::runtime_error(msg);
106template <
typename F,
typename... RVecs>
112 for (
auto i = 0UL; i <
size; i++)
113 ret[i] =
f(vs[i]...);
118template <
typename Tuple_t, std::size_t... Is>
120 ->
decltype(
MapImpl(std::get<std::tuple_size<Tuple_t>::value - 1>(t), std::get<Is>(t)...))
122 constexpr const auto tupleSizeM1 = std::tuple_size<Tuple_t>::value - 1;
123 return MapImpl(std::get<tupleSizeM1>(t), std::get<Is>(t)...);
155 static constexpr size_t SizeTypeMax() {
return std::numeric_limits<Size_T>::max(); }
163 void grow_pod(
void *FirstEl,
size_t MinSize,
size_t TSize);
167 static void report_size_overflow(
size_t MinSize);
170 static void report_at_maximum_capacity();
193 throw std::runtime_error(
"Setting size to a value greater than capacity.");
216 return const_cast<void *
>(
reinterpret_cast<const void *
>(
reinterpret_cast<const char *
>(
this) +
289 throw std::runtime_error(
"`front` called on an empty RVec");
297 throw std::runtime_error(
"`front` called on an empty RVec");
305 throw std::runtime_error(
"`back` called on an empty RVec");
313 throw std::runtime_error(
"`back` called on an empty RVec");
327template <
typename T,
bool = (std::is_trivially_copy_constructible<T>::value) &&
328 (std::is_trivially_move_constructible<T>::value) &&
329 std::is_trivially_destructible<T>::value>
344 template <
typename It1,
typename It2>
347 std::uninitialized_copy(std::make_move_iterator(
I), std::make_move_iterator(E), Dest);
352 template <
typename It1,
typename It2>
355 std::uninitialized_copy(
I, E, Dest);
368 ::new ((
void *)this->
end()) T(Elt);
376 ::new ((
void *)this->
end()) T(::std::move(Elt));
388template <
typename T,
bool TriviallyCopyable>
393 if (MinSize > this->SizeTypeMax())
394 this->report_size_overflow(MinSize);
400 if (this->capacity() == this->SizeTypeMax())
401 this->report_at_maximum_capacity();
404 size_t NewCapacity = size_t(
NextPowerOf2(this->capacity() + 2));
405 NewCapacity = std::min(std::max(NewCapacity, MinSize), this->SizeTypeMax());
406 T *NewElts =
static_cast<T *
>(
malloc(NewCapacity *
sizeof(T)));
410 this->uninitialized_move(this->begin(), this->end(), NewElts);
414 destroy_range(this->begin(), this->end());
417 if (!this->isSmall())
421 this->fBeginX = NewElts;
422 this->fCapacity = NewCapacity;
441 template <
typename It1,
typename It2>
450 template <
typename It1,
typename It2>
454 std::uninitialized_copy(
I, E, Dest);
459 template <
typename T1,
typename T2>
462 typename std::enable_if<std::is_same<
typename std::remove_const<T1>::type,
T2>::value>
::type * =
nullptr)
469 memcpy(
reinterpret_cast<void *
>(Dest),
I, (E -
I) *
sizeof(T));
489 memcpy(
reinterpret_cast<void *
>(this->
end()), &Elt,
sizeof(T));
498template <
typename T,
unsigned N>
526template <
typename ForwardIt>
529#if __cplusplus < 201703L
530 for (; first != last; ++first)
531 new (
static_cast<void *
>(std::addressof(*first)))
typename std::iterator_traits<ForwardIt>::value_type();
533 std::uninitialized_value_construct(first, last);
599 }
else if (
N > this->
size()) {
602 for (
auto I = this->
end(), E = this->
begin() +
N;
I != E; ++
I)
614 }
else if (
N > this->
size()) {
617 std::uninitialized_fill(this->
end(), this->
begin() +
N, NV);
630 if (this->
size() < NumItems) {
631 throw std::runtime_error(
"Popping back more elements than those available.");
640 T Result = ::std::move(this->
back());
648 template <
typename in_iter,
649 typename =
typename std::enable_if<std::is_convertible<
650 typename std::iterator_traits<in_iter>::iterator_category, std::input_iterator_tag>::value>
::type>
651 void append(in_iter in_start, in_iter in_end)
653 size_type NumInputs = std::distance(in_start, in_end);
655 this->
grow(this->
size() + NumInputs);
665 this->
grow(this->
size() + NumInputs);
667 std::uninitialized_fill_n(this->
end(), NumInputs, Elt);
671 void append(std::initializer_list<T> IL) {
append(IL.begin(), IL.end()); }
683 std::uninitialized_fill(this->
begin(), this->
end(), Elt);
686 template <
typename in_iter,
687 typename =
typename std::enable_if<std::is_convertible<
688 typename std::iterator_traits<in_iter>::iterator_category, std::input_iterator_tag>::value>
::type>
689 void assign(in_iter in_start, in_iter in_end)
707 throw std::runtime_error(
"The iterator passed to `erase` is out of bounds.");
712 std::move(
I + 1, this->
end(),
I);
724 if (S < this->
begin() || E > this->
end() || S > E) {
725 throw std::runtime_error(
"Invalid start/end pair passed to `erase` (out of bounds or start > end).");
740 if (
I == this->
end()) {
742 return this->
end() - 1;
746 throw std::runtime_error(
"The iterator passed to `insert` is out of bounds.");
750 size_t EltNo =
I - this->
begin();
752 I = this->begin() + EltNo;
755 ::new ((
void *)this->
end()) T(::std::move(this->
back()));
757 std::move_backward(
I, this->
end() - 1, this->
end());
763 if (
I <= EltPtr && EltPtr < this->
end())
766 *
I = ::std::move(*EltPtr);
772 if (
I == this->
end()) {
774 return this->
end() - 1;
778 throw std::runtime_error(
"The iterator passed to `insert` is out of bounds.");
782 size_t EltNo =
I - this->
begin();
784 I = this->begin() + EltNo;
786 ::new ((
void *)this->
end()) T(std::move(this->
back()));
788 std::move_backward(
I, this->
end() - 1, this->
end());
793 const T *EltPtr = &Elt;
794 if (
I <= EltPtr && EltPtr < this->
end())
804 size_t InsertElt =
I - this->
begin();
806 if (
I == this->
end()) {
808 return this->begin() + InsertElt;
812 throw std::runtime_error(
"The iterator passed to `insert` is out of bounds.");
819 I = this->begin() + InsertElt;
825 if (
size_t(this->
end() -
I) >= NumToInsert) {
826 T *OldEnd = this->
end();
827 append(std::move_iterator<iterator>(this->
end() - NumToInsert), std::move_iterator<iterator>(this->
end()));
830 std::move_backward(
I, OldEnd - NumToInsert, OldEnd);
832 std::fill_n(
I, NumToInsert, Elt);
840 T *OldEnd = this->
end();
842 size_t NumOverwritten = OldEnd -
I;
846 std::fill_n(
I, NumOverwritten, Elt);
849 std::uninitialized_fill_n(OldEnd, NumToInsert - NumOverwritten, Elt);
853 template <
typename ItTy,
854 typename =
typename std::enable_if<std::is_convertible<
855 typename std::iterator_traits<ItTy>::iterator_category, std::input_iterator_tag>::value>
::type>
859 size_t InsertElt =
I - this->
begin();
861 if (
I == this->
end()) {
863 return this->begin() + InsertElt;
867 throw std::runtime_error(
"The iterator passed to `insert` is out of bounds.");
870 size_t NumToInsert = std::distance(From, To);
876 I = this->begin() + InsertElt;
882 if (
size_t(this->
end() -
I) >= NumToInsert) {
883 T *OldEnd = this->
end();
884 append(std::move_iterator<iterator>(this->
end() - NumToInsert), std::move_iterator<iterator>(this->
end()));
887 std::move_backward(
I, OldEnd - NumToInsert, OldEnd);
889 std::copy(From, To,
I);
897 T *OldEnd = this->
end();
899 size_t NumOverwritten = OldEnd -
I;
903 for (T *J =
I; NumOverwritten > 0; --NumOverwritten) {
916 template <
typename... ArgTypes>
921 ::new ((
void *)this->
end()) T(std::forward<ArgTypes>(Args)...);
949 temp = std::move(RHS);
950 RHS = std::move(*
this);
951 *
this = std::move(
temp);
953 }
else if (RHS.
isSmall() && !this->Owns()) {
955 temp = std::move(*
this);
956 *
this = std::move(RHS);
957 RHS = std::move(
temp);
961 if (RHS.
size() > this->capacity())
967 size_t NumShared = this->
size();
968 if (NumShared > RHS.
size())
969 NumShared = RHS.
size();
970 for (
size_type i = 0; i != NumShared; ++i)
971 std::iter_swap(this->
begin() + i, RHS.
begin() + i);
975 size_t EltDiff = this->
size() - RHS.
size();
981 }
else if (RHS.
size() > this->size()) {
982 size_t EltDiff = RHS.
size() - this->
size();
1000 size_t RHSSize = RHS.
size();
1001 size_t CurSize = this->
size();
1002 if (CurSize >= RHSSize) {
1006 NewEnd = std::copy(RHS.
begin(), RHS.
begin() + RHSSize, this->begin());
1008 NewEnd = this->
begin();
1030 this->
grow(RHSSize);
1031 }
else if (CurSize) {
1033 std::copy(RHS.
begin(), RHS.
begin() + CurSize, this->begin());
1044template <
typename T>
1052 if (!RHS.isSmall()) {
1059 this->
fSize = RHS.fSize;
1067 size_t RHSSize = RHS.size();
1068 size_t CurSize = this->
size();
1069 if (CurSize >= RHSSize) {
1073 NewEnd = std::move(RHS.begin(), RHS.end(), NewEnd);
1098 this->
grow(RHSSize);
1099 }
else if (CurSize) {
1101 std::move(RHS.begin(), RHS.begin() + CurSize, this->begin());
1114template <
typename T>
1120template <
typename T>
1148template <
typename T,
unsigned int N>
1171 template <
typename ItTy,
1172 typename =
typename std::enable_if<std::is_convertible<
1173 typename std::iterator_traits<ItTy>::iterator_category, std::input_iterator_tag>::value>
::type>
1241 return begin()[idx];
1246 return begin()[idx];
1249 template <typename V, unsigned M, typename = std::enable_if<std::is_convertible<V, bool>::value>>
1254 if (
n != this->
size()) {
1255 std::string msg =
"Cannot index RVecN of size " + std::to_string(this->
size()) +
1256 " with condition vector of different size (" + std::to_string(
n) +
").";
1257 throw std::runtime_error(msg);
1261 for (
auto c : conds)
1265 ret.reserve(n_true);
1268 ret.push_back(this->
operator[](i));
1275 template <typename U, unsigned M, typename = std::enable_if<std::is_convertible<T, U>::value>>
1284 std::string msg =
"RVecN::at: size is " + std::to_string(this->
fSize) +
" but out-of-bounds index " +
1285 std::to_string(
pos) +
" was requested.";
1286 throw std::out_of_range(msg);
1294 std::string msg =
"RVecN::at: size is " + std::to_string(this->
fSize) +
" but out-of-bounds index " +
1295 std::to_string(
pos) +
" was requested.";
1296 throw std::out_of_range(msg);
1524template <
typename T>
1525class R__CLING_PTRCHECK(off)
RVec :
public RVecN<T, Internal::VecOps::RVecInlineStorageSize<T>::value> {
1544 template <
typename ItTy,
1545 typename =
typename std::enable_if<std::is_convertible<
1546 typename std::iterator_traits<ItTy>::iterator_category, std::input_iterator_tag>::value>
::type>
1571 template <
unsigned N>
1574 template <
unsigned N>
1582 template <typename U, typename = std::enable_if<std::is_convertible<T, U>::value>>
1588 using SuperClass::operator[];
1590 template <typename V, typename = std::enable_if<std::is_convertible<V, bool>::value>>
1593 return RVec(SuperClass::operator[](conds));
1603template <
typename T,
unsigned N>
1606 return X.capacity_in_bytes();
1612#define RVEC_UNARY_OPERATOR(OP) \
1613template <typename T> \
1614RVec<T> operator OP(const RVec<T> &v) \
1617 for (auto &x : ret) \
1626#undef RVEC_UNARY_OPERATOR
1632#define ERROR_MESSAGE(OP) \
1633 "Cannot call operator " #OP " on vectors of different sizes."
1635#define RVEC_BINARY_OPERATOR(OP) \
1636template <typename T0, typename T1> \
1637auto operator OP(const RVec<T0> &v, const T1 &y) \
1638 -> RVec<decltype(v[0] OP y)> \
1640 RVec<decltype(v[0] OP y)> ret(v.size()); \
1641 auto op = [&y](const T0 &x) { return x OP y; }; \
1642 std::transform(v.begin(), v.end(), ret.begin(), op); \
1646template <typename T0, typename T1> \
1647auto operator OP(const T0 &x, const RVec<T1> &v) \
1648 -> RVec<decltype(x OP v[0])> \
1650 RVec<decltype(x OP v[0])> ret(v.size()); \
1651 auto op = [&x](const T1 &y) { return x OP y; }; \
1652 std::transform(v.begin(), v.end(), ret.begin(), op); \
1656template <typename T0, typename T1> \
1657auto operator OP(const RVec<T0> &v0, const RVec<T1> &v1) \
1658 -> RVec<decltype(v0[0] OP v1[0])> \
1660 if (v0.size() != v1.size()) \
1661 throw std::runtime_error(ERROR_MESSAGE(OP)); \
1663 RVec<decltype(v0[0] OP v1[0])> ret(v0.size()); \
1664 auto op = [](const T0 &x, const T1 &y) { return x OP y; }; \
1665 std::transform(v0.begin(), v0.end(), v1.begin(), ret.begin(), op); \
1677#undef RVEC_BINARY_OPERATOR
1683#define RVEC_ASSIGNMENT_OPERATOR(OP) \
1684template <typename T0, typename T1> \
1685RVec<T0>& operator OP(RVec<T0> &v, const T1 &y) \
1687 auto op = [&y](T0 &x) { return x OP y; }; \
1688 std::transform(v.begin(), v.end(), v.begin(), op); \
1692template <typename T0, typename T1> \
1693RVec<T0>& operator OP(RVec<T0> &v0, const RVec<T1> &v1) \
1695 if (v0.size() != v1.size()) \
1696 throw std::runtime_error(ERROR_MESSAGE(OP)); \
1698 auto op = [](T0 &x, const T1 &y) { return x OP y; }; \
1699 std::transform(v0.begin(), v0.end(), v1.begin(), v0.begin(), op); \
1713#undef RVEC_ASSIGNMENT_OPERATOR
1719#define RVEC_LOGICAL_OPERATOR(OP) \
1720template <typename T0, typename T1> \
1721auto operator OP(const RVec<T0> &v, const T1 &y) \
1724 RVec<int> ret(v.size()); \
1725 auto op = [y](const T0 &x) -> int { return x OP y; }; \
1726 std::transform(v.begin(), v.end(), ret.begin(), op); \
1730template <typename T0, typename T1> \
1731auto operator OP(const T0 &x, const RVec<T1> &v) \
1734 RVec<int> ret(v.size()); \
1735 auto op = [x](const T1 &y) -> int { return x OP y; }; \
1736 std::transform(v.begin(), v.end(), ret.begin(), op); \
1740template <typename T0, typename T1> \
1741auto operator OP(const RVec<T0> &v0, const RVec<T1> &v1) \
1744 if (v0.size() != v1.size()) \
1745 throw std::runtime_error(ERROR_MESSAGE(OP)); \
1747 RVec<int> ret(v0.size()); \
1748 auto op = [](const T0 &x, const T1 &y) -> int { return x OP y; }; \
1749 std::transform(v0.begin(), v0.end(), v1.begin(), ret.begin(), op); \
1761#undef RVEC_LOGICAL_OPERATOR
1768template <
typename T>
struct PromoteTypeImpl;
1770template <>
struct PromoteTypeImpl<float> {
using Type = float; };
1771template <>
struct PromoteTypeImpl<
double> {
using Type =
double; };
1772template <>
struct PromoteTypeImpl<long
double> {
using Type =
long double; };
1774template <
typename T>
struct PromoteTypeImpl {
using Type = double; };
1776template <
typename T>
1777using PromoteType =
typename PromoteTypeImpl<T>::Type;
1779template <
typename U,
typename V>
1780using PromoteTypes =
decltype(PromoteType<U>() + PromoteType<V>());
1784#define RVEC_UNARY_FUNCTION(NAME, FUNC) \
1785 template <typename T> \
1786 RVec<PromoteType<T>> NAME(const RVec<T> &v) \
1788 RVec<PromoteType<T>> ret(v.size()); \
1789 auto f = [](const T &x) { return FUNC(x); }; \
1790 std::transform(v.begin(), v.end(), ret.begin(), f); \
1794#define RVEC_BINARY_FUNCTION(NAME, FUNC) \
1795 template <typename T0, typename T1> \
1796 RVec<PromoteTypes<T0, T1>> NAME(const T0 &x, const RVec<T1> &v) \
1798 RVec<PromoteTypes<T0, T1>> ret(v.size()); \
1799 auto f = [&x](const T1 &y) { return FUNC(x, y); }; \
1800 std::transform(v.begin(), v.end(), ret.begin(), f); \
1804 template <typename T0, typename T1> \
1805 RVec<PromoteTypes<T0, T1>> NAME(const RVec<T0> &v, const T1 &y) \
1807 RVec<PromoteTypes<T0, T1>> ret(v.size()); \
1808 auto f = [&y](const T0 &x) { return FUNC(x, y); }; \
1809 std::transform(v.begin(), v.end(), ret.begin(), f); \
1813 template <typename T0, typename T1> \
1814 RVec<PromoteTypes<T0, T1>> NAME(const RVec<T0> &v0, const RVec<T1> &v1) \
1816 if (v0.size() != v1.size()) \
1817 throw std::runtime_error(ERROR_MESSAGE(NAME)); \
1819 RVec<PromoteTypes<T0, T1>> ret(v0.size()); \
1820 auto f = [](const T0 &x, const T1 &y) { return FUNC(x, y); }; \
1821 std::transform(v0.begin(), v0.end(), v1.begin(), ret.begin(), f); \
1825#define RVEC_STD_UNARY_FUNCTION(F) RVEC_UNARY_FUNCTION(F, std::F)
1826#define RVEC_STD_BINARY_FUNCTION(F) RVEC_BINARY_FUNCTION(F, std::F)
1873#undef RVEC_STD_UNARY_FUNCTION
1880#define RVEC_VDT_UNARY_FUNCTION(F) RVEC_UNARY_FUNCTION(F, vdt::F)
1882RVEC_VDT_UNARY_FUNCTION(fast_expf)
1883RVEC_VDT_UNARY_FUNCTION(fast_logf)
1884RVEC_VDT_UNARY_FUNCTION(fast_sinf)
1885RVEC_VDT_UNARY_FUNCTION(fast_cosf)
1886RVEC_VDT_UNARY_FUNCTION(fast_tanf)
1887RVEC_VDT_UNARY_FUNCTION(fast_asinf)
1888RVEC_VDT_UNARY_FUNCTION(fast_acosf)
1889RVEC_VDT_UNARY_FUNCTION(fast_atanf)
1891RVEC_VDT_UNARY_FUNCTION(fast_exp)
1892RVEC_VDT_UNARY_FUNCTION(fast_log)
1893RVEC_VDT_UNARY_FUNCTION(fast_sin)
1894RVEC_VDT_UNARY_FUNCTION(fast_cos)
1895RVEC_VDT_UNARY_FUNCTION(fast_tan)
1896RVEC_VDT_UNARY_FUNCTION(fast_asin)
1897RVEC_VDT_UNARY_FUNCTION(fast_acos)
1898RVEC_VDT_UNARY_FUNCTION(fast_atan)
1899#undef RVEC_VDT_UNARY_FUNCTION
1903#undef RVEC_UNARY_FUNCTION
1918template <
typename T,
typename V>
1921 if (
v0.size() !=
v1.size())
1922 throw std::runtime_error(
"Cannot compute inner product of vectors of different sizes");
1923 return std::inner_product(
v0.begin(),
v0.end(),
v1.begin(),
decltype(
v0[0] *
v1[0])(0));
1949template <
typename T>
1952 return std::accumulate(
v.begin(),
v.end(), zero);
1957 return std::accumulate(
v.begin(),
v.end(), zero);
1961template <
typename T>
1964 return std::accumulate(
v.begin(),
v.end(), init, std::multiplies<T>());
1979template <
typename T>
1982 if (
v.empty())
return 0.;
2011template <
typename T,
typename R = T>
2014 if (
v.empty())
return zero;
2015 return Sum(
v, zero) /
v.size();
2028template <
typename T>
2031 return *std::max_element(
v.begin(),
v.end());
2044template <
typename T>
2047 return *std::min_element(
v.begin(),
v.end());
2062template <
typename T>
2065 return std::distance(
v.begin(), std::max_element(
v.begin(),
v.end()));
2080template <
typename T>
2083 return std::distance(
v.begin(), std::min_element(
v.begin(),
v.end()));
2097template <
typename T>
2100 const std::size_t
size =
v.size();
2101 if (
size < std::size_t(2))
return 0.;
2102 T sum_squares(0), squared_sum(0);
2103 auto pred = [&sum_squares, &squared_sum](
const T&
x) {sum_squares+=
x*
x; squared_sum+=
x;};
2104 std::for_each(
v.begin(),
v.end(), pred);
2105 squared_sum *= squared_sum;
2107 return 1. / (dsize - 1.) * (sum_squares - squared_sum / dsize );
2121template <
typename T>
2124 return std::sqrt(
Var(
v));
2145template <
typename... Args>
2158 constexpr auto nArgs =
sizeof...(Args);
2161 "Map: the first N-1 arguments must be RVecs or references to RVecs");
2164 std::make_index_sequence<
sizeof...(args) - 1>());
2177template <
typename T,
typename F>
2180 const auto thisSize =
v.size();
2182 w.reserve(thisSize);
2183 for (
auto &&val :
v) {
2185 w.emplace_back(val);
2200template <
typename T>
2204 if (
static_cast<bool>(
e) ==
true)
2219template <
typename T>
2223 if (
static_cast<bool>(
e) ==
false)
2228template <
typename T>
2245template <
typename T>
2251 std::sort(i.
begin(), i.
end(), [&
v](size_type i1, size_type i2) { return v[i1] < v[i2]; });
2266template <
typename T,
typename Compare>
2273 [&
v, &
c](size_type i1, size_type i2) { return c(v[i1], v[i2]); });
2290template <
typename T>
2296 std::stable_sort(i.
begin(), i.
end(), [&
v](size_type i1, size_type i2) { return v[i1] < v[i2]; });
2313template <
typename T,
typename Compare>
2319 std::stable_sort(i.
begin(), i.
end(), [&
v, &
c](size_type i1, size_type i2) { return c(v[i1], v[i2]); });
2334template <
typename T>
2338 const size_type isize = i.size();
2340 for (size_type k = 0; k < isize; k++)
2346template <
typename T>
2350 const size_type isize = i.size();
2352 for (size_type k = 0; k < isize; k++)
2354 if (i[k] <
v.size() && i[k]>=0){
2377template <
typename T>
2381 const size_type
size =
v.size();
2382 const size_type absn = std::abs(
n);
2384 const auto msg = std::to_string(absn) +
" elements requested from Take but input contains only " +
2385 std::to_string(
size) +
" elements.";
2386 throw std::runtime_error(msg);
2390 for (size_type k = 0; k < absn; k++)
2391 r[k] =
v[
size - absn + k];
2393 for (size_type k = 0; k < absn; k++)
2418template <
typename T>
2422 const size_type
size =
v.size();
2423 const size_type absn = std::abs(
n);
2431 temp.resize(
n, default_val);
2435 const auto num_to_fill = absn -
size;
2443template <
typename T>
2447 std::sort(idxs.begin(), idxs.end());
2448 idxs.erase(std::unique(idxs.begin(), idxs.end()), idxs.end());
2451 if (
v.size() > idxs.size())
2452 r.reserve(
v.size() - idxs.size());
2454 auto discardIt = idxs.begin();
2456 for (sz_t i = 0u; i <
v.size(); ++i) {
2457 if (discardIt != idxs.end() && i == *discardIt)
2460 r.emplace_back(
v[i]);
2476template <
typename T>
2480 std::reverse(
r.begin(),
r.end());
2497template <
typename T>
2501 std::sort(
r.begin(),
r.end());
2522template <
typename T,
typename Compare>
2526 std::sort(
r.begin(),
r.end(), std::forward<Compare>(
c));
2546template <
typename T>
2550 std::stable_sort(
r.begin(),
r.end());
2582template <
typename T,
typename Compare>
2586 std::stable_sort(
r.begin(),
r.end(), std::forward<Compare>(
c));
2604 using size_type = std::size_t;
2606 r[0].resize(size1*size2);
2607 r[1].resize(size1*size2);
2609 for(size_type i=0; i<size1; i++) {
2610 for(size_type j=0; j<size2; j++) {
2633template <
typename T1,
typename T2>
2658template <
typename T>
2662 const size_type s =
v.size();
2664 throw std::runtime_error(
"Cannot make unique combinations of size " + std::to_string(
n) +
2665 " from vector of size " + std::to_string(s) +
".");
2669 for(size_type k=0; k<s; k++)
2672 const auto innersize = [=] {
2673 size_type inners = s -
n + 1;
2674 for (size_type
m = s -
n + 2;
m <= s; ++
m)
2677 size_type factn = 1;
2678 for (size_type i = 2; i <=
n; ++i)
2686 size_type inneridx = 0;
2687 for (size_type k = 0; k <
n; k++)
2692 bool run_through =
true;
2696 run_through =
false;
2704 for (
long j=i+1; j<(long)
n; j++)
2706 for (size_type k = 0; k <
n; k++)
2722template <
typename T>
2727 const auto size =
v.size();
2729 for(size_type i=0; i<
size; i++) {
2753template <
typename T>
2757 if (!v2_is_sorted) v2_sorted =
Sort(
v2);
2758 const auto v2_begin = v2_is_sorted ?
v2.begin() : v2_sorted.
begin();
2759 const auto v2_end = v2_is_sorted ?
v2.end() : v2_sorted.
end();
2761 const auto size =
v1.size();
2764 for(size_type i=0; i<
size; i++) {
2765 if (std::binary_search(v2_begin, v2_end,
v1[i])) {
2766 r.emplace_back(
v1[i]);
2787template <
typename T>
2791 const size_type
size =
c.size();
2794 for (size_type i=0; i<
size; i++) {
2795 r.emplace_back(
c[i] != 0 ?
v1[i] :
v2[i]);
2815template <
typename T>
2819 const size_type
size =
c.size();
2822 for (size_type i=0; i<
size; i++) {
2823 r.emplace_back(
c[i] != 0 ?
v1[i] :
v2);
2843template <
typename T>
2847 const size_type
size =
c.size();
2850 for (size_type i=0; i<
size; i++) {
2851 r.emplace_back(
c[i] != 0 ?
v1 :
v2[i]);
2869template <
typename T>
2873 const size_type
size =
c.size();
2876 for (size_type i=0; i<
size; i++) {
2877 r.emplace_back(
c[i] != 0 ?
v1 :
v2);
2892template <typename T0, typename T1, typename Common_t = typename std::common_type<T0, T1>::type>
2897 std::copy(
v0.begin(),
v0.end(), std::back_inserter(res));
2898 std::copy(
v1.begin(),
v1.end(), std::back_inserter(res));
2908template <
typename T0,
typename T1 = T0,
typename Common_t = std::common_type_t<T0, T1>>
2911 static_assert(std::is_floating_point<T0>::value && std::is_floating_point<T1>::value,
2912 "DeltaPhi must be called with floating point values.");
2913 auto r = std::fmod(
v2 -
v1, 2.0 *
c);
2929template <
typename T0,
typename T1 = T0,
typename Common_t =
typename std::common_type_t<T0, T1>>
2933 const size_type
size =
v1.size();
2935 for (size_type i = 0; i <
size; i++) {
2947template <
typename T0,
typename T1 = T0,
typename Common_t =
typename std::common_type_t<T0, T1>>
2951 const size_type
size =
v1.size();
2953 for (size_type i = 0; i <
size; i++) {
2965template <
typename T0,
typename T1 = T0,
typename Common_t =
typename std::common_type_t<T0, T1>>
2969 const size_type
size =
v2.size();
2971 for (size_type i = 0; i <
size; i++) {
2984template <
typename T0,
typename T1 = T0,
typename T2 = T0,
typename T3 = T0,
typename Common_t = std::common_type_t<T0, T1, T2, T3>>
2987 const auto dphi =
DeltaPhi(phi1, phi2,
c);
2988 return (eta1 - eta2) * (eta1 - eta2) + dphi * dphi;
2998template <
typename T0,
typename T1 = T0,
typename T2 = T0,
typename T3 = T0,
typename Common_t = std::common_type_t<T0, T1, T2, T3>>
3011template <
typename T0,
typename T1 = T0,
typename T2 = T0,
typename T3 = T0,
typename Common_t = std::common_type_t<T0, T1, T2, T3>>
3014 const auto dphi =
DeltaPhi(phi1, phi2,
c);
3015 return std::sqrt((eta1 - eta2) * (eta1 - eta2) + dphi * dphi);
3023template <
typename T0,
typename T1 = T0,
typename T2 = T0,
typename T3 = T0,
typename T4 = T0,
3024 typename T5 = T0,
typename Common_t = std::common_type_t<T0, T1>>
3027 const auto cx = y1 * z2 - y2 * z1;
3028 const auto cy = x1 * z2 - x2 * z1;
3029 const auto cz = x1 * y2 - x2 * y1;
3032 const auto c = std::sqrt(cx * cx + cy * cy + cz * cz);
3035 const auto d = x1 * x2 + y1 * y2 + z1 * z2;
3037 return std::atan2(
c,
d);
3045template <
typename T0,
typename T1 = T0,
typename T2 = T0,
typename T3 = T0,
typename T4 = T0,
3046 typename T5 = T0,
typename T6 = T0,
typename T7 = T0,
typename Common_t = std::common_type_t<T0, T1, T2, T3, T4, T5, T6, T7>>
3048 const T0& x1,
const T1& y1,
const T2& z1,
const T3& mass1,
3049 const T4& x2,
const T5& y2,
const T6& z2,
const T7& mass2)
3053 const auto p1_sq = x1 * x1 + y1 * y1 + z1 * z1;
3054 const auto p2_sq = x2 * x2 + y2 * y2 + z2 * z2;
3056 if (p1_sq <= 0 && p2_sq <= 0)
3057 return (mass1 + mass2);
3059 auto mm = mass1 + std::sqrt(mass2*mass2 + p2_sq);
3060 auto m2 = mm*mm - p2_sq;
3062 return std::sqrt( m2 );
3064 return std::sqrt( -m2 );
3067 auto mm = mass2 + std::sqrt(mass1*mass1 + p1_sq);
3068 auto m2 = mm*mm - p1_sq;
3070 return std::sqrt( m2 );
3072 return std::sqrt( -m2 );
3075 const auto m1_sq = mass1 * mass1;
3076 const auto m2_sq = mass2 * mass2;
3078 const auto r1 = m1_sq / p1_sq;
3079 const auto r2 = m2_sq / p2_sq;
3080 const auto x = r1 + r2 + r1 * r2;
3081 const auto a =
Angle(x1, y1, z1, x2, y2, z2);
3082 const auto cos_a = std::cos(
a);
3085 y = (
x + std::sin(
a) * std::sin(
a)) / (std::sqrt(
x + 1) + cos_a);
3087 y = std::sqrt(
x + 1) - cos_a;
3090 const auto z = 2 * std::sqrt(p1_sq * p2_sq);
3093 return std::sqrt(m1_sq + m2_sq +
y * z);
3101template <
typename T0,
typename T1 = T0,
typename T2 = T0,
typename T3 = T0,
typename T4 = T0,
3102 typename T5 = T0,
typename T6 = T0,
typename T7 = T0,
typename Common_t = std::common_type_t<T0, T1, T2, T3, T4, T5, T6, T7>>
3114 for (std::size_t i = 0u; i <
size; ++i) {
3127template <
typename T0,
typename T1 = T0,
typename T2 = T0,
typename T3 = T0,
typename T4 = T0,
3128 typename T5 = T0,
typename T6 = T0,
typename T7 = T0,
typename Common_t = std::common_type_t<T0, T1, T2, T3, T4, T5, T6, T7>>
3140 for (std::size_t i = 0u; i <
size; ++i) {
3142 const auto x1 = pt1[i] * std::cos(phi1[i]);
3143 const auto y1 = pt1[i] * std::sin(phi1[i]);
3144 const auto z1 = pt1[i] * std::sinh(eta1[i]);
3146 const auto x2 = pt2[i] * std::cos(phi2[i]);
3147 const auto y2 = pt2[i] * std::sin(phi2[i]);
3148 const auto z2 = pt2[i] * std::sinh(eta2[i]);
3163template <
typename T0,
typename T1 = T0,
typename T2 = T0,
typename T3 = T0,
typename Common_t = std::common_type_t<T0, T1, T2, T3>>
3166 const std::size_t
size =
pt.size();
3170 Common_t x_sum = 0.;
3171 Common_t y_sum = 0.;
3172 Common_t z_sum = 0.;
3173 Common_t e_sum = 0.;
3175 for (std::size_t i = 0u; i <
size; ++ i) {
3177 const auto x =
pt[i] * std::cos(phi[i]);
3179 const auto y =
pt[i] * std::sin(phi[i]);
3181 const auto z =
pt[i] * std::sinh(eta[i]);
3183 const auto e = std::sqrt(
x *
x +
y *
y + z * z + mass[i] * mass[i]);
3188 return std::sqrt(e_sum * e_sum - x_sum * x_sum - y_sum * y_sum - z_sum * z_sum);
3209template <
typename T,
typename... Args_t>
3215 for (
auto i = 0UL; i <
size; ++i) {
3216 ret.emplace_back(args[i]...);
3229template <
typename T>
3232 const auto size =
v.size();
3235 for (
auto i = 0UL; i <
size; ++i) {
3236 ret.emplace_back(i);
3296template <
typename T =
double,
typename Ret_t = std::conditional_t<std::is_
floating_po
int_v<T>, T,
double>>
3299 if (!
n || (
n > std::numeric_limits<long long>::max()))
3304 long double step = std::is_floating_point_v<Ret_t> ?
3305 (end -
start) /
static_cast<long double>(
n - endpoint) :
3306 (end >=
start ?
static_cast<long double>(end -
start) / (
n - endpoint) : (
static_cast<long double>(end) -
start) / (
n - endpoint));
3309 temp[0] = std::is_floating_point_v<Ret_t> ?
static_cast<Ret_t
>(
start) : std::floor(
start);
3310 if constexpr (std::is_floating_point_v<Ret_t>)
3312 for (
unsigned long long i = 1; i <
n; i++)
3314 temp[i] =
static_cast<Ret_t
>(
start + i * step);
3319 for (
unsigned long long i = 1; i <
n; i++)
3382template <
typename T =
double,
typename Ret_t = std::conditional_t<std::is_
floating_po
int_v<T>, T,
double>>
3385 if (!
n || (
n > std::numeric_limits<long long>::max()))
3391 long double start_c =
start;
3392 long double end_c = end;
3393 long double base_c = base;
3395 long double step = (end_c - start_c) / (
n - endpoint);
3397 temp[0] = std::is_floating_point_v<Ret_t> ?
3398 static_cast<Ret_t
>(std::pow(base_c, start_c)) :
3399 std::floor(std::pow(base_c, start_c));
3401 if constexpr (std::is_floating_point_v<Ret_t>)
3403 for (
unsigned long long i = 1; i <
n; i++)
3405 auto exponent = start_c + i * step;
3406 temp[i] =
static_cast<Ret_t
>(std::pow(base_c, exponent));
3411 for (
unsigned long long i = 1; i <
n; i++)
3413 auto exponent = start_c + i * step;
3414 temp[i] = std::floor(std::pow(base_c, exponent));
3476template <
typename T =
double,
typename Ret_t = std::conditional_t<std::is_
floating_po
int_v<T>, T,
double>>
3479 unsigned long long n = std::ceil(( end >=
start ? (end -
start) :
static_cast<long double>(end)-
start)/
static_cast<long double>(step));
3481 if (!
n || (
n > std::numeric_limits<long long>::max()))
3488 long double start_c =
start;
3489 long double step_c = step;
3491 temp[0] = std::is_floating_point_v<Ret_t> ?
static_cast<Ret_t
>(
start) : std::floor(
start);
3492 if constexpr (std::is_floating_point_v<Ret_t>)
3494 for (
unsigned long long i = 1; i <
n; i++)
3496 temp[i] =
static_cast<Ret_t
>(start_c + i * step_c);
3501 for (
unsigned long long i = 1; i <
n; i++)
3503 temp[i] = std::floor(start_c + i * step_c);
3519 ret.reserve(length);
3520 for (
auto i = 0UL; i < length; ++i) {
3521 ret.emplace_back(i);
3531 ret.reserve(begin < end ? end - begin : 0u);
3532 for (
auto i = begin; i < end; ++i)
3553 throw std::runtime_error(
"Range: the stride must not be zero");
3556 float ret_cap = std::ceil(
static_cast<float>(end-begin) / stride);
3562 ret.reserve(
static_cast<size_t>(ret_cap));
3565 for (
auto i = begin; i < end; i+=stride)
3570 for (
auto i = begin; i > end; i+=stride)
3584 constexpr bool mustConvert = std::is_same<char, T>::value || std::is_same<signed char, T>::value ||
3585 std::is_same<unsigned char, T>::value || std::is_same<wchar_t, T>::value ||
3586 std::is_same<char16_t, T>::value || std::is_same<char32_t, T>::value;
3587 using Print_t =
typename std::conditional<mustConvert, long long int, T>::type;
3589 auto size =
v.size();
3591 for (std::size_t i = 0; i <
size - 1; ++i) {
3592 os << (Print_t)
v[i] <<
", ";
3594 os << (Print_t)
v[
size - 1];
3600#if (_VECOPS_USE_EXTERN_TEMPLATES)
3602#define RVEC_EXTERN_UNARY_OPERATOR(T, OP) \
3603 extern template RVec<T> operator OP<T>(const RVec<T> &);
3605#define RVEC_EXTERN_BINARY_OPERATOR(T, OP) \
3606 extern template auto operator OP<T, T>(const T &x, const RVec<T> &v) \
3607 -> RVec<decltype(x OP v[0])>; \
3608 extern template auto operator OP<T, T>(const RVec<T> &v, const T &y) \
3609 -> RVec<decltype(v[0] OP y)>; \
3610 extern template auto operator OP<T, T>(const RVec<T> &v0, const RVec<T> &v1)\
3611 -> RVec<decltype(v0[0] OP v1[0])>;
3613#define RVEC_EXTERN_ASSIGN_OPERATOR(T, OP) \
3614 extern template RVec<T> &operator OP<T, T>(RVec<T> &, const T &); \
3615 extern template RVec<T> &operator OP<T, T>(RVec<T> &, const RVec<T> &);
3617#define RVEC_EXTERN_LOGICAL_OPERATOR(T, OP) \
3618 extern template RVec<int> operator OP<T, T>(const RVec<T> &, const T &); \
3619 extern template RVec<int> operator OP<T, T>(const T &, const RVec<T> &); \
3620 extern template RVec<int> operator OP<T, T>(const RVec<T> &, const RVec<T> &);
3622#define RVEC_EXTERN_FLOAT_TEMPLATE(T) \
3623 extern template class RVec<T>; \
3624 RVEC_EXTERN_UNARY_OPERATOR(T, +) \
3625 RVEC_EXTERN_UNARY_OPERATOR(T, -) \
3626 RVEC_EXTERN_UNARY_OPERATOR(T, !) \
3627 RVEC_EXTERN_BINARY_OPERATOR(T, +) \
3628 RVEC_EXTERN_BINARY_OPERATOR(T, -) \
3629 RVEC_EXTERN_BINARY_OPERATOR(T, *) \
3630 RVEC_EXTERN_BINARY_OPERATOR(T, /) \
3631 RVEC_EXTERN_ASSIGN_OPERATOR(T, +=) \
3632 RVEC_EXTERN_ASSIGN_OPERATOR(T, -=) \
3633 RVEC_EXTERN_ASSIGN_OPERATOR(T, *=) \
3634 RVEC_EXTERN_ASSIGN_OPERATOR(T, /=) \
3635 RVEC_EXTERN_LOGICAL_OPERATOR(T, <) \
3636 RVEC_EXTERN_LOGICAL_OPERATOR(T, >) \
3637 RVEC_EXTERN_LOGICAL_OPERATOR(T, ==) \
3638 RVEC_EXTERN_LOGICAL_OPERATOR(T, !=) \
3639 RVEC_EXTERN_LOGICAL_OPERATOR(T, <=) \
3640 RVEC_EXTERN_LOGICAL_OPERATOR(T, >=) \
3641 RVEC_EXTERN_LOGICAL_OPERATOR(T, &&) \
3642 RVEC_EXTERN_LOGICAL_OPERATOR(T, ||)
3644#define RVEC_EXTERN_INTEGER_TEMPLATE(T) \
3645 extern template class RVec<T>; \
3646 RVEC_EXTERN_UNARY_OPERATOR(T, +) \
3647 RVEC_EXTERN_UNARY_OPERATOR(T, -) \
3648 RVEC_EXTERN_UNARY_OPERATOR(T, ~) \
3649 RVEC_EXTERN_UNARY_OPERATOR(T, !) \
3650 RVEC_EXTERN_BINARY_OPERATOR(T, +) \
3651 RVEC_EXTERN_BINARY_OPERATOR(T, -) \
3652 RVEC_EXTERN_BINARY_OPERATOR(T, *) \
3653 RVEC_EXTERN_BINARY_OPERATOR(T, /) \
3654 RVEC_EXTERN_BINARY_OPERATOR(T, %) \
3655 RVEC_EXTERN_BINARY_OPERATOR(T, &) \
3656 RVEC_EXTERN_BINARY_OPERATOR(T, |) \
3657 RVEC_EXTERN_BINARY_OPERATOR(T, ^) \
3658 RVEC_EXTERN_ASSIGN_OPERATOR(T, +=) \
3659 RVEC_EXTERN_ASSIGN_OPERATOR(T, -=) \
3660 RVEC_EXTERN_ASSIGN_OPERATOR(T, *=) \
3661 RVEC_EXTERN_ASSIGN_OPERATOR(T, /=) \
3662 RVEC_EXTERN_ASSIGN_OPERATOR(T, %=) \
3663 RVEC_EXTERN_ASSIGN_OPERATOR(T, &=) \
3664 RVEC_EXTERN_ASSIGN_OPERATOR(T, |=) \
3665 RVEC_EXTERN_ASSIGN_OPERATOR(T, ^=) \
3666 RVEC_EXTERN_ASSIGN_OPERATOR(T, >>=) \
3667 RVEC_EXTERN_ASSIGN_OPERATOR(T, <<=) \
3668 RVEC_EXTERN_LOGICAL_OPERATOR(T, <) \
3669 RVEC_EXTERN_LOGICAL_OPERATOR(T, >) \
3670 RVEC_EXTERN_LOGICAL_OPERATOR(T, ==) \
3671 RVEC_EXTERN_LOGICAL_OPERATOR(T, !=) \
3672 RVEC_EXTERN_LOGICAL_OPERATOR(T, <=) \
3673 RVEC_EXTERN_LOGICAL_OPERATOR(T, >=) \
3674 RVEC_EXTERN_LOGICAL_OPERATOR(T, &&) \
3675 RVEC_EXTERN_LOGICAL_OPERATOR(T, ||)
3677RVEC_EXTERN_INTEGER_TEMPLATE(
char)
3678RVEC_EXTERN_INTEGER_TEMPLATE(
short)
3679RVEC_EXTERN_INTEGER_TEMPLATE(
int)
3680RVEC_EXTERN_INTEGER_TEMPLATE(
long)
3683RVEC_EXTERN_INTEGER_TEMPLATE(
unsigned char)
3684RVEC_EXTERN_INTEGER_TEMPLATE(
unsigned short)
3685RVEC_EXTERN_INTEGER_TEMPLATE(
unsigned int)
3686RVEC_EXTERN_INTEGER_TEMPLATE(
unsigned long)
3689RVEC_EXTERN_FLOAT_TEMPLATE(
float)
3690RVEC_EXTERN_FLOAT_TEMPLATE(
double)
3692#undef RVEC_EXTERN_UNARY_OPERATOR
3693#undef RVEC_EXTERN_BINARY_OPERATOR
3694#undef RVEC_EXTERN_ASSIGN_OPERATOR
3695#undef RVEC_EXTERN_LOGICAL_OPERATOR
3696#undef RVEC_EXTERN_INTEGER_TEMPLATE
3697#undef RVEC_EXTERN_FLOAT_TEMPLATE
3699#define RVEC_EXTERN_UNARY_FUNCTION(T, NAME, FUNC) \
3700 extern template RVec<PromoteType<T>> NAME(const RVec<T> &);
3702#define RVEC_EXTERN_STD_UNARY_FUNCTION(T, F) RVEC_EXTERN_UNARY_FUNCTION(T, F, std::F)
3704#define RVEC_EXTERN_BINARY_FUNCTION(T0, T1, NAME, FUNC) \
3705 extern template RVec<PromoteTypes<T0, T1>> NAME(const RVec<T0> &, const T1 &); \
3706 extern template RVec<PromoteTypes<T0, T1>> NAME(const T0 &, const RVec<T1> &); \
3707 extern template RVec<PromoteTypes<T0, T1>> NAME(const RVec<T0> &, const RVec<T1> &);
3709#define RVEC_EXTERN_STD_BINARY_FUNCTION(T, F) RVEC_EXTERN_BINARY_FUNCTION(T, T, F, std::F)
3711#define RVEC_EXTERN_STD_FUNCTIONS(T) \
3712 RVEC_EXTERN_STD_UNARY_FUNCTION(T, abs) \
3713 RVEC_EXTERN_STD_BINARY_FUNCTION(T, fdim) \
3714 RVEC_EXTERN_STD_BINARY_FUNCTION(T, fmod) \
3715 RVEC_EXTERN_STD_BINARY_FUNCTION(T, remainder) \
3716 RVEC_EXTERN_STD_UNARY_FUNCTION(T, exp) \
3717 RVEC_EXTERN_STD_UNARY_FUNCTION(T, exp2) \
3718 RVEC_EXTERN_STD_UNARY_FUNCTION(T, expm1) \
3719 RVEC_EXTERN_STD_UNARY_FUNCTION(T, log) \
3720 RVEC_EXTERN_STD_UNARY_FUNCTION(T, log10) \
3721 RVEC_EXTERN_STD_UNARY_FUNCTION(T, log2) \
3722 RVEC_EXTERN_STD_UNARY_FUNCTION(T, log1p) \
3723 RVEC_EXTERN_STD_BINARY_FUNCTION(T, pow) \
3724 RVEC_EXTERN_STD_UNARY_FUNCTION(T, sqrt) \
3725 RVEC_EXTERN_STD_UNARY_FUNCTION(T, cbrt) \
3726 RVEC_EXTERN_STD_BINARY_FUNCTION(T, hypot) \
3727 RVEC_EXTERN_STD_UNARY_FUNCTION(T, sin) \
3728 RVEC_EXTERN_STD_UNARY_FUNCTION(T, cos) \
3729 RVEC_EXTERN_STD_UNARY_FUNCTION(T, tan) \
3730 RVEC_EXTERN_STD_UNARY_FUNCTION(T, asin) \
3731 RVEC_EXTERN_STD_UNARY_FUNCTION(T, acos) \
3732 RVEC_EXTERN_STD_UNARY_FUNCTION(T, atan) \
3733 RVEC_EXTERN_STD_BINARY_FUNCTION(T, atan2) \
3734 RVEC_EXTERN_STD_UNARY_FUNCTION(T, sinh) \
3735 RVEC_EXTERN_STD_UNARY_FUNCTION(T, cosh) \
3736 RVEC_EXTERN_STD_UNARY_FUNCTION(T, tanh) \
3737 RVEC_EXTERN_STD_UNARY_FUNCTION(T, asinh) \
3738 RVEC_EXTERN_STD_UNARY_FUNCTION(T, acosh) \
3739 RVEC_EXTERN_STD_UNARY_FUNCTION(T, atanh) \
3740 RVEC_EXTERN_STD_UNARY_FUNCTION(T, floor) \
3741 RVEC_EXTERN_STD_UNARY_FUNCTION(T, ceil) \
3742 RVEC_EXTERN_STD_UNARY_FUNCTION(T, trunc) \
3743 RVEC_EXTERN_STD_UNARY_FUNCTION(T, round) \
3744 RVEC_EXTERN_STD_UNARY_FUNCTION(T, erf) \
3745 RVEC_EXTERN_STD_UNARY_FUNCTION(T, erfc) \
3746 RVEC_EXTERN_STD_UNARY_FUNCTION(T, lgamma) \
3747 RVEC_EXTERN_STD_UNARY_FUNCTION(T, tgamma) \
3749RVEC_EXTERN_STD_FUNCTIONS(
float)
3750RVEC_EXTERN_STD_FUNCTIONS(
double)
3751#undef RVEC_EXTERN_STD_UNARY_FUNCTION
3752#undef RVEC_EXTERN_STD_BINARY_FUNCTION
3753#undef RVEC_EXTERN_STD_UNARY_FUNCTIONS
3757#define RVEC_EXTERN_VDT_UNARY_FUNCTION(T, F) RVEC_EXTERN_UNARY_FUNCTION(T, F, vdt::F)
3759RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_expf)
3760RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_logf)
3761RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_sinf)
3762RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_cosf)
3763RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_tanf)
3764RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_asinf)
3765RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_acosf)
3766RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_atanf)
3768RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_exp)
3769RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_log)
3770RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_sin)
3771RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_cos)
3772RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_tan)
3773RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_asin)
3774RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_acos)
3775RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_atan)
#define R__unlikely(expr)
#define R__RVEC_NODISCARD
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
#define R__CLING_PTRCHECK(ONOFF)
static Double_t Product(const Double_t *x, const Float_t *y)
Product.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Double_t Dot(const TGLVector3 &v1, const TGLVector3 &v2)
Int_t Compare(const void *item1, const void *item2)
Binding & operator=(OUT(*fun)(void))
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, const T &Elt)
typename SuperClass::iterator iterator
typename SuperClass::size_type size_type
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void assign(std::initializer_list< T > IL)
typename SuperClass::const_iterator const_iterator
void resize(size_type N, const T &NV)
void reserve(size_type N)
iterator insert(iterator I, ItTy From, ItTy To)
reference emplace_back(ArgTypes &&...Args)
Internal::VecOps::SmallVectorTemplateBase< T > SuperClass
void assign(in_iter in_start, in_iter in_end)
iterator insert(iterator I, const T &Elt)
iterator insert(iterator I, size_type NumToInsert, const T &Elt)
RVecImpl & operator=(const RVecImpl &RHS)
iterator erase(const_iterator CS, const_iterator CE)
typename SuperClass::reference reference
void append(size_type NumInputs, const T &Elt)
Append NumInputs copies of Elt to the end.
iterator erase(const_iterator CI)
void pop_back_n(size_type NumItems)
RVecImpl(const RVecImpl &)=delete
void append(std::initializer_list< T > IL)
void insert(iterator I, std::initializer_list< T > IL)
This is all the stuff common to all SmallVectors.
SmallVectorBase(void *FirstEl, size_t TotalCapacity)
static constexpr size_t SizeTypeMax()
The maximum value of the Size_T used.
Size_T fCapacity
Always >= -1. fCapacity == -1 indicates the RVec is in "memory adoption" mode.
void grow_pod(void *FirstEl, size_t MinSize, size_t TSize)
This is an implementation of the grow() method which only works on POD-like data types and is out of ...
bool Owns() const
If false, the RVec is in "memory adoption" mode, i.e. it is acting as a view on a memory buffer it do...
size_t capacity() const noexcept
void set_size(size_t N)
Set the array size to N, which the current array must have enough capacity for.
typename SuperClass::iterator iterator
void grow(size_t MinSize=0)
Double the size of the allocated memory, guaranteeing space for at least one more element or MinSize ...
typename SuperClass::size_type size_type
typename SuperClass::reference reference
void push_back(const T &Elt)
static void uninitialized_move(It1 I, It1 E, It2 Dest)
Move the range [I, E) onto the uninitialized memory starting with "Dest", constructing elements into ...
SmallVectorTemplateCommon< T > SuperClass
SmallVectorTemplateBase(size_t Size)
typename SuperClass::const_iterator const_iterator
static void uninitialized_copy(T1 *I, T1 *E, T2 *Dest, typename std::enable_if< std::is_same< typename std::remove_const< T1 >::type, T2 >::value >::type *=nullptr)
Copy the range [I, E) onto the uninitialized memory starting with "Dest", constructing elements into ...
static void destroy_range(T *, T *)
static void uninitialized_copy(It1 I, It1 E, It2 Dest)
Copy the range [I, E) onto the uninitialized memory starting with "Dest", constructing elements into ...
SmallVectorTemplateBase<TriviallyCopyable = false> - This is where we put method implementations that...
void push_back(const T &Elt)
void grow(size_t MinSize=0)
Grow the allocated memory (without initializing new elements), doubling the size of the allocated mem...
static void uninitialized_move(It1 I, It1 E, It2 Dest)
Move the range [I, E) into the uninitialized memory starting with "Dest", constructing elements as ne...
SmallVectorTemplateBase(size_t Size)
static void destroy_range(T *S, T *E)
static void uninitialized_copy(It1 I, It1 E, It2 Dest)
Copy the range [I, E) onto the uninitialized memory starting with "Dest", constructing elements as ne...
This is the part of SmallVectorTemplateBase which does not depend on whether the type T is a POD.
size_type max_size() const noexcept
const_iterator cbegin() const noexcept
void grow_pod(size_t MinSize, size_t TSize)
ptrdiff_t difference_type
reverse_iterator rbegin() noexcept
const_iterator cend() const noexcept
const_reference back() const
void resetToSmall()
Put this vector in a state of being small.
iterator begin() noexcept
std::reverse_iterator< iterator > reverse_iterator
const T & const_reference
bool isSmall() const
Return true if this is a smallvector which has not had dynamic memory allocated for it.
const_reverse_iterator crend() const noexcept
const_iterator end() const noexcept
SmallVectorTemplateCommon(size_t Size)
const_reverse_iterator crbegin() const noexcept
pointer data() noexcept
Return a pointer to the vector's buffer, even if empty().
size_t capacity_in_bytes() const
reverse_iterator rend() noexcept
const_reverse_iterator rbegin() const noexcept
const_reference front() const
size_type size_in_bytes() const
std::reverse_iterator< const_iterator > const_reverse_iterator
size_t capacity() const noexcept
const_iterator begin() const noexcept
const_pointer data() const noexcept
Return a pointer to the vector's buffer, even if empty().
void * getFirstEl() const
Find the address of the first element.
const_reverse_iterator rend() const noexcept
A "std::vector"-like collection of values implementing handy operation to analyse them.
RVecN< bool, Internal::VecOps::RVecInlineStorageSize< bool >::value > SuperClass
typename SuperClass::size_type size_type
typename SuperClass::value_type value_type
RVecN(Detail::VecOps::RVecImpl< T > &&RHS)
reference operator[](size_type idx)
typename Internal::VecOps::SmallVectorTemplateCommon< T >::const_reference const_reference
RVecN operator[](const RVecN< V, M > &conds) const
RVecN(std::initializer_list< T > IL)
const_reference at(size_type pos) const
RVecN & operator=(Detail::VecOps::RVecImpl< T > &&RHS)
RVecN & operator=(RVecN &&RHS)
typename Internal::VecOps::SmallVectorTemplateCommon< T >::size_type size_type
value_type at(size_type pos, value_type fallback) const
No exception thrown. The user specifies the desired value in case the RVecN is shorter than pos.
RVecN & operator=(std::initializer_list< T > IL)
RVecN & operator=(const RVecN &RHS)
RVecN(const std::vector< T > &RHS)
RVecN(size_t Size, const T &Value)
reference at(size_type pos)
value_type at(size_type pos, value_type fallback)
No exception thrown. The user specifies the desired value in case the RVecN is shorter than pos.
typename Internal::VecOps::SmallVectorTemplateCommon< T >::reference reference
typename Internal::VecOps::SmallVectorTemplateCommon< T >::value_type value_type
const_reference operator[](size_type idx) const
A "std::vector"-like collection of values implementing handy operation to analyse them.
RVecN< T, Internal::VecOps::RVecInlineStorageSize< T >::value > SuperClass
RVec(RVecN< T, N > &&RHS)
typename SuperClass::reference reference
RVec(const RVecN< T, N > &RHS)
RVec(size_t Size, const T &Value)
RVec & operator=(RVec &&RHS)
RVec operator[](const RVec< V > &conds) const
RVec(std::initializer_list< T > IL)
typename SuperClass::const_reference const_reference
RVec(const std::vector< T > &RHS)
typename SuperClass::size_type size_type
RVec(Detail::VecOps::RVecImpl< T > &&RHS)
typename SuperClass::value_type value_type
RVec & operator=(const RVec &RHS)
Type
enumeration specifying the integration types.
T Max(const RVec< T > &v)
Get the greatest element of an RVec.
RVec< T > Reverse(const RVec< T > &v)
Return copy of reversed vector.
RVec< T > Intersect(const RVec< T > &v1, const RVec< T > &v2, bool v2_is_sorted=false)
Return the intersection of elements of two RVecs.
auto All(const RVec< T > &v) -> decltype(v[0]==false)
Return true if all of the elements equate to true, return false otherwise.
RVec< Common_t > DeltaR(const RVec< T0 > &eta1, const RVec< T1 > &eta2, const RVec< T2 > &phi1, const RVec< T3 > &phi2, const Common_t c=M_PI)
Return the distance on the - plane ( ) from the collections eta1, eta2, phi1 and phi2.
RVec< PromoteType< T > > asinh(const RVec< T > &v)
RVec< PromoteType< T > > expm1(const RVec< T > &v)
RVec< PromoteType< T > > lgamma(const RVec< T > &v)
RVec< typename RVec< T >::size_type > Nonzero(const RVec< T > &v)
Return the indices of the elements which are not zero.
RVec< PromoteTypes< T0, T1 > > remainder(const T0 &x, const RVec< T1 > &v)
#define RVEC_UNARY_OPERATOR(OP)
RVec< Common_t > DeltaR2(const RVec< T0 > &eta1, const RVec< T1 > &eta2, const RVec< T2 > &phi1, const RVec< T3 > &phi2, const Common_t c=M_PI)
Return the square of the distance on the - plane ( ) from the collections eta1, eta2,...
RVec< PromoteType< T > > cosh(const RVec< T > &v)
RVec< PromoteType< T > > abs(const RVec< T > &v)
#define RVEC_ASSIGNMENT_OPERATOR(OP)
RVec< PromoteType< T > > round(const RVec< T > &v)
RVec< T > Sort(const RVec< T > &v)
Return copy of RVec with elements sorted in ascending order.
RVec< typename RVec< T >::size_type > StableArgsort(const RVec< T > &v)
Return an RVec of indices that sort the input RVec while keeping the order of equal elements.
RVec< PromoteType< T > > tgamma(const RVec< T > &v)
RVec< PromoteType< T > > log2(const RVec< T > &v)
Common_t DeltaPhi(T0 v1, T1 v2, const Common_t c=M_PI)
Return the angle difference of two scalars.
RVec< Common_t > Concatenate(const RVec< T0 > &v0, const RVec< T1 > &v1)
Return the concatenation of two RVecs.
RVec< PromoteType< T > > tan(const RVec< T > &v)
RVec< PromoteType< T > > erf(const RVec< T > &v)
RVec< PromoteType< T > > cos(const RVec< T > &v)
RVec< PromoteType< T > > floor(const RVec< T > &v)
RVec< PromoteTypes< T0, T1 > > pow(const T0 &x, const RVec< T1 > &v)
RVec< PromoteType< T > > atanh(const RVec< T > &v)
RVec< PromoteType< T > > acosh(const RVec< T > &v)
Common_t InvariantMasses_PxPyPzM(const T0 &x1, const T1 &y1, const T2 &z1, const T3 &mass1, const T4 &x2, const T5 &y2, const T6 &z2, const T7 &mass2)
Return the invariant mass of two particles given x coordinate (px), y coordinate (py),...
RVec< PromoteType< T > > ceil(const RVec< T > &v)
RVec< PromoteType< T > > cbrt(const RVec< T > &v)
T Sum(const RVec< T > &v, const T zero=T(0))
Sum elements of an RVec.
double Mean(const RVec< T > &v)
Get the mean of the elements of an RVec.
RVec< Common_t > InvariantMasses(const RVec< T0 > &pt1, const RVec< T1 > &eta1, const RVec< T2 > &phi1, const RVec< T3 > &mass1, const RVec< T4 > &pt2, const RVec< T5 > &eta2, const RVec< T6 > &phi2, const RVec< T7 > &mass2)
Return the invariant mass of two particles given the collections of the quantities transverse momentu...
RVec< T > Take(const RVec< T > &v, const RVec< typename RVec< T >::size_type > &i)
Return elements of a vector at given indices.
RVec< PromoteType< T > > asin(const RVec< T > &v)
void swap(RVec< T > &lhs, RVec< T > &rhs)
RVec< PromoteTypes< T0, T1 > > hypot(const T0 &x, const RVec< T1 > &v)
RVec< PromoteType< T > > log(const RVec< T > &v)
RVec< T > Construct(const RVec< Args_t > &... args)
Build an RVec of objects starting from RVecs of input to their constructors.
RVec< PromoteTypes< T0, T1 > > atan2(const T0 &x, const RVec< T1 > &v)
RVec< PromoteType< T > > trunc(const RVec< T > &v)
RVec< PromoteType< T > > llround(const RVec< T > &v)
RVec< PromoteTypes< T0, T1 > > fdim(const T0 &x, const RVec< T1 > &v)
#define RVEC_STD_BINARY_FUNCTION(F)
RVec< PromoteType< T > > lround(const RVec< T > &v)
#define RVEC_BINARY_OPERATOR(OP)
RVec< T > Drop(const RVec< T > &v, RVec< typename RVec< T >::size_type > idxs)
Return a copy of the container without the elements at the specified indices.
Common_t InvariantMass(const RVec< T0 > &pt, const RVec< T1 > &eta, const RVec< T2 > &phi, const RVec< T3 > &mass)
Return the invariant mass of multiple particles given the collections of the quantities transverse mo...
Common_t Angle(T0 x1, T1 y1, T2 z1, T3 x2, T4 y2, T5 z2)
Return the angle between two three-vectors given the quantities x coordinate (x), y coordinate (y),...
RVec< Ret_t > Logspace(T start, T end, unsigned long long n=128, const bool endpoint=true, T base=10.0)
Produce RVec with n log-spaced entries from base^{start} to base^{end}.
T Min(const RVec< T > &v)
Get the smallest element of an RVec.
size_t CapacityInBytes(const RVecN< T, N > &X)
#define RVEC_LOGICAL_OPERATOR(OP)
RVec< PromoteType< T > > sinh(const RVec< T > &v)
RVec< PromoteType< T > > sqrt(const RVec< T > &v)
RVec< PromoteType< T > > erfc(const RVec< T > &v)
RVec< RVec< std::size_t > > Combinations(const std::size_t size1, const std::size_t size2)
Return the indices that represent all combinations of the elements of two RVecs.
#define RVEC_STD_UNARY_FUNCTION(F)
RVec< PromoteType< T > > log10(const RVec< T > &v)
RVec< typename RVec< T >::size_type > Enumerate(const RVec< T > &v)
For any Rvec v produce another RVec with entries starting from 0, and incrementing by 1 until a N = v...
RVec< PromoteTypes< T0, T1 > > fmod(const T0 &x, const RVec< T1 > &v)
auto Map(Args &&... args)
Create new collection applying a callable to the elements of the input collection.
RVec< PromoteType< T > > exp(const RVec< T > &v)
RVec< T > Where(const RVec< int > &c, const RVec< T > &v1, const RVec< T > &v2)
Return the elements of v1 if the condition c is true and v2 if the condition c is false.
double StdDev(const RVec< T > &v)
Get the standard deviation of the elements of an RVec.
auto Any(const RVec< T > &v) -> decltype(v[0]==true)
Return true if any of the elements equates to true, return false otherwise.
RVec< Ret_t > Linspace(T start, T end, unsigned long long n=128, const bool endpoint=true)
Produce RVec with N evenly-spaced entries from start to end.
RVec< PromoteType< T > > tanh(const RVec< T > &v)
RVec< PromoteType< T > > acos(const RVec< T > &v)
RVec< PromoteType< T > > log1p(const RVec< T > &v)
RVec< Ret_t > Arange(T start, T end, T step)
Produce RVec with entries in the range [start, end) in increments of step.
RVec< typename RVec< T >::size_type > Argsort(const RVec< T > &v)
Return an RVec of indices that sort the input RVec.
std::size_t ArgMin(const RVec< T > &v)
Get the index of the smallest element of an RVec In case of multiple occurrences of the minimum value...
RVec< PromoteType< T > > atan(const RVec< T > &v)
RVec< T > StableSort(const RVec< T > &v)
Return copy of RVec with elements sorted in ascending order while keeping the order of equal elements...
RVec< PromoteType< T > > sin(const RVec< T > &v)
double Var(const RVec< T > &v)
Get the variance of the elements of an RVec.
RVec< PromoteType< T > > exp2(const RVec< T > &v)
RVec< T > Filter(const RVec< T > &v, F &&f)
Create a new collection with the elements passing the filter expressed by the predicate.
std::size_t ArgMax(const RVec< T > &v)
Get the index of the greatest element of an RVec In case of multiple occurrences of the maximum value...
bool IsSmall(const ROOT::VecOps::RVec< T > &v)
bool IsAdopting(const ROOT::VecOps::RVec< T > &v)
Special implementation of ROOT::RRangeCast for TCollection, including a check that the cast target ty...
auto MapImpl(F &&f, RVecs &&... vs) -> RVec< decltype(f(vs[0]...))>
void ResetView(RVec< T > &v, T *addr, std::size_t sz)
An unsafe function to reset the buffer for which this RVec is acting as a view.
ROOT::VecOps::RVec< T > RVec
uint64_t NextPowerOf2(uint64_t A)
Return the next power of two (in 64-bits) that is strictly greater than A.
constexpr bool All(const bool *vals, std::size_t size)
std::size_t GetVectorsSize(const std::string &id, const RVec< T > &... vs)
void UninitializedValueConstruct(ForwardIt first, ForwardIt last)
auto MapFromTuple(Tuple_t &&t, std::index_sequence< Is... >) -> decltype(MapImpl(std::get< std::tuple_size< Tuple_t >::value - 1 >(t), std::get< Is >(t)...))
namespace associated R package for ROOT.
ROOT::VecOps::RVec< unsigned int > RVecU
ROOT::VecOps::RVec< long long int > RVecLL
ROOT::VecOps::RVec< float > RVecF
ROOT::VecOps::RVec< char > RVecC
ROOT::VecOps::RVec< long int > RVecL
ROOT::VecOps::RVec< unsigned long int > RVecUL
ROOT::VecOps::RVec< bool > RVecB
ROOT::VecOps::RVec< unsigned long long int > RVecULL
ROOT::VecOps::RVec< double > RVecD
ROOT::VecOps::RVec< int > RVecI
The size of the inline storage of an RVec.
static constexpr std::size_t cacheLineSize
static constexpr unsigned maxInlineByteSize
static constexpr unsigned value
static constexpr unsigned elementsPerCacheLine
Used to figure out the offset of the first element of an RVec.
char Base[sizeof(SmallVectorBase)]
Storage for the SmallVector elements.
char InlineElts[N *sizeof(T)]