43 template <
class _Type,
class _Alloc>
54 template <
class _Type,
class _Alloc>
58 auto it =
std::find(vec.begin(), vec.end(), item);
59 return it != vec.end();
63 template <
class _Type,
class _Alloc>
67 auto it =
std::find(vec.begin(), vec.end(),item);
68 return it != vec.end();
72 template <
class _Type,
class _Alloc,
class InputIt>
76 vec.reserve (vec.size() + std::distance(first, last));
77 for (
auto it=first; it!=last; ++it)
83 template <
class _Type,
class _Alloc,
class InputIt>
89 std::function<
CepsBool(
const _Type&)> func
92 vec.reserve (vec.size() + std::distance(first, last));
93 for (
auto it=first; it!=last; ++it)
103 template <
class _Type,
class _Alloc>
107 vec.push_back(value);
112 template <
class _Type,
class _Alloc,
class InputIt>
116 vec.reserve (vec.size () + std::distance (first, last));
117 for (
auto it = first; it != last; ++it)
121 vec.push_back (item);
127 template <
class _Type,
class _Alloc>
133 vec.push_back(value);
138 template <
class _Type,
class _Alloc>
144 vec.push_back(value);
149 template <
class _Type,
class _Alloc>
153 vec.erase(std::remove(vec.begin(),vec.end(),value),vec.end());
158 template <
class _Type,
class _Alloc,
class InputIt>
162 for (InputIt it=first; it!=last; ++it)
171 template <
class _Type,
class _Alloc>
175 return std::find(vec.begin(),vec.end(),value);
179 template <
class _Type,
class _Alloc>
183 return std::find(vec.begin(),vec.end(),value);
187 template <
class _Type,
class _Alloc>
188 std::pair<CepsBool, CepsUInt>
191 auto it =
find (vec, value);
192 if (it == vec.end ())
194 return {
true, std::distance (vec.begin (), it)};
198 template <
class _Type,
class _Alloc>
202 auto it =
find(vec, value);
205 return std::distance(vec.begin(), it);
209 template <
class _Type,
class _Alloc>
213 std::function<
CepsBool(
const _Type& x)> predicate
216 return std::count_if(vec.begin(),vec.end(),predicate);
221 template <
class _Type,
class _Alloc>
225 std::function<
CepsBool(_Type* x)> predicate
228 return std::count_if(vec.begin(),vec.end(),predicate);
232 template <
class _Type,
class _Alloc,
typename _Compare>
236 std::sort(vec.begin(),vec.end(),compare);
241 template <
class _Type,
class _Alloc>
245 return sort(vec,std::less<_Type>());
252 template <
class _Type,
class _Alloc,
typename _Compare>
257 std::iota(p.begin(),p.end(),0);
259 return compare (vec[i],vec[j]);
268 template <
class _Type,
class _Alloc>
276 template <
class _Type,
class _Alloc>
291 std::swap(vec[prev_j], vec[j]);
301 template <
class _Type,
class _Alloc>
309 using eq_t = std::equal_to<_Type>;
314 if (eq_t {}(origin[i], target[j]))
320 "target union with origin is not target. Index of " << p[j] <<
" is missing into target vec"
327 template <
class _Type,
class _Alloc>
331 std::rotate(vec.rbegin(),vec.rbegin()+n,vec.rend());
336 template <
class _Type,
class _Alloc>
340 std::rotate(vec.begin(),vec.begin()+n,vec.end());
354 template <
class _Type,
class _Alloc>
361 _Type x_min = vec[0];
374 template <
class _Type,
class _Alloc,
typename _Res>
381 _Type x_min = vec[0];
382 _Res f_min = func(x_min);
400 template <
class _Type,
class _Alloc>
407 _Type x_max = vec[0];
420 template <
class _Type,
class _Alloc,
typename _Res>
427 _Type x_max = vec[0];
428 _Res f_max = func(x_max);
446 template <
class _Type,
class _Alloc>
454 template <
class _Type,
class _Alloc>
462 template <
class _Type,
class _Alloc>
470 template <
class _Type,
class _Alloc>
485 template <
class _Type,
class _Alloc>
490 vecOut.resize(N+1, _Type(0x0));
492 vecOut[i] = vecOut[i-1] + vec[i-1];
501 template <
class _Type,
class _Alloc>
520 template <
typename _Input1,
typename _Input2>
529 CepsSize n1 = std::distance(first1, last1);
530 CepsSize n2 = std::distance(first2, last2);
534 indices1.reserve(n1);
535 indices2.reserve(n2);
537 while (first1 != last1 && first2 != last2)
540 else if (*first2<*first1)
544 indices1.push_back(n1-std::distance(first1,last1));
545 indices2.push_back(n2-std::distance(first2,last2));
555 template <
class _Key,
class _Value>
561 _Value defaultValue = _Value ())
577 vals2.resize (keys2.size(), _Value(defaultValue));
581 vals2[perm2[idx2[i]]] = vals1[perm1[idx1[i]]];
590 template <
typename _Type>
597 vec.erase(vec.begin());
603 template <
class _Type>
612 if (rest !=0 and eqDistrib)
615 " is not divisible into groups of size " +
616 std::to_string(s) +
". The last one mays be incomplete.");
627 for (
CepsUInt j = 0; j < s and i < n; ++j, ++i)
628 subVec.push_back(vec[i]);
629 vecs.push_back(subVec);
636 template <
class _Type,
class _Res>
641 for (
const _Type &v : vec)
649 template <
class _Type1,
class _Alloc1,
class _Type2,
class _Alloc2>
653 const size_t& n = vec .size();
654 const size_t& m = other.size();
655 CEPS_ABORT_IF(n!=m,
"You are trying to sum two vectors with different sizes !");
668 class _ResultType = decltype (std::declval<_Type1> () + std::declval<_Type2> ())>
672 using ResultType = decltype (std::declval<_Type1> () + std::declval<_Type2> ());
674 const size_t &n = a.size ();
675 const size_t &m = b.size ();
676 CEPS_ABORT_IF (n != m,
"you are trying to sum two vectors with different sizes !");
686 template <
class _Type1,
class _Alloc1,
class _Type2,
class _Alloc2>
690 const size_t &n = vec.size ();
691 const size_t &m = other.size ();
692 CEPS_ABORT_IF (n != m,
"you are trying to substract two vectors with different sizes !");
705 class _ResultType = decltype (std::declval<_Type1> () - std::declval<_Type2> ())>
709 const size_t &n = a.size ();
710 const size_t &m = b.size ();
711 CEPS_ABORT_IF (n != m,
"you are trying to substract two vectors with different sizes !");
721 template <
class _Type1,
class _Alloc1,
class _Type2,
class _Alloc2>
725 const size_t &n = vec.size ();
726 const size_t &m = other.size ();
727 CEPS_ABORT_IF (n != m,
"you are trying to multiply two vectors with different sizes !");
740 class _ResultType = decltype (std::declval<_Type1> () * std::declval<_Type2> ())>
744 const size_t &n = a.size ();
745 const size_t &m = b.size ();
746 CEPS_ABORT_IF (n != m,
"you are trying to multiply two vectors with different sizes !");
756 template <
class _Type1,
class _Alloc1,
class _Type2,
class _Alloc2>
760 const size_t &n = vec.size ();
761 const size_t &m = other.size ();
762 CEPS_ABORT_IF (n != m,
"you are trying to divide two vectors with different sizes !");
775 class _ResultType = decltype (std::declval<_Type1> () / std::declval<_Type2> ())>
779 const size_t &n = a.size ();
780 const size_t &m = b.size ();
781 CEPS_ABORT_IF (n != m,
"you are trying to substract two vectors with different sizes !");
791 template <
class _Type,
class _Alloc>
796 for (
const _Type &item : v)
798 os <<
"]" << std::flush;
803 template <
class _Type,
class _Compare>
808 for (
const _Type &item : v)
810 os <<
"]" << std::flush;
#define CEPS_ABORT(message)
Stops the execution with a message. If testing is enabled, only throws a runtime_error.
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
std::vector< _Type, _Alloc > CepsVector
C++ vector.
size_t CepsSize
Size unsigned.
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
int32_t CepsInt
Need 32 bit integer.
CepsVector< _ResultType, _Alloc1 > operator*(const CepsVector< _Type1, _Alloc1 > &a, const CepsVector< _Type2, _Alloc2 > &b)
Term by term multiplication of 2 vectors.
CepsVector< _Type1, _Alloc1 > & operator*=(CepsVector< _Type1, _Alloc1 > &vec, const CepsVector< _Type2, _Alloc2 > &other)
Term by term multiplication of 2 vectors.
CepsVector< _Type1, _Alloc1 > & operator/=(CepsVector< _Type1, _Alloc1 > &vec, const CepsVector< _Type2, _Alloc2 > &other)
Term by term division of 2 vectors.
CepsVector< _ResultType, _Alloc1 > operator+(const CepsVector< _Type1, _Alloc1 > &a, const CepsVector< _Type2, _Alloc2 > &b)
Term by term sum of 2 vectors.
std::ostream & operator<<(std::ostream &os, const CepsVector< _Type, _Alloc > &v)
Output operator.
CepsVector< _ResultType, _Alloc1 > operator/(const CepsVector< _Type1, _Alloc1 > &a, const CepsVector< _Type2, _Alloc2 > &b)
Term by term division of 2 vectors.
CepsVector< _Type1, _Alloc1 > & operator+=(CepsVector< _Type1, _Alloc1 > &vec, const CepsVector< _Type2, _Alloc2 > &other)
Term by term sum and assign of 2 vectors.
CepsVector< _Type1, _Alloc1 > & operator-=(CepsVector< _Type1, _Alloc1 > &vec, const CepsVector< _Type2, _Alloc2 > &other)
Term by term difference of 2 vectors.
CepsVector< _ResultType, _Alloc1 > operator-(const CepsVector< _Type1, _Alloc1 > &a, const CepsVector< _Type2, _Alloc2 > &b)
Term by term difference of 2 vectors.
A namespace for all utility methods.
void insert(CepsVector< _Type, _Alloc > &vec, const _Type &value)
Conditional insertion of several elements.
CepsBool contains(const CepsVector< _Type, _Alloc > &vec, const _Type &item)
Tells if vectors contains a given item.
void eraseValue(CepsVector< _Type, _Alloc > &vec, const _Type &value)
Removes a value from a vector.
void applyPermutation(CepsVector< _Type, _Alloc > &vec, const CepsVector< CepsUInt > &p)
Apply a permutation to a vector.
void cumSum(const CepsVector< _Type, _Alloc > &vec, CepsVector< _Type, _Alloc > &vecOut)
Cumulated sum of values.
void pushBack(CepsVector< _Type, _Alloc > &vec, InputIt first, InputIt last)
Classic push back for several elements.
CepsUInt argmax(CepsVector< _Type, _Alloc > &vec)
Returns the position of the maximum in a whole vector.
CepsUInt argmin(CepsVector< _Type, _Alloc > &vec)
Returns the position of the minimum in a whole vector.
CepsVector< CepsUInt > getSortPermutation(const CepsVector< _Type, _Alloc > &vec, _Compare compare)
Get the permutation that would be applied to sort the whole vector with specific comparator.
void rightRotate(CepsVector< _Type, _Alloc > &vec, CepsUInt n=1)
Rotate n times the whole vector to the right.
CepsVector< _Type, _Alloc >::iterator find(CepsVector< _Type, _Alloc > &vec, const _Type &value)
Returns the result of find in the whole vector.
CepsInt argVector(const CepsVector< _Type, _Alloc > &vec, const _Type &value)
Get position of element in vector, -1 if not found.
void insertUnique(CepsVector< _Type, _Alloc > &vec, InputIt first, InputIt last)
Set behaviour: insert if elements does not exist in vector.
const _Type & max(const CepsVector< _Type, _Alloc > &vec)
Returns the maximum of the vector, const version.
void eraseValues(CepsVector< _Type, _Alloc > &vec, InputIt first, InputIt last)
Removes several values from a vector.
void sort(CepsVector< _Type, _Alloc > &vec)
Basic sorting of whole vector, increasing values.
const _Type & min(const CepsVector< _Type, _Alloc > &vec)
Returns the minimum of the vector, const version.
void destroy(CepsMap< _Key, _Tp, _Compare, _Alloc > &map, CepsBool deleteAll=true)
Deletes all elements of the map properly, even if created with new.
_Res applyAlong(const CepsVector< _Type > &vec, std::function< void(const _Type &, _Res &)> f, _Res init=_Res())
Applies f(elem,init) to each element of a vector.
void popFront(CepsVector< _Type > &vec)
Remove first element.
void insertIf(CepsVector< _Type, _Alloc > &vec, InputIt first, InputIt last, std::function< CepsBool(const _Type &)> func)
Conditional insertion of several elements.
CepsVector< _Type, _Alloc >::const_iterator find(const CepsVector< _Type, _Alloc > &vec, const _Type &value)
Returns the result of find in the whole vector.
std::pair< CepsBool, CepsUInt > indexOf(const CepsVector< _Type, _Alloc > &vec, const _Type &value)
Returns T/F and an index of the position of element in the vector.
void distribute(const CepsVector< _Type > &vec, CepsVector< CepsVector< _Type >> &vecs, CepsUInt s, CepsBool eqDistrib=true)
Divides the content of a vector into vectors of size s. Result is put in vecs. If eqDistrib is true,...
CepsUInt countWithPredicate(const CepsVector< _Type, _Alloc > &vec, std::function< CepsBool(const _Type &x)> predicate)
Count the number of elements of a vector that satisfy a condition.
void leftRotate(CepsVector< _Type, _Alloc > &vec, CepsUInt n=1)
Rotate n times the whole vector to the left.
void setIntersectionIndices(_Input1 first1, _Input1 last1, _Input2 first2, _Input2 last2, CepsVector< CepsUInt > &indices1, CepsVector< CepsUInt > &indices2)
Returns the indices in two containers of the elements that are present in both containers.
void sort(CepsVector< _Type, _Alloc > &vec, _Compare compare)
Sort whole vector with specified comparator.
CepsVector< CepsUInt > getIndicesInVector(const CepsVector< _Type, _Alloc > &origin, const CepsVector< _Type, _Alloc > &target)
Compute indices of target elements into the origin vector.
void destroyObject(_Type &)
Destroy[delete] any type.
void extractValues(const CepsVector< _Key > &keys1, const CepsVector< _Value > &vals1, const CepsVector< _Key > &keys2, CepsVector< _Value > &vals2, _Value defaultValue=_Value())
Get the values from vals1, indexed by keys1, following the keys given in keys2. Result put in vals2....