aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
operators4MultiDim_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40#pragma once
41
42
49
50#ifndef DOXYGEN_SHOULD_SKIP_THIS
51
52// allow operatorsPatterns to be used
53# define GUM_OPERATOR_PATTERN_ALLOWED 1
54
56
57// ==========================================================================
58// MultiDimArrays functions
59// ==========================================================================
60
61// a specialized function for summing two multiDimArrays
62
63// addition taking in argument 2 multiDimArrays
64# define GUM_MULTI_DIM_OPERATOR_NAME add2MultiDimArrays
65# define GUM_MULTI_DIM_OPERATOR(x, y) (x) + (y)
67# undef GUM_MULTI_DIM_OPERATOR_NAME
68# undef GUM_MULTI_DIM_OPERATOR
69
70# define GUM_MULTI_DIM_OPERATOR_IMPL2ARRAY_NAME add2MultiDimArrays
71# define GUM_MULTI_DIM_OPERATOR(x, y) (x) + (y)
73# undef GUM_MULTI_DIM_OPERATOR_IMPL2ARRAY_NAME
74# undef GUM_MULTI_DIM_OPERATOR
75
76# define GUM_MULTI_DIM_OPERATOR_POINTER_NAME add2MultiDimArrays4Pointers
77# define GUM_MULTI_DIM_OPERATOR(x, y) new T((*x) + (*y))
79# undef GUM_MULTI_DIM_OPERATOR_POINTER_NAME
80# undef GUM_MULTI_DIM_OPERATOR
81
82# define GUM_MULTI_DIM_OPERATOR_POINTER_IMPL2ARRAY_NAME add2MultiDimArrays4Pointers
83# define GUM_MULTI_DIM_OPERATOR(x, y) new T((*x) + (*y))
85# undef GUM_MULTI_DIM_OPERATOR_POINTER_IMPL2ARRAY_NAME
86# undef GUM_MULTI_DIM_OPERATOR
87
88// a specialized function for subtracting two multiDimArrays
89
90# define GUM_MULTI_DIM_OPERATOR_NAME subtract2MultiDimArrays
91# define GUM_MULTI_DIM_OPERATOR(x, y) (x) - (y)
93# undef GUM_MULTI_DIM_OPERATOR_NAME
94# undef GUM_MULTI_DIM_OPERATOR
95
96# define GUM_MULTI_DIM_OPERATOR_IMPL2ARRAY_NAME subtract2MultiDimArrays
97# define GUM_MULTI_DIM_OPERATOR(x, y) (x) - (y)
99# undef GUM_MULTI_DIM_OPERATOR_IMPL2ARRAY_NAME
100# undef GUM_MULTI_DIM_OPERATOR
101
102# define GUM_MULTI_DIM_OPERATOR_POINTER_NAME subtract2MultiDimArrays4Pointers
103# define GUM_MULTI_DIM_OPERATOR(x, y) new T((*x) - (*y))
105# undef GUM_MULTI_DIM_OPERATOR_POINTER_NAME
106# undef GUM_MULTI_DIM_OPERATOR
107
108# define GUM_MULTI_DIM_OPERATOR_POINTER_IMPL2ARRAY_NAME subtract2MultiDimArrays4Pointers
109# define GUM_MULTI_DIM_OPERATOR(x, y) new T((*x) - (*y))
111# undef GUM_MULTI_DIM_OPERATOR_POINTER_IMPL2ARRAY_NAME
112# undef GUM_MULTI_DIM_OPERATOR
113
114// a specialized function for multiplying two multiDimArrays
115
116# define GUM_MULTI_DIM_OPERATOR_NAME multiply2MultiDimArrays
117# define GUM_MULTI_DIM_OPERATOR(x, y) (x) * (y)
119# undef GUM_MULTI_DIM_OPERATOR_NAME
120# undef GUM_MULTI_DIM_OPERATOR
121
122# define GUM_MULTI_DIM_OPERATOR_IMPL2ARRAY_NAME multiply2MultiDimArrays
123# define GUM_MULTI_DIM_OPERATOR(x, y) (x) * (y)
125# undef GUM_MULTI_DIM_OPERATOR_IMPL2ARRAY_NAME
126# undef GUM_MULTI_DIM_OPERATOR
127
128# define GUM_MULTI_DIM_OPERATOR_POINTER_NAME multiply2MultiDimArrays4Pointers
129# define GUM_MULTI_DIM_OPERATOR(x, y) new T((*x) * (*y))
131# undef GUM_MULTI_DIM_OPERATOR_POINTER_NAME
132# undef GUM_MULTI_DIM_OPERATOR
133
134# define GUM_MULTI_DIM_OPERATOR_POINTER_IMPL2ARRAY_NAME multiply2MultiDimArrays4Pointers
135# define GUM_MULTI_DIM_OPERATOR(x, y) new T((*x) * (*y))
137# undef GUM_MULTI_DIM_OPERATOR_POINTER_IMPL2ARRAY_NAME
138# undef GUM_MULTI_DIM_OPERATOR
139
140// a specialized function for dividing two multiDimArrays
141
142# define GUM_MULTI_DIM_OPERATOR_NAME divide2MultiDimArrays
143# define GUM_MULTI_DIM_OPERATOR(x, y) (x) / (y)
145# undef GUM_MULTI_DIM_OPERATOR_NAME
146# undef GUM_MULTI_DIM_OPERATOR
147
148# define GUM_MULTI_DIM_OPERATOR_IMPL2ARRAY_NAME divide2MultiDimArrays
149# define GUM_MULTI_DIM_OPERATOR(x, y) (x) / (y)
151# undef GUM_MULTI_DIM_OPERATOR_IMPL2ARRAY_NAME
152# undef GUM_MULTI_DIM_OPERATOR
153
154# define GUM_MULTI_DIM_OPERATOR_POINTER_NAME divide2MultiDimArrays4Pointers
155# define GUM_MULTI_DIM_OPERATOR(x, y) new T((*x) / (*y))
157# undef GUM_MULTI_DIM_OPERATOR_POINTER_NAME
158# undef GUM_MULTI_DIM_OPERATOR
159
160# define GUM_MULTI_DIM_OPERATOR_POINTER_IMPL2ARRAY_NAME divide2MultiDimArrays4Pointers
161# define GUM_MULTI_DIM_OPERATOR(x, y) new T((*x) / (*y))
163# undef GUM_MULTI_DIM_OPERATOR_POINTER_IMPL2ARRAY_NAME
164# undef GUM_MULTI_DIM_OPERATOR
165
166// ==========================================================================
167// MultiDimFunctionGraphs functions
168// ==========================================================================
169
170// ///////////////////////////////////////////////////////
171// a specialized function for summing two multiDimFunctionGraphs
172// ///////////////////////////////////////////////////////
173
174# define GUM_MULTI_DIM_OPERATOR std::plus
175
176# define GUM_MULTI_DIM_OPERATOR_NAME add2MultiDimFunctionGraphs
178# undef GUM_MULTI_DIM_OPERATOR_NAME
179
180# define GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME add2MultiDimFunctionGraphs
182# undef GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME
183
184# undef GUM_MULTI_DIM_OPERATOR
185
186// ///////////////////////////////////////////////////////
187// a specialized function for subtracting two multiDimFunctionGraphs
188// ///////////////////////////////////////////////////////
189
190# define GUM_MULTI_DIM_OPERATOR std::minus
191
192# define GUM_MULTI_DIM_OPERATOR_NAME subtract2MultiDimFunctionGraphs
194# undef GUM_MULTI_DIM_OPERATOR_NAME
195
196# define GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME subtract2MultiDimFunctionGraphs
198# undef GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME
199
200# undef GUM_MULTI_DIM_OPERATOR
201
202// ///////////////////////////////////////////////////////
203// a specialized function for multiplying two multiDimFunctionGraphs
204// ///////////////////////////////////////////////////////
205
206# define GUM_MULTI_DIM_OPERATOR std::multiplies
207
208# define GUM_MULTI_DIM_OPERATOR_NAME multiply2MultiDimFunctionGraphs
210# undef GUM_MULTI_DIM_OPERATOR_NAME
211
212# define GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME multiply2MultiDimFunctionGraphs
214# undef GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME
215
216# undef GUM_MULTI_DIM_OPERATOR
217
218// ///////////////////////////////////////////////////////
219// a specialized function for dividing two multiDimFunctionGraphs
220// ///////////////////////////////////////////////////////
221
222# define GUM_MULTI_DIM_OPERATOR std::divides
223
224# define GUM_MULTI_DIM_OPERATOR_NAME divide2MultiDimFunctionGraphs
226# undef GUM_MULTI_DIM_OPERATOR_NAME
227
228# define GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME divide2MultiDimFunctionGraphs
230# undef GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME
231
232# undef GUM_MULTI_DIM_OPERATOR
233
234// ///////////////////////////////////////////////////////
235// a specialized function for finding max of two multiDimFunctionGraphs
236// ///////////////////////////////////////////////////////
237
238# define GUM_MULTI_DIM_OPERATOR Maximizes
239
240# define GUM_MULTI_DIM_OPERATOR_NAME maximize2MultiDimFunctionGraphs
242# undef GUM_MULTI_DIM_OPERATOR_NAME
243
244# define GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME maximize2MultiDimFunctionGraphs
246# undef GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME
247
248# undef GUM_MULTI_DIM_OPERATOR
249
250// ///////////////////////////////////////////////////////
251// a specialized function for finding min of two multiDimFunctionGraphs
252// ///////////////////////////////////////////////////////
253
254# define GUM_MULTI_DIM_OPERATOR Minimizes
255
256# define GUM_MULTI_DIM_OPERATOR_NAME minimize2MultiDimFunctionGraphs
258# undef GUM_MULTI_DIM_OPERATOR_NAME
259
260# define GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME minimize2MultiDimFunctionGraphs
262# undef GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME
263
264# undef GUM_MULTI_DIM_OPERATOR
265
266// a specialized function for functionally combining two multiDimArrays
267
268# define GUM_MULTI_DIM_OPERATOR_NAME_F combine2MultiDimArrays
269# define GUM_MULTI_DIM_OPERATOR(x, y) f((x), (y))
271# undef GUM_MULTI_DIM_OPERATOR_NAME_F
272# undef GUM_MULTI_DIM_OPERATOR
273
274// the operators that should be used to select appropriately the functions
275// to combine multiDims
276
277// the function to be used to add two MultiDimImplementations
278# define GUM_MULTI_DIM_OPERATOR_NAME operator+
279# define GUM_MULTI_DIM_OPERATOR_FUNC_NAME "+"
280# define GUM_MULTI_DIM_SYMMETRIC_OPERATOR
282# undef GUM_MULTI_DIM_OPERATOR_NAME
283# undef GUM_MULTI_DIM_OPERATOR_FUNC_NAME
284# undef GUM_MULTI_DIM_SYMMETRIC_OPERATOR
285
286// the function to be used to multiply two MultiDimImplementations
287# define GUM_MULTI_DIM_OPERATOR_NAME operator*
288# define GUM_MULTI_DIM_OPERATOR_FUNC_NAME "*"
289# define GUM_MULTI_DIM_SYMMETRIC_OPERATOR
291# undef GUM_MULTI_DIM_OPERATOR_NAME
292# undef GUM_MULTI_DIM_OPERATOR_FUNC_NAME
293# undef GUM_MULTI_DIM_SYMMETRIC_OPERATOR
294
295// the function to be used to subtract two MultiDimImplementations
296# define GUM_MULTI_DIM_OPERATOR_NAME operator-
297# define GUM_MULTI_DIM_OPERATOR_FUNC_NAME "-"
299# undef GUM_MULTI_DIM_OPERATOR_NAME
300# undef GUM_MULTI_DIM_OPERATOR_FUNC_NAME
301
302// the function to be used to divide two MultiDimImplementations
303# define GUM_MULTI_DIM_OPERATOR_NAME operator/
304# define GUM_MULTI_DIM_OPERATOR_FUNC_NAME "/"
306# undef GUM_MULTI_DIM_OPERATOR_NAME
307# undef GUM_MULTI_DIM_OPERATOR_FUNC_NAME
308
309// default "basename" functions for combining two MultiDimImplementations
310
311# define GUM_MULTI_DIM_OPERATOR_NAME add2MultiDimImplementations
312# define GUM_MULTI_DIM_OPERATOR(x, y) (x) + (y)
314# undef GUM_MULTI_DIM_OPERATOR_NAME
315# undef GUM_MULTI_DIM_OPERATOR
316
317# define GUM_MULTI_DIM_OPERATOR_NAME subtract2MultiDimImplementations
318# define GUM_MULTI_DIM_OPERATOR(x, y) (x) - (y)
320# undef GUM_MULTI_DIM_OPERATOR_NAME
321# undef GUM_MULTI_DIM_OPERATOR
322
323# define GUM_MULTI_DIM_OPERATOR_NAME multiply2MultiDimImplementations
324# define GUM_MULTI_DIM_OPERATOR(x, y) (x) * (y)
326# undef GUM_MULTI_DIM_OPERATOR_NAME
327# undef GUM_MULTI_DIM_OPERATOR
328
329# define GUM_MULTI_DIM_OPERATOR_NAME divide2MultiDimImplementations
330# define GUM_MULTI_DIM_OPERATOR(x, y) (x) / (y)
332# undef GUM_MULTI_DIM_OPERATOR_NAME
333# undef GUM_MULTI_DIM_OPERATOR
334
335//
336// DO NOT FORGET TO REGISTER YOUR BINARY FUNCTIONS
337//
338
339namespace gum {
340
341 // the function used to register all the above functions
342 template < typename GUM_SCALAR >
344 // ensure that only one thread will register the projections
345 static std::once_flag first;
346 std::call_once(first, []() {
347 std::string MultiDimArrayString("MultiDimArray");
348 std::string MultiDimFunctionGraphString("MultiDimFunctionGraph");
349 std::string BaseNameString("MultiDimImplementation");
350
351 // register base functions for multiDimArrays
353 MultiDimArrayString,
354 MultiDimArrayString,
357 MultiDimArrayString,
358 MultiDimArrayString,
361 MultiDimArrayString,
362 MultiDimArrayString,
365 MultiDimArrayString,
366 MultiDimArrayString,
368
369 // register base functions for multiDimFunctionGraphs
371 MultiDimFunctionGraphString,
372 MultiDimFunctionGraphString,
375 MultiDimFunctionGraphString,
376 MultiDimFunctionGraphString,
379 MultiDimFunctionGraphString,
380 MultiDimFunctionGraphString,
383 MultiDimFunctionGraphString,
384 MultiDimFunctionGraphString,
386
387 // register default basename functions
389 BaseNameString,
390 BaseNameString,
391 &add2MultiDimImplementations);
393 BaseNameString,
394 BaseNameString,
395 &subtract2MultiDimImplementations);
397 BaseNameString,
398 BaseNameString,
399 &multiply2MultiDimImplementations);
401 BaseNameString,
402 BaseNameString,
403 &divide2MultiDimImplementations);
404 });
405 }
406
407 // the function used to register all the above functions
408 template < typename GUM_SCALAR >
410 // ensure that only one thread will register the projections
411 static std::once_flag first;
412 std::call_once(first, []() {
413 std::string MultiDimArrayString("MultiDimArray");
414 std::string BaseNameString("MultiDimImplementation");
415
416 // register base functions for multiDimArrays
418 MultiDimArrayString,
419 MultiDimArrayString,
422 MultiDimArrayString,
423 MultiDimArrayString,
426 MultiDimArrayString,
427 MultiDimArrayString,
430 MultiDimArrayString,
431 MultiDimArrayString,
433 });
434 }
435
436} /* namespace gum */
437
438// remove permission to use operatorsPatterns
439# undef GUM_OPERATOR_PATTERN_ALLOWED
440
441#endif /* DOXYGEN_SHOULD_SKIP_THIS */
void operators4MultiDimInit()
the function used to register all the operators on multidimImplementations over non-pointers types.
MultiDimArray< T * > * multiply2MultiDimArrays4Pointers(const MultiDimArray< T * > *t1, const MultiDimArray< T * > *t2)
a specialized function for multiplying two multiDimArrays
MultiDimArray< T > * subtract2MultiDimArrays(const MultiDimArray< T > *t1, const MultiDimArray< T > *t2)
a specialized function for subtracting two multiDimArrays
MultiDimArray< T > * divide2MultiDimArrays(const MultiDimArray< T > *t1, const MultiDimArray< T > *t2)
a specialized function for dividing two multiDimArrays
void pointerOperators4MultiDimInit()
the function used to register all the operators on multidimImplementations over pointers types.
MultiDimFunctionGraph< T > * divide2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for dividing two multiDimArrays
MultiDimArray< T * > * divide2MultiDimArrays4Pointers(const MultiDimArray< T * > *t1, const MultiDimArray< T * > *t2)
a specialized function for dividing two multiDimArrays
MultiDimArray< T > * add2MultiDimArrays(const MultiDimArray< T > *t1, const MultiDimArray< T > *t2)
a specialized function for summing two multiDimArrays
MultiDimArray< T * > * subtract2MultiDimArrays4Pointers(const MultiDimArray< T * > *t1, const MultiDimArray< T * > *t2)
a specialized function for subtracting two multiDimArrays
MultiDimFunctionGraph< T > * multiply2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for multiplying two multiDimArrays
MultiDimFunctionGraph< T > * subtract2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for subtracting two multiDimArrays
MultiDimArray< T * > * add2MultiDimArrays4Pointers(const MultiDimArray< T * > *t1, const MultiDimArray< T * > *t2)
a specialized function for summing two multiDimArrays
MultiDimArray< T > * multiply2MultiDimArrays(const MultiDimArray< T > *t1, const MultiDimArray< T > *t2)
a specialized function for multiplying two multiDimArrays
MultiDimFunctionGraph< T > * add2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for summing two multiDimArrays
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
void registerOperator(const std::string &operation_name, const std::string &type1, const std::string &type2, typename OperatorRegister4MultiDim< GUM_SCALAR >::OperatorPtr function)
A function to more easily register new operators in MultiDims.
the pattern used by all "basename" binary operators
the pattern used by all binary MultiDimArrays operators
the pattern used by all binary MultiDimFunctionGraphs operators
the pattern used by all binary MultiDimImplementations operators
A container for registering binary functions on multiDimImplementations.