CEPS  24.01
Cardiac ElectroPhysiology Simulator
CepsVector.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
31 #pragma once
32 
33 #include <functional>
34 #include <numeric>
35 
37 
39 namespace ceps
40 {
41 
43  template <class _Type, class _Alloc>
44  void
45  destroy(CepsVector<_Type,_Alloc>& vec, CepsBool deleteAll = true)
46  {
47  if (deleteAll)
48  for (_Type &v : vec)
50  return vec.clear();
51  }
52 
54  template <class _Type, class _Alloc>
55  CepsBool
56  contains(const CepsVector<_Type,_Alloc>& vec, const _Type& item)
57  {
58  auto it = std::find(vec.begin(), vec.end(), item);
59  return it != vec.end();
60  }
61 
63  template <class _Type, class _Alloc>
64  CepsBool
65  contains(const CepsVector<_Type,_Alloc>& vec, _Type&& item)
66  {
67  auto it = std::find(vec.begin(), vec.end(),item);
68  return it != vec.end();
69  }
70 
72  template <class _Type, class _Alloc, class InputIt>
73  void
74  pushBack(CepsVector<_Type,_Alloc> &vec, InputIt first, InputIt last)
75  {
76  vec.reserve (vec.size() + std::distance(first, last));
77  for (auto it=first; it!=last; ++it)
78  vec.push_back (*it);
79  return;
80  }
81 
83  template <class _Type, class _Alloc, class InputIt>
84  void
87  InputIt first,
88  InputIt last,
89  std::function<CepsBool(const _Type&)> func
90  )
91  {
92  vec.reserve (vec.size() + std::distance(first, last));
93  for (auto it=first; it!=last; ++it)
94  {
95  auto item = *it;
96  if (func(item))
97  vec.push_back(item);
98  }
99  return;
100  }
101 
103  template <class _Type, class _Alloc>
104  void
105  insert(CepsVector<_Type,_Alloc>& vec, const _Type& value)
106  {
107  vec.push_back(value);
108  return;
109  }
110 
112  template <class _Type, class _Alloc, class InputIt>
113  void
114  insertUnique(CepsVector<_Type,_Alloc>& vec, InputIt first, InputIt last)
115  {
116  vec.reserve (vec.size () + std::distance (first, last));
117  for (auto it = first; it != last; ++it)
118  {
119  auto item = *it;
120  if (not contains (vec, item))
121  vec.push_back (item);
122  }
123  return;
124  }
125 
127  template <class _Type, class _Alloc>
128  CepsBool
129  insertUnique (CepsVector<_Type,_Alloc>& vec, const _Type& value)
130  {
131  CepsBool b = contains(vec, value);
132  if (not b)
133  vec.push_back(value);
134  return not b;
135  }
136 
138  template <class _Type, class _Alloc>
139  CepsBool
141  {
142  CepsBool b = contains(vec, value);
143  if (not b)
144  vec.push_back(value);
145  return not b;
146  }
147 
149  template <class _Type, class _Alloc>
150  void
151  eraseValue(CepsVector<_Type,_Alloc>& vec, const _Type& value)
152  {
153  vec.erase(std::remove(vec.begin(),vec.end(),value),vec.end());
154  return;
155  }
156 
158  template <class _Type, class _Alloc, class InputIt>
159  void
160  eraseValues(CepsVector<_Type,_Alloc>& vec, InputIt first, InputIt last)
161  {
162  for (InputIt it=first; it!=last; ++it)
163  {
164  auto item = *it;
165  eraseValue(vec,item);
166  }
167  return;
168  }
169 
171  template <class _Type, class _Alloc>
173  find(CepsVector<_Type,_Alloc>& vec, const _Type& value)
174  {
175  return std::find(vec.begin(),vec.end(),value);
176  }
177 
179  template <class _Type, class _Alloc>
181  find(const CepsVector<_Type,_Alloc>& vec, const _Type& value)
182  {
183  return std::find(vec.begin(),vec.end(),value);
184  }
185 
187  template <class _Type, class _Alloc>
188  std::pair<CepsBool, CepsUInt>
189  indexOf(const CepsVector<_Type,_Alloc>& vec, const _Type &value)
190  {
191  auto it = find (vec, value);
192  if (it == vec.end ())
193  return {false, 0U};
194  return {true, std::distance (vec.begin (), it)};
195  }
196 
198  template <class _Type, class _Alloc>
199  CepsInt
200  argVector(const CepsVector<_Type,_Alloc>& vec, const _Type& value)
201  {
202  auto it = find(vec, value);
203  if (it == vec.end())
204  return -1;
205  return std::distance(vec.begin(), it);
206  }
207 
209  template <class _Type, class _Alloc>
210  CepsUInt
212  const CepsVector<_Type,_Alloc>& vec,
213  std::function<CepsBool(const _Type& x)> predicate
214  )
215  {
216  return std::count_if(vec.begin(),vec.end(),predicate);
217  }
218 
221  template <class _Type, class _Alloc>
222  CepsUInt
224  const CepsVector<_Type*,_Alloc>& vec,
225  std::function<CepsBool(_Type* x)> predicate
226  )
227  {
228  return std::count_if(vec.begin(),vec.end(),predicate);
229  }
230 
232  template <class _Type, class _Alloc, typename _Compare>
233  void
234  sort(CepsVector<_Type,_Alloc>& vec, _Compare compare)
235  {
236  std::sort(vec.begin(),vec.end(),compare);
237  return;
238  }
239 
241  template <class _Type, class _Alloc>
242  void
244  {
245  return sort(vec,std::less<_Type>());
246  }
247 
252  template <class _Type, class _Alloc, typename _Compare>
254  getSortPermutation(const CepsVector<_Type,_Alloc>& vec, _Compare compare)
255  {
256  CepsVector<CepsUInt> p(vec.size());
257  std::iota(p.begin(),p.end(),0);
258  std::sort(p.begin(),p.end(),[&] (CepsUInt i, CepsUInt j) {
259  return compare (vec[i],vec[j]);
260  });
261  return p;
262  }
263 
268  template <class _Type, class _Alloc>
271  {
272  return getSortPermutation(vec, std::less<_Type>());
273  }
274 
276  template <class _Type, class _Alloc>
277  void
279  {
280  const CepsUInt& n = vec.size();
281  CepsVector<CepsBool> done(n,false);
282  for (CepsUInt i=0; i<n; ++i)
283  {
284  if (done[i])
285  continue;
286 
287  done[i] = true;
288  CepsUInt prev_j = i, j = p[i];
289  while (i != j)
290  {
291  std::swap(vec[prev_j], vec[j]);
292  done[j] = true;
293  prev_j = j;
294  j = p[j];
295  }
296  }
297  return;
298  }
299 
301  template <class _Type, class _Alloc>
304  {
305  const CepsUInt &n = target.size();
306  const CepsUInt &m = target.size();
307  CepsVector<CepsUInt> p (m, static_cast<CepsUInt>(-1));
308 
309  using eq_t = std::equal_to<_Type>;
310 
311  // loop to store target elements indices into origin basis
312  for (CepsUInt i=0U; i<n; ++i)
313  for (CepsUInt j=0U; j<m; ++j)
314  if (eq_t {}(origin[i], target[j]))
315  p[j] = i;
316 
317  // only check if target Union origin == target
318  for (CepsUInt j=0U; j<m; ++j)
319  CEPS_ABORT_IF (p[j]>n,
320  "target union with origin is not target. Index of " << p[j] << " is missing into target vec"
321  );
322 
323  return p;
324  }
325 
327  template <class _Type, class _Alloc>
328  void
330  {
331  std::rotate(vec.rbegin(),vec.rbegin()+n,vec.rend());
332  return;
333  }
334 
336  template <class _Type, class _Alloc>
337  void
339  {
340  std::rotate(vec.begin(),vec.begin()+n,vec.end());
341  return;
342  }
343 
344  /*
345  template <class _Type, class _Alloc>
346  void
347  roll (CepsVector<_Type, _Alloc> &vec, CepsUInt i = 1)
348  {
349  return rrotate (vec, i);
350  }
351  */
352 
354  template <class _Type, class _Alloc>
355  CepsUInt
357  {
358  CEPS_ABORT_IF(vec.empty(),"empty vector");
359 
360  CepsUInt i_min = 0;
361  _Type x_min = vec[0];
362  const CepsUInt &n = vec.size();
363 
364  for (CepsUInt i=1; i<n; ++i)
365  if (vec[i] < x_min)
366  {
367  x_min = vec[i];
368  i_min = i;
369  }
370  return i_min;
371  }
372 
374  template <class _Type, class _Alloc, typename _Res>
375  CepsUInt
376  argmin(CepsVector<_Type,_Alloc>& vec, std::function<_Res(const _Type&)> func)
377  {
378  CEPS_ABORT_IF(vec.empty(),"empty vector");
379 
380  CepsUInt i_min = 0;
381  _Type x_min = vec[0];
382  _Res f_min = func(x_min);
383  _Res f;
384  const CepsUInt& n = vec.size ();
385 
386  for (CepsUInt i=1; i<n; ++i)
387  {
388  f = func(vec[i]);
389  if (f < f_min)
390  {
391  x_min = vec[i];
392  f_min = f;
393  i_min = i;
394  }
395  }
396  return i_min;
397  }
398 
400  template <class _Type, class _Alloc>
401  CepsUInt
403  {
404  CEPS_ABORT_IF(vec.empty(),"empty vector");
405 
406  CepsUInt i_max = 0;
407  _Type x_max = vec[0];
408  const CepsUInt& n = vec.size();
409 
410  for (CepsUInt i=1; i<n; ++i)
411  if (x_max < vec[i])
412  {
413  x_max = vec[i];
414  i_max = i;
415  }
416  return i_max;
417  }
418 
420  template <class _Type, class _Alloc, typename _Res>
421  CepsUInt
422  argmax (CepsVector<_Type,_Alloc>& vec, std::function<_Res(const _Type&)> func)
423  {
424  CEPS_ABORT_IF(vec.empty(),"empty vector");
425 
426  CepsUInt i_max = 0;
427  _Type x_max = vec[0];
428  _Res f_max = func(x_max);
429  _Res f;
430  const CepsUInt& n = vec.size();
431 
432  for (CepsUInt i=1; i<n; ++i)
433  {
434  f = func (vec[i]);
435  if (f_max < f)
436  {
437  x_max = vec[i];
438  f_max = f;
439  i_max = i;
440  }
441  }
442  return i_max;
443  }
444 
446  template <class _Type, class _Alloc>
447  const _Type&
449  {
450  return vec[argmin(vec)];
451  }
452 
454  template <class _Type, class _Alloc>
455  _Type &
457  {
458  return vec[argmin(vec)];
459  }
460 
462  template <class _Type, class _Alloc>
463  const _Type&
465  {
466  return vec[argmax(vec)];
467  }
468 
470  template <class _Type, class _Alloc>
471  _Type&
473  {
474  return vec[argmax(vec)];
475  }
476 
485  template <class _Type, class _Alloc>
486  void
488  {
489  CepsUInt N = vec.size();
490  vecOut.resize(N+1, _Type(0x0));
491  for (CepsUInt i=1U; i<N+1; ++i)
492  vecOut[i] = vecOut[i-1] + vec[i-1];
493  return;
494  }
495 
501  template <class _Type, class _Alloc>
504  {
505  CepsVector<_Type,_Alloc> out = {};
506  cumSum(vec,out);
507  return out;
508  }
509 
520  template <typename _Input1, typename _Input2>
521  void
522  setIntersectionIndices(_Input1 first1,
523  _Input1 last1,
524  _Input2 first2,
525  _Input2 last2,
526  CepsVector<CepsUInt>& indices1,
527  CepsVector<CepsUInt>& indices2)
528  {
529  CepsSize n1 = std::distance(first1, last1);
530  CepsSize n2 = std::distance(first2, last2);
531 
532  indices1.clear();
533  indices2.clear();
534  indices1.reserve(n1);
535  indices2.reserve(n2);
536 
537  while (first1 != last1 && first2 != last2)
538  if (*first1<*first2)
539  ++first1;
540  else if (*first2<*first1)
541  ++first2;
542  else // are same
543  {
544  indices1.push_back(n1-std::distance(first1,last1));
545  indices2.push_back(n2-std::distance(first2,last2));
546  ++first1;
547  ++first2;
548  }
549  return;
550  }
551 
555  template <class _Key, class _Value>
556  void
558  const CepsVector<_Value>& vals1,
559  const CepsVector<_Key>& keys2,
560  CepsVector<_Value>& vals2,
561  _Value defaultValue = _Value ())
562  {
563  // sort keys1
564  CepsVector<_Key> skeys1 = keys1;
566  ceps::applyPermutation (skeys1, perm1);
567 
568  // sort keys2
569  CepsVector<_Key> skeys2 = keys2;
571  ceps::applyPermutation (skeys2, perm2);
572 
573  CepsVector<CepsUInt> idx1; // indices of intersection in skeys1
574  CepsVector<CepsUInt> idx2; // indices of intersection in skeys2
575 
576  setIntersectionIndices(skeys1.begin(), skeys1.end(), skeys2.begin(), skeys2.end(), idx1, idx2);
577  vals2.resize (keys2.size(), _Value(defaultValue));
578 
579  const CepsUInt &n = idx1.size();
580  for (CepsUInt i = 0; i < n; ++i)
581  vals2[perm2[idx2[i]]] = vals1[perm1[idx1[i]]];
582 
583  return;
584  }
585 
586 
587 
588 
590  template <typename _Type>
591  void
593  {
594  if (vec.empty())
595  return;
596 
597  vec.erase(vec.begin());
598  return;
599  }
600 
603  template <class _Type>
604  void
606  CepsUInt s, CepsBool eqDistrib = true)
607  {
608  const CepsUInt &n = vec.size();
609  const CepsSize &rest = n % s;
610  const CepsSize &div = n / s;
611 
612  if (rest !=0 and eqDistrib)
613  {
614  CEPS_ABORT("The size " + std::to_string(n) +
615  " is not divisible into groups of size " +
616  std::to_string(s) + ". The last one mays be incomplete.");
617  return;
618  }
619 
620  vecs.clear();
621  vecs.reserve(div);
622 
623  for (CepsUInt i = 0; i < n; ++i)
624  {
625  CepsVector<_Type> subVec = {};
626  subVec.reserve(s);
627  for (CepsUInt j = 0; j < s and i < n; ++j, ++i)
628  subVec.push_back(vec[i]);
629  vecs.push_back(subVec);
630  }
631 
632  return;
633  }
634 
636  template <class _Type, class _Res>
637  _Res
638  applyAlong(const CepsVector<_Type> &vec, std::function<void(const _Type &, _Res &)> f,
639  _Res init = _Res ())
640  {
641  for (const _Type &v : vec)
642  f(v,init);
643  return init;
644  }
645 
646 } // namespace ceps
647 
649 template <class _Type1, class _Alloc1, class _Type2, class _Alloc2>
652 {
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 !");
656 
657  for (CepsUInt i = 0; i < n; ++i)
658  vec[i] += other[i];
659  return vec;
660 }
661 
663 template <
664  class _Type1,
665  class _Alloc1,
666  class _Type2,
667  class _Alloc2,
668  class _ResultType = decltype (std::declval<_Type1> () + std::declval<_Type2> ())>
671 {
672  using ResultType = decltype (std::declval<_Type1> () + std::declval<_Type2> ());
673 
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 !");
677 
679  c.resize (n);
680  for (CepsUInt i = 0; i < n; ++i)
681  c[i] = a[i] + b[i];
682  return c;
683 }
684 
686 template <class _Type1, class _Alloc1, class _Type2, class _Alloc2>
689 {
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 !");
693 
694  for (CepsUInt i = 0; i < n; ++i)
695  vec[i] -= other[i];
696  return vec;
697 }
698 
700 template <
701  class _Type1,
702  class _Alloc1,
703  class _Type2,
704  class _Alloc2,
705  class _ResultType = decltype (std::declval<_Type1> () - std::declval<_Type2> ())>
708 {
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 !");
712 
714  c.resize (n);
715  for (CepsUInt i = 0; i < n; ++i)
716  c[i] = a[i] - b[i];
717  return c;
718 }
719 
721 template <class _Type1, class _Alloc1, class _Type2, class _Alloc2>
724 {
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 !");
728 
729  for (CepsUInt i = 0; i < n; ++i)
730  vec[i] *= other[i];
731  return vec;
732 }
733 
735 template <
736  class _Type1,
737  class _Alloc1,
738  class _Type2,
739  class _Alloc2,
740  class _ResultType = decltype (std::declval<_Type1> () * std::declval<_Type2> ())>
743 {
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 !");
747 
749  c.resize (n);
750  for (CepsUInt i = 0; i < n; ++i)
751  c[i] = a[i] * b[i];
752  return c;
753 }
754 
756 template <class _Type1, class _Alloc1, class _Type2, class _Alloc2>
759 {
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 !");
763 
764  for (CepsUInt i = 0; i < n; ++i)
765  vec[i] /= other[i];
766  return vec;
767 }
768 
770 template <
771  class _Type1,
772  class _Alloc1,
773  class _Type2,
774  class _Alloc2,
775  class _ResultType = decltype (std::declval<_Type1> () / std::declval<_Type2> ())>
778 {
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 !");
782 
784  c.resize (n);
785  for (CepsUInt i = 0; i < n; ++i)
786  c[i] = a[i] / b[i];
787  return c;
788 }
789 
791 template <class _Type, class _Alloc>
792 std::ostream &
793 operator<< (std::ostream &os, const CepsVector<_Type, _Alloc> &v)
794 {
795  os << "[";
796  for (const _Type &item : v)
797  os << item << " ";
798  os << "]" << std::flush;
799  return os;
800 }
801 
803 template <class _Type, class _Compare>
804 std::ostream &
805 operator<< (std::ostream &os, const CepsSet<_Type, _Compare> &v)
806 {
807  os << "[";
808  for (const _Type &item : v)
809  os << item << " ";
810  os << "]" << std::flush;
811  return os;
812 }
#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.
Definition: CepsTypes.hpp:209
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
size_t CepsSize
Size unsigned.
Definition: CepsTypes.hpp:126
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
int32_t CepsInt
Need 32 bit integer.
Definition: CepsTypes.hpp:106
CepsVector< _ResultType, _Alloc1 > operator*(const CepsVector< _Type1, _Alloc1 > &a, const CepsVector< _Type2, _Alloc2 > &b)
Term by term multiplication of 2 vectors.
Definition: CepsVector.hpp:742
CepsVector< _Type1, _Alloc1 > & operator*=(CepsVector< _Type1, _Alloc1 > &vec, const CepsVector< _Type2, _Alloc2 > &other)
Term by term multiplication of 2 vectors.
Definition: CepsVector.hpp:723
CepsVector< _Type1, _Alloc1 > & operator/=(CepsVector< _Type1, _Alloc1 > &vec, const CepsVector< _Type2, _Alloc2 > &other)
Term by term division of 2 vectors.
Definition: CepsVector.hpp:758
CepsVector< _ResultType, _Alloc1 > operator+(const CepsVector< _Type1, _Alloc1 > &a, const CepsVector< _Type2, _Alloc2 > &b)
Term by term sum of 2 vectors.
Definition: CepsVector.hpp:670
std::ostream & operator<<(std::ostream &os, const CepsVector< _Type, _Alloc > &v)
Output operator.
Definition: CepsVector.hpp:793
CepsVector< _ResultType, _Alloc1 > operator/(const CepsVector< _Type1, _Alloc1 > &a, const CepsVector< _Type2, _Alloc2 > &b)
Term by term division of 2 vectors.
Definition: CepsVector.hpp:777
CepsVector< _Type1, _Alloc1 > & operator+=(CepsVector< _Type1, _Alloc1 > &vec, const CepsVector< _Type2, _Alloc2 > &other)
Term by term sum and assign of 2 vectors.
Definition: CepsVector.hpp:651
CepsVector< _Type1, _Alloc1 > & operator-=(CepsVector< _Type1, _Alloc1 > &vec, const CepsVector< _Type2, _Alloc2 > &other)
Term by term difference of 2 vectors.
Definition: CepsVector.hpp:688
CepsVector< _ResultType, _Alloc1 > operator-(const CepsVector< _Type1, _Alloc1 > &a, const CepsVector< _Type2, _Alloc2 > &b)
Term by term difference of 2 vectors.
Definition: CepsVector.hpp:707
A namespace for all utility methods.
void insert(CepsVector< _Type, _Alloc > &vec, const _Type &value)
Conditional insertion of several elements.
Definition: CepsVector.hpp:105
CepsBool contains(const CepsVector< _Type, _Alloc > &vec, const _Type &item)
Tells if vectors contains a given item.
Definition: CepsVector.hpp:56
void eraseValue(CepsVector< _Type, _Alloc > &vec, const _Type &value)
Removes a value from a vector.
Definition: CepsVector.hpp:151
void applyPermutation(CepsVector< _Type, _Alloc > &vec, const CepsVector< CepsUInt > &p)
Apply a permutation to a vector.
Definition: CepsVector.hpp:278
void cumSum(const CepsVector< _Type, _Alloc > &vec, CepsVector< _Type, _Alloc > &vecOut)
Cumulated sum of values.
Definition: CepsVector.hpp:487
void pushBack(CepsVector< _Type, _Alloc > &vec, InputIt first, InputIt last)
Classic push back for several elements.
Definition: CepsVector.hpp:74
CepsUInt argmax(CepsVector< _Type, _Alloc > &vec)
Returns the position of the maximum in a whole vector.
Definition: CepsVector.hpp:402
CepsUInt argmin(CepsVector< _Type, _Alloc > &vec)
Returns the position of the minimum in a whole vector.
Definition: CepsVector.hpp:356
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.
Definition: CepsVector.hpp:254
void rightRotate(CepsVector< _Type, _Alloc > &vec, CepsUInt n=1)
Rotate n times the whole vector to the right.
Definition: CepsVector.hpp:329
CepsVector< _Type, _Alloc >::iterator find(CepsVector< _Type, _Alloc > &vec, const _Type &value)
Returns the result of find in the whole vector.
Definition: CepsVector.hpp:173
CepsInt argVector(const CepsVector< _Type, _Alloc > &vec, const _Type &value)
Get position of element in vector, -1 if not found.
Definition: CepsVector.hpp:200
void insertUnique(CepsVector< _Type, _Alloc > &vec, InputIt first, InputIt last)
Set behaviour: insert if elements does not exist in vector.
Definition: CepsVector.hpp:114
const _Type & max(const CepsVector< _Type, _Alloc > &vec)
Returns the maximum of the vector, const version.
Definition: CepsVector.hpp:464
void eraseValues(CepsVector< _Type, _Alloc > &vec, InputIt first, InputIt last)
Removes several values from a vector.
Definition: CepsVector.hpp:160
void sort(CepsVector< _Type, _Alloc > &vec)
Basic sorting of whole vector, increasing values.
Definition: CepsVector.hpp:243
const _Type & min(const CepsVector< _Type, _Alloc > &vec)
Returns the minimum of the vector, const version.
Definition: CepsVector.hpp:448
void destroy(CepsMap< _Key, _Tp, _Compare, _Alloc > &map, CepsBool deleteAll=true)
Deletes all elements of the map properly, even if created with new.
Definition: CepsMap.hpp:93
_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.
Definition: CepsVector.hpp:638
void popFront(CepsVector< _Type > &vec)
Remove first element.
Definition: CepsVector.hpp:592
void insertIf(CepsVector< _Type, _Alloc > &vec, InputIt first, InputIt last, std::function< CepsBool(const _Type &)> func)
Conditional insertion of several elements.
Definition: CepsVector.hpp:85
CepsVector< _Type, _Alloc >::const_iterator find(const CepsVector< _Type, _Alloc > &vec, const _Type &value)
Returns the result of find in the whole vector.
Definition: CepsVector.hpp:181
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.
Definition: CepsVector.hpp:189
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,...
Definition: CepsVector.hpp:605
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.
Definition: CepsVector.hpp:211
void leftRotate(CepsVector< _Type, _Alloc > &vec, CepsUInt n=1)
Rotate n times the whole vector to the left.
Definition: CepsVector.hpp:338
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.
Definition: CepsVector.hpp:522
void sort(CepsVector< _Type, _Alloc > &vec, _Compare compare)
Sort whole vector with specified comparator.
Definition: CepsVector.hpp:234
CepsVector< CepsUInt > getIndicesInVector(const CepsVector< _Type, _Alloc > &origin, const CepsVector< _Type, _Alloc > &target)
Compute indices of target elements into the origin vector.
Definition: CepsVector.hpp:303
void destroyObject(_Type &)
Destroy[delete] any type.
Definition: CepsMemory.hpp:116
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....
Definition: CepsVector.hpp:557