TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
TRUSTVect_tools.tpp
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef TRUSTVect_tools_TPP_included
17#define TRUSTVect_tools_TPP_included
18
19#ifdef MICROSOFT
20#define HUGE_VALL 1e99
21#endif
22#include <TRUST_Ref.h>
23
24/*! Small iterator class to scan blocks of a MD vector (blocks described by integer indices) or scan a single big block (trustIdType).
25 * The important point: the operator*() always returns a trustIdType (TID), whether internal data is int* or trustIdType* :
26 * - in sequential, we can scan a whole Big array from start to end,
27 * - in parallel, we can scan chunks of the arrays, as defined by MD_Vector_mono::blocs_items_to_compute_ (which store int values, never long)
28 */
29template<typename _SIZE_>
31{
32 Block_Iter() = default;
33 Block_Iter(const Block_Iter& other) = default; // default copy ctor, will copy all members
34 Block_Iter& operator=(const Block_Iter& other) = default; // default copy operator
35 Block_Iter(const ArrOfInt& items_blocs, const ArrOfInt& items) : int_ptr(items_blocs.addr())
36 {
37 items_ = items;
38 }
39 Block_Iter(const ArrOfInt& items_blocs) : int_ptr(items_blocs.addr()) {}
40 Block_Iter(_SIZE_ s, _SIZE_ e) : start(s), end(e) {}
41
42 _SIZE_ operator*() const
43 {
44 return start == -1 ? (_SIZE_)*int_ptr : start; // potentially casting!
45 }
46 Block_Iter operator++(int) // Postfix operator
47 {
48 Block_Iter ret = *this;
49 if(int_ptr) int_ptr++;
50 else std::swap(start, end);
51 return ret;
52 }
53 bool empty() const { return int_ptr == nullptr && start == -1; }
54
55 const int * int_ptr=nullptr;
56 OBS_PTR(ArrOfInt) items_;
57 _SIZE_ start=-1;
58 _SIZE_ end=-1;
59};
60
61template <typename _SIZE_>
62Block_Iter<_SIZE_> determine_blocks(Mp_vect_options opt, const MD_Vector& md, const _SIZE_ vect_size_tot, const int line_size, int& nblocs_left);
63
64/*! @brief renvoie 1 si meme strucuture parallele et egalite au sens TRUSTArray (y compris espaces virtuels) BM: faut-il etre aussi strict, comparer uniquement size() elements ?
65 *
66 */
67template<typename _TYPE_, typename _SIZE_>
68inline int operator==(const TRUSTVect<_TYPE_,_SIZE_>& x, const TRUSTVect<_TYPE_,_SIZE_>& y)
69{
72 if (!(x.get_md_vector() == y.get_md_vector())) return 0;
73 const TRUSTArray<_TYPE_,_SIZE_>& ax = x;
74 const TRUSTArray<_TYPE_,_SIZE_>& ay = y;
75 return ax == ay;
76}
77
78template<typename _TYPE_, typename _SIZE_>
79inline int operator!=(const TRUSTVect<_TYPE_,_SIZE_>& x, const TRUSTVect<_TYPE_,_SIZE_>& y)
80{
81 return !(x == y);
82}
83
84template<typename _TYPE_, typename _SIZE_>
85extern void invalidate_data(TRUSTVect<_TYPE_,_SIZE_>& resu, Mp_vect_options opt);
86
87// ==================================================================================================================================
88// DEBUT code pour operation min/max/abs
89enum class TYPE_OPERATION_VECT { IMAX_ , IMIN_ , MAX_ , MIN_ , MAX_ABS_ , MIN_ABS_ };
90
91
92inline double neutral_value_double_(const bool IS_MAX)
93{
94 return IS_MAX ? (-HUGE_VAL) : HUGE_VAL;
95}
96
97inline float neutral_value_float_(const bool IS_MAX)
98{
99 return IS_MAX ? (-HUGE_VALF) : HUGE_VALF; // et ouiiiiiiiiiiiiiiii
100}
101
102inline int neutral_value_int_(const bool IS_MAX)
103{
104 return IS_MAX ? INT_MIN : INT_MAX;
105}
106
107template <typename _TYPE_, TYPE_OPERATION_VECT _TYPE_OP_ >
108inline _TYPE_ neutral_value()
109{
110 static constexpr bool IS_MAX = ((_TYPE_OP_ == TYPE_OPERATION_VECT::IMAX_) || (_TYPE_OP_ == TYPE_OPERATION_VECT::MAX_)), IS_MAX_ABS = (_TYPE_OP_ == TYPE_OPERATION_VECT::MAX_ABS_);
111 if (IS_MAX_ABS)
112 return 0;
113 else
114 {
115 _TYPE_ neutral_val;
116
117 if (std::is_same<_TYPE_, double>::value) neutral_val = (_TYPE_) neutral_value_double_(IS_MAX);
118 else if (std::is_same<_TYPE_, float>::value) neutral_val = (_TYPE_) neutral_value_float_(IS_MAX);
119 else neutral_val = (_TYPE_) neutral_value_int_(IS_MAX);
120
121 return neutral_val;
122 }
123}
124
125template <typename _TYPE_, typename _SIZE_, typename _TYPE_RETURN_, TYPE_OPERATION_VECT _TYPE_OP_ >
126extern _TYPE_RETURN_ local_extrema_vect_generic(const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt);
127
128template<typename _TYPE_, typename _SIZE_>
129inline int local_imax_vect(const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_REAL_ITEMS)
130{
131 return local_extrema_vect_generic<_TYPE_,_SIZE_,int,TYPE_OPERATION_VECT::IMAX_>(vx,opt);
132}
133
134template<typename _TYPE_, typename _SIZE_>
135inline int local_imin_vect(const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_REAL_ITEMS)
136{
137 return local_extrema_vect_generic<_TYPE_,_SIZE_,int,TYPE_OPERATION_VECT::IMIN_>(vx,opt);
138}
139
140template<typename _TYPE_, typename _SIZE_>
141inline _TYPE_ local_max_vect_(const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_REAL_ITEMS)
142{
143 return local_max_vect(vx,opt);
144}
145
146template<typename _TYPE_, typename _SIZE_>
147inline _TYPE_ local_max_vect(const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_REAL_ITEMS)
148{
149 return local_extrema_vect_generic<_TYPE_,_SIZE_,_TYPE_ /* return type */,TYPE_OPERATION_VECT::MAX_>(vx,opt);
150}
151
152template<typename _TYPE_, typename _SIZE_>
153inline _TYPE_ local_min_vect_(const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_REAL_ITEMS)
154{
155 return local_min_vect(vx,opt);
156}
157
158template<typename _TYPE_, typename _SIZE_>
159inline _TYPE_ local_min_vect(const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_REAL_ITEMS)
160{
161 return local_extrema_vect_generic<_TYPE_,_SIZE_,_TYPE_ /* return type */,TYPE_OPERATION_VECT::MIN_>(vx, opt);
162}
163
164template<typename _TYPE_, typename _SIZE_>
165inline _TYPE_ mp_max_vect_(const TRUSTVect<_TYPE_,_SIZE_>& x, Mp_vect_options opt=VECT_REAL_ITEMS)
166{
167 return mp_max_vect(x, opt);
168}
169
170template<typename _TYPE_, typename _SIZE_>
171inline _TYPE_ mp_max_vect(const TRUSTVect<_TYPE_,_SIZE_>& x, Mp_vect_options opt=VECT_REAL_ITEMS)
172{
173 _TYPE_ s = local_max_vect(x, opt);
174 s = Process::mp_max(s);
175 return s;
176}
177
178template<typename _TYPE_, typename _SIZE_>
179inline _TYPE_ mp_min_vect_(const TRUSTVect<_TYPE_,_SIZE_>& x, Mp_vect_options opt=VECT_REAL_ITEMS)
180{
181 return mp_min_vect(x, opt);
182}
183
184template<typename _TYPE_, typename _SIZE_>
185inline _TYPE_ mp_min_vect(const TRUSTVect<_TYPE_,_SIZE_>& x, Mp_vect_options opt=VECT_REAL_ITEMS)
186{
187 _TYPE_ s = local_min_vect(x, opt);
188 s = Process::mp_min(s);
189 return s;
190}
191
192template<typename _SIZE_>
193inline trustIdType mp_somme_vect(const TRUSTVect<trustIdType,_SIZE_>& vx)
194{
195 trustIdType x = local_somme_vect(vx);
196 trustIdType y = Process::mp_sum(x);
197 return y;
198}
199
200template<typename _SIZE_>
201inline double mp_somme_vect_as_double(const TRUSTVect<trustIdType,_SIZE_>& vx)
202{
203 return static_cast<double>(mp_somme_vect(vx));
204}
205
206#if INT_is_64_ == 2
207template<typename _SIZE_>
208inline trustIdType mp_somme_vect(const TRUSTVect<int,_SIZE_>& vx)
209{
210 int x = local_somme_vect(vx);
211 trustIdType y = Process::mp_sum(x);
212 return y;
213}
214
215template<typename _SIZE_>
216inline double mp_somme_vect_as_double(const TRUSTVect<int,_SIZE_>& vx)
217{
218 return static_cast<double>(mp_somme_vect(vx));
219}
220
221#endif
222
223template<typename _SIZE_>
224inline float mp_somme_vect(const TRUSTVect<float,_SIZE_>& vx)
225{
226 float x = local_somme_vect(vx);
227 float y = Process::mp_sum(x);
228 return y;
229}
230
231template<typename _SIZE_>
232inline double mp_somme_vect(const TRUSTVect<double,_SIZE_>& vx)
233{
234 double x = local_somme_vect(vx);
235 double y = Process::mp_sum(x);
236 return y;
237}
238
239template<typename _TYPE_, typename _SIZE_>
240inline _TYPE_ local_max_abs_vect_(const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_REAL_ITEMS)
241{
242 return local_max_abs_vect(vx,opt);
243}
244
245template<typename _TYPE_, typename _SIZE_>
246inline _TYPE_ local_max_abs_vect(const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_REAL_ITEMS)
247{
248 return local_extrema_vect_generic<_TYPE_,_SIZE_,_TYPE_ /* return type */,TYPE_OPERATION_VECT::MAX_ABS_>(vx, opt);
249}
250
251template<typename _TYPE_, typename _SIZE_>
252inline _TYPE_ local_min_abs_vect_(const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_REAL_ITEMS)
253{
254 return local_min_abs_vect(vx,opt);
255}
256
257template<typename _TYPE_, typename _SIZE_>
258inline _TYPE_ local_min_abs_vect(const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_REAL_ITEMS)
259{
260 return local_extrema_vect_generic<_TYPE_,_SIZE_,_TYPE_ /* return type */,TYPE_OPERATION_VECT::MIN_ABS_>(vx, opt);
261}
262
263template<typename _TYPE_, typename _SIZE_>
264inline _TYPE_ mp_max_abs_vect_(const TRUSTVect<_TYPE_,_SIZE_>& x, Mp_vect_options opt=VECT_REAL_ITEMS)
265{
266 return mp_max_abs_vect(x, opt);
267}
268
269template<typename _TYPE_, typename _SIZE_>
270inline _TYPE_ mp_max_abs_vect(const TRUSTVect<_TYPE_,_SIZE_>& x, Mp_vect_options opt=VECT_REAL_ITEMS)
271{
272 _TYPE_ s = local_max_abs_vect(x, opt);
273 s = Process::mp_max(s);
274 return s;
275}
276
277template<typename _TYPE_, typename _SIZE_>
278inline _TYPE_ mp_min_abs_vect_(const TRUSTVect<_TYPE_,_SIZE_>& x, Mp_vect_options opt=VECT_REAL_ITEMS)
279{
280 return mp_min_abs_vect(x, opt);
281}
282
283template<typename _TYPE_, typename _SIZE_>
284inline _TYPE_ mp_min_abs_vect(const TRUSTVect<_TYPE_,_SIZE_>& x, Mp_vect_options opt=VECT_REAL_ITEMS)
285{
286 _TYPE_ s = local_min_abs_vect(x, opt);
287 s = Process::mp_min(s);
288 return s;
289}
290
291template<typename _TYPE_, typename _SIZE_>
292extern _TYPE_ local_prodscal(const TRUSTVect<_TYPE_,_SIZE_>& vx, const TRUSTVect<_TYPE_,_SIZE_>& vy, Mp_vect_options opt=VECT_SEQUENTIAL_ITEMS);
293
294enum class TYPE_OPERATION_VECT_BIS { SQUARE_ , SOMME_ };
295
296template <typename _TYPE_, typename _SIZE_, TYPE_OPERATION_VECT_BIS _TYPE_OP_ >
297extern _TYPE_ local_operations_vect_bis_generic(const TRUSTVect<_TYPE_,_SIZE_>& vx,Mp_vect_options opt);
298
299template<typename _TYPE_, typename _SIZE_>
300inline _TYPE_ local_carre_norme_vect(const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_SEQUENTIAL_ITEMS)
301{
302 return local_operations_vect_bis_generic<_TYPE_,_SIZE_,TYPE_OPERATION_VECT_BIS::SQUARE_>(vx,opt);
303}
304
305template<typename _TYPE_, typename _SIZE_>
306inline _TYPE_ mp_carre_norme_vect(const TRUSTVect<_TYPE_,_SIZE_>& vx)
307{
308 return Process::mp_sum(local_carre_norme_vect(vx));
309}
310
311template<typename _TYPE_, typename _SIZE_>
312inline _TYPE_ local_somme_vect(const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_SEQUENTIAL_ITEMS)
313{
314 return local_operations_vect_bis_generic<_TYPE_,_SIZE_,TYPE_OPERATION_VECT_BIS::SOMME_>(vx,opt);
315}
316
317template<typename _TYPE_, typename _SIZE_>
318inline _TYPE_ mp_prodscal(const TRUSTVect<_TYPE_,_SIZE_>& x, const TRUSTVect<_TYPE_,_SIZE_>& y)
319{
320 return Process::mp_sum(local_prodscal(x, y));
321}
322
323template <typename _SIZE_>
324inline int mp_norme_vect(const TRUSTVect<int, _SIZE_>& vx) = delete; // forbidden
325
326template<typename _TYPE_, typename _SIZE_>
327inline _TYPE_ mp_norme_vect(const TRUSTVect<_TYPE_,_SIZE_>& vx)
328{
329 _TYPE_ x = mp_carre_norme_vect(vx);
330 x = sqrt(x);
331 return x;
332}
333
334template<typename _TYPE_, typename _SIZE_>
335inline _TYPE_ mp_norme_vect_(const TRUSTVect<_TYPE_,_SIZE_>& vx)
336{
337 return mp_norme_vect(vx);
338}
339
340template <typename _SIZE_>
341inline int mp_moyenne_vect(const TRUSTVect<int, _SIZE_>& x) = delete; // forbidden
342
343template<typename _TYPE_, typename _SIZE_>
344inline _TYPE_ mp_moyenne_vect(const TRUSTVect<_TYPE_,_SIZE_>& x)
345{
346#ifndef LATATOOLS
347 _TYPE_ s = mp_somme_vect(x);
348 trustIdType n;
349 const MD_Vector& md = x.get_md_vector();
350 if (md.non_nul()) n = md->nb_items_seq_tot() * x.line_size();
351 else
352 {
353 assert(Process::is_sequential()); // Coding error: mp_moyenne_vect is used on a not distributed TRUSTVect<double> !
354 n = x.size_totale();
355 }
356 return s / (_TYPE_)n;
357#else
358 return (_TYPE_) 0;
359#endif
360}
361// FIN code pour operation min/max/abs
362// ==================================================================================================================================
363
364// ==================================================================================================================================
365// DEBUT code pour operateurs vect/vect ou vect/scalair
366enum class TYPE_OPERATOR_VECT { ADD_ , SUB_ , MULT_ , DIV_ , EGAL_ };
367
368inline void error_divide(const char * nom_funct)
369{
370 Cerr << "What ??? Divide by 0 in " << nom_funct << " operator_divide() !!" << finl;
371 throw;
372}
373
374template <typename _TYPE_, typename _SIZE_, TYPE_OPERATOR_VECT _TYPE_OP_ >
375extern void operator_vect_vect_generic(TRUSTVect<_TYPE_,_SIZE_>& resu, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt);
376
377template<typename _TYPE_, typename _SIZE_>
378inline void operator_add(TRUSTVect<_TYPE_,_SIZE_>& resu, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_ALL_ITEMS)
379{
380 operator_vect_vect_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_VECT::ADD_>(resu,vx,opt);
381}
382
383template<typename _TYPE_, typename _SIZE_>
384inline void operator_sub(TRUSTVect<_TYPE_,_SIZE_>& resu, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_ALL_ITEMS)
385{
386 operator_vect_vect_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_VECT::SUB_>(resu,vx,opt);
387}
388
389template<typename _TYPE_, typename _SIZE_>
390inline void operator_multiply(TRUSTVect<_TYPE_,_SIZE_>& resu, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_ALL_ITEMS)
391{
392 operator_vect_vect_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_VECT::MULT_>(resu,vx,opt);
393}
394
395template<typename _SIZE_>
396inline void operator_divide(TRUSTVect<int, _SIZE_>& resu, const TRUSTVect<int, _SIZE_>& vx, Mp_vect_options opt=VECT_ALL_ITEMS) = delete; // forbidden
397
398template<typename _TYPE_, typename _SIZE_>
399inline void operator_divide(TRUSTVect<_TYPE_,_SIZE_>& resu, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_ALL_ITEMS)
400{
401 operator_vect_vect_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_VECT::DIV_>(resu,vx,opt);
402}
403
404template<typename _TYPE_, typename _SIZE_>
405inline void operator_egal(TRUSTVect<_TYPE_,_SIZE_>& resu, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_ALL_ITEMS)
406{
407 operator_vect_vect_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_VECT::EGAL_>(resu,vx,opt);
408}
409
410enum class TYPE_OPERATOR_SINGLE { ADD_ , SUB_ , MULT_ , DIV_ , EGAL_ , NEGATE_ , INV_ , ABS_ , SQRT_ , SQUARE_ };
411
412template <typename _TYPE_, typename _SIZE_, TYPE_OPERATOR_SINGLE _TYPE_OP_ >
413extern void operator_vect_single_generic(TRUSTVect<_TYPE_,_SIZE_>& resu, const _TYPE_ x, Mp_vect_options opt);
414
415template<typename _TYPE_, typename _SIZE_>
416inline void operator_add(TRUSTVect<_TYPE_,_SIZE_>& resu, const _TYPE_ x, Mp_vect_options opt=VECT_ALL_ITEMS)
417{
418 operator_vect_single_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_SINGLE::ADD_>(resu,x,opt);
419}
420
421template<typename _TYPE_, typename _SIZE_>
422inline void operator_sub(TRUSTVect<_TYPE_,_SIZE_>& resu, const _TYPE_ x, Mp_vect_options opt=VECT_ALL_ITEMS)
423{
424 operator_vect_single_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_SINGLE::SUB_>(resu,x,opt);
425}
426
427// ATTENTION : on utilise is_convertible sinon soucis quand TYPE = double et x = int ... ex : operator_multiply(TRUSTVect<double>, 1) ...
428template<typename _TYPE_, typename _SIZE_, typename _SCALAR_TYPE_>
429typename std::enable_if<std::is_convertible<_SCALAR_TYPE_, _TYPE_>::value >::type
430inline operator_multiply(TRUSTVect<_TYPE_,_SIZE_>& resu, const _SCALAR_TYPE_ x, Mp_vect_options opt=VECT_ALL_ITEMS)
431{
432 operator_vect_single_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_SINGLE::MULT_>(resu,x,opt);
433}
434
435template<typename _SIZE_>
436inline void operator_divide(TRUSTVect<int,_SIZE_>& resu, const int x, Mp_vect_options opt=VECT_ALL_ITEMS) = delete; // forbidden (avant c'etait possible ... a voir si besoin)
437
438template<typename _TYPE_, typename _SIZE_>
439inline void operator_divide(TRUSTVect<_TYPE_,_SIZE_>& resu, const _TYPE_ x, Mp_vect_options opt=VECT_ALL_ITEMS)
440{
441 operator_vect_single_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_SINGLE::DIV_>(resu,x,opt);
442}
443
444template<typename _TYPE_, typename _SIZE_>
445inline void operator_egal(TRUSTVect<_TYPE_,_SIZE_>& resu, _TYPE_ x, Mp_vect_options opt=VECT_ALL_ITEMS)
446{
447 operator_vect_single_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_SINGLE::EGAL_>(resu,x,opt);
448}
449
450template<typename _TYPE_, typename _SIZE_>
451inline void operator_negate(TRUSTVect<_TYPE_,_SIZE_>& resu, Mp_vect_options opt=VECT_ALL_ITEMS)
452{
453 operator_vect_single_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_SINGLE::NEGATE_>(resu,(_TYPE_)0 /* inutile */,opt);
454}
455
456template<typename _SIZE_>
457inline void operator_inverse(TRUSTVect<int,_SIZE_>& resu, Mp_vect_options opt=VECT_ALL_ITEMS) = delete; // forbidden
458
459template<typename _TYPE_, typename _SIZE_>
460inline void operator_inverse(TRUSTVect<_TYPE_,_SIZE_>& resu, Mp_vect_options opt=VECT_ALL_ITEMS)
461{
462 operator_vect_single_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_SINGLE::INV_>(resu,0. /* inutile */,opt);
463}
464
465template<typename _TYPE_, typename _SIZE_>
466inline void operator_abs(TRUSTVect<_TYPE_,_SIZE_>& resu, Mp_vect_options opt=VECT_ALL_ITEMS)
467{
468 operator_vect_single_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_SINGLE::ABS_>(resu,(_TYPE_)0 /* inutile */,opt);
469}
470
471template<typename _SIZE_>
472inline void racine_carree(TRUSTVect<int,_SIZE_>& resu, Mp_vect_options opt=VECT_ALL_ITEMS) = delete; // forbidden
473
474template<typename _TYPE_, typename _SIZE_>
475inline void racine_carree(TRUSTVect<_TYPE_,_SIZE_>& resu, Mp_vect_options opt=VECT_ALL_ITEMS)
476{
477 operator_vect_single_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_SINGLE::SQRT_>(resu,0. /* inutile */,opt);
478}
479
480template<typename _SIZE_>
481inline void racine_carree_(TRUSTVect<int,_SIZE_>& resu, Mp_vect_options opt=VECT_ALL_ITEMS) = delete; // forbidden
482
483template<typename _TYPE_, typename _SIZE_>
484inline void racine_carree_(TRUSTVect<_TYPE_,_SIZE_>& resu, Mp_vect_options opt=VECT_ALL_ITEMS)
485{
486 racine_carree(resu,opt);
487}
488
489template<typename _TYPE_, typename _SIZE_>
490inline void carre(TRUSTVect<_TYPE_,_SIZE_>& resu, Mp_vect_options opt=VECT_ALL_ITEMS)
491{
492 operator_vect_single_generic<_TYPE_,_SIZE_,TYPE_OPERATOR_SINGLE::SQUARE_>(resu,0. /* inutile */,opt);
493}
494
495template<typename _TYPE_, typename _SIZE_>
496inline void carre_(TRUSTVect<_TYPE_,_SIZE_>& resu, Mp_vect_options opt)
497{
498 carre(resu,opt);
499}
500
501// FIN code pour operateurs vect/vect ou vect/scalair
502// ==================================================================================================================================
503
504// ==================================================================================================================================
505// DEBUT code pour operations speciales
506enum class TYPE_OPERATION_VECT_SPEC { ADD_ , SQUARE_ };
507
508template <TYPE_OPERATION_VECT_SPEC _TYPE_OP_, typename _SIZE_>
509inline void ajoute_operation_speciale_generic(TRUSTVect<int,_SIZE_>& resu, int alpha, const TRUSTVect<int,_SIZE_>& vx, Mp_vect_options opt) = delete; // forbidden ... ajoute si besoin
510
511template <TYPE_OPERATION_VECT_SPEC _TYPE_OP_ ,typename _TYPE_, typename _SIZE_>
512extern void ajoute_operation_speciale_generic(TRUSTVect<_TYPE_,_SIZE_>& resu, _TYPE_ alpha, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt);
513
514template<typename _TYPE_, typename _SIZE_>
515inline void ajoute_alpha_v(TRUSTVect<_TYPE_,_SIZE_>& resu, _TYPE_ alpha, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_REAL_ITEMS)
516{
517 ajoute_operation_speciale_generic<TYPE_OPERATION_VECT_SPEC::ADD_,_TYPE_>(resu,alpha,vx,opt);
518}
519
520template<typename _TYPE_, typename _SIZE_>
521inline void ajoute_carre(TRUSTVect<_TYPE_,_SIZE_>& resu, _TYPE_ alpha, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_ALL_ITEMS)
522{
523 ajoute_operation_speciale_generic<TYPE_OPERATION_VECT_SPEC::SQUARE_,_TYPE_>(resu,alpha,vx,opt);
524}
525
526template<typename _TYPE_, typename _SIZE_>
527extern void ajoute_produit_scalaire(TRUSTVect<_TYPE_,_SIZE_>& resu, _TYPE_ alpha, const TRUSTVect<_TYPE_,_SIZE_>& vx, const TRUSTVect<_TYPE_,_SIZE_>& vy, Mp_vect_options opt = VECT_ALL_ITEMS);
528
529enum class TYPE_OPERATION_VECT_SPEC_GENERIC { MUL_ , DIV_ };
530
531template <TYPE_OPERATION_VECT_SPEC_GENERIC _TYPE_OP_ , typename _TYPE_, typename _SIZE_>
532extern void operation_speciale_tres_generic(TRUSTVect<_TYPE_,_SIZE_>& resu, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt);
533
534template <TYPE_OPERATION_VECT_SPEC_GENERIC _TYPE_OP_, typename _SIZE_>
535inline void operation_speciale_tres_generic(TRUSTVect<int,_SIZE_>& resu, const TRUSTVect<int,_SIZE_>& vx, Mp_vect_options opt) = delete; // forbidden !!
536
537template<typename _SIZE_>
538inline void tab_multiply_any_shape_(TRUSTVect<int,_SIZE_>& resu, const TRUSTVect<int,_SIZE_>& vx, Mp_vect_options opt) = delete; // forbidden
539
540template<typename _TYPE_, typename _SIZE_>
541inline void tab_multiply_any_shape_(TRUSTVect<_TYPE_,_SIZE_>& resu, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt)
542{
543 operation_speciale_tres_generic<TYPE_OPERATION_VECT_SPEC_GENERIC::MUL_,_TYPE_>(resu,vx,opt);
544}
545
546template<typename _SIZE_>
547inline void tab_divide_any_shape_(TRUSTVect<int,_SIZE_>& resu, const TRUSTVect<int,_SIZE_>& vx, Mp_vect_options opt) = delete; // forbidden
548
549template<typename _TYPE_, typename _SIZE_>
550inline void tab_divide_any_shape_(TRUSTVect<_TYPE_,_SIZE_>& resu, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt)
551{
552 operation_speciale_tres_generic<TYPE_OPERATION_VECT_SPEC_GENERIC::DIV_,_TYPE_>(resu,vx,opt);
553}
554
555// Cette methode permettent de multiplier un tableau a plusieurs dimensions par un tableau de dimension inferieure (par exemple un tableau a trois composantes par un tableau a une composante).
556// Chaque valeur du tableau vx est utilisee pour plusieurs items consecutifs du tableau resu (le nombre de fois est le rapport des line_size() des deux tableaux).
557// resu.line_size() doit etre un multiple int de vx.line_size() et les descripteurs doivent etre identiques.
558// Cas particulier: vx peut contenir une constante unique (size_array() == 1 et descripteur nul), dans ce cas c'est un simple produit par la constante
559template<typename _TYPE_, typename _SIZE_>
560inline void tab_multiply_any_shape(TRUSTVect<_TYPE_,_SIZE_>& resu, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_ALL_ITEMS)
561{
562 if (vx.size_array() == 1 && !vx.get_md_vector().non_nul()) // Produit par une constante
563 {
564 const _TYPE_ x = vx[0];
565 operator_multiply(resu, x, opt);
566 }
567 else if (vx.line_size() == resu.line_size()) // Produit membre a membre
568 operator_multiply(resu, vx, opt);
569 else // Cas general
570 tab_multiply_any_shape_(resu, vx, opt);
571}
572
573template<typename _SIZE_>
574inline void tab_multiply_any_shape(TRUSTVect<int,_SIZE_>& resu, const TRUSTVect<int,_SIZE_>& vx, Mp_vect_options opt=VECT_ALL_ITEMS) = delete; // forbidden
575
576// Idem que tab_multiply_any_shape() mais avec une division
577template<typename _TYPE_, typename _SIZE_>
578inline void tab_divide_any_shape(TRUSTVect<_TYPE_,_SIZE_>& resu, const TRUSTVect<_TYPE_,_SIZE_>& vx, Mp_vect_options opt=VECT_ALL_ITEMS)
579{
580 if (vx.size_array() == 1 && !vx.get_md_vector().non_nul()) // division par une constante
581 {
582 if (vx[0] == 0) error_divide(__func__);
583 const _TYPE_ x = 1. / vx[0];
584 operator_multiply(resu, x, opt);
585 }
586 else if (vx.line_size() == resu.line_size()) // division membre a membre
587 operator_divide(resu, vx, opt);
588 else // Cas general
589 tab_divide_any_shape_(resu, vx, opt);
590}
591
592template<typename _SIZE_>
593inline void tab_divide_any_shape(TRUSTVect<int,_SIZE_>& resu, const TRUSTVect<int,_SIZE_>& vx, Mp_vect_options opt=VECT_ALL_ITEMS) = delete; // forbidden
594// FIN code pour operations speciales
595// ==================================================================================================================================
596
597#endif /* TRUSTVect_tools_TPP_included */
virtual trustIdType nb_items_seq_tot() const
: Cette classe est un OWN_PTR mais l'objet pointe est partage entre plusieurs
Definition MD_Vector.h:48
int non_nul() const
Definition MD_Vector.h:56
static double mp_min(double)
Definition Process.cpp:386
static double mp_max(double)
Definition Process.cpp:376
static double mp_sum(double)
Calcule la somme de x sur tous les processeurs du groupe courant.
Definition Process.cpp:146
static bool is_sequential()
Definition Process.cpp:115
Represents a an array of int/int64/double/... values.
Definition TRUSTArray.h:81
_SIZE_ size_array() const
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
int line_size() const
Definition TRUSTVect.tpp:67
virtual const MD_Vector & get_md_vector() const
Definition TRUSTVect.h:123
Block_Iter(const ArrOfInt &items_blocs)
Block_Iter(const Block_Iter &other)=default
Block_Iter(_SIZE_ s, _SIZE_ e)
Block_Iter & operator=(const Block_Iter &other)=default
bool empty() const
OBS_PTR(ArrOfInt) items_
Block_Iter(const ArrOfInt &items_blocs, const ArrOfInt &items)
const int * int_ptr
Block_Iter operator++(int)
Block_Iter()=default
_SIZE_ operator*() const