aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
multiDimBijArray_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
50
52
53namespace gum {
54
55 template < typename GUM_SCALAR >
57 MultiDimWithOffset< GUM_SCALAR >(), _array_(from._array_), _name_(from._name_) {
58 GUM_CONS_CPY(MultiDimBijArray);
59
60 for (auto var: from.variablesSequence()) {
62 }
63 }
64
65 template < typename GUM_SCALAR >
67 const MultiDimArray< GUM_SCALAR >& array) :
68 MultiDimWithOffset< GUM_SCALAR >(), _array_(array), _name_("MultiDimBijArray") {
69 GUM_CONSTRUCTOR(MultiDimBijArray);
70
71 for (auto var: array.variablesSequence()) {
73 }
74 }
75
76 template < typename GUM_SCALAR >
78 const MultiDimBijArray< GUM_SCALAR >& array) :
79 MultiDimWithOffset< GUM_SCALAR >(), _array_(array._array_), _name_("MultiDimBijArray") {
80 GUM_CONSTRUCTOR(MultiDimBijArray);
81
82 for (auto var: array.variablesSequence()) {
84 }
85 }
86
87 template < typename GUM_SCALAR >
91
92 template < typename GUM_SCALAR >
97
98 template < typename GUM_SCALAR >
102
103 template < typename GUM_SCALAR >
104 INLINE const std::string& MultiDimBijArray< GUM_SCALAR >::name() const {
105 return _name_;
106 }
107
108 template < typename GUM_SCALAR >
110 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.")
111 }
112
113 template < typename GUM_SCALAR >
115 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.")
116 }
117
118 template < typename GUM_SCALAR >
120 return (Size)0;
121 }
122
123 template < typename GUM_SCALAR >
124 INLINE void MultiDimBijArray< GUM_SCALAR >::fill(const GUM_SCALAR& d) const {
125 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.")
126 }
127
128 template < typename GUM_SCALAR >
130 // Do nothing
131 }
132
133 template < typename GUM_SCALAR >
134 INLINE GUM_SCALAR MultiDimBijArray< GUM_SCALAR >::get(const Instantiation& i) const {
135 if (i.isMaster(this)) {
136 return _array_.values_[this->offsets_[&i]];
137 } else {
138 return _array_.values_[this->getOffs_(i)];
139 }
140 }
141
142 template < typename GUM_SCALAR >
144 const GUM_SCALAR& value) const {
145 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.")
146 }
147
148 template < typename GUM_SCALAR >
149 INLINE void MultiDimBijArray< GUM_SCALAR >::populate(const std::vector< GUM_SCALAR >& v) const {
150 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.")
151 }
152
153 template < typename GUM_SCALAR >
154 INLINE void
155 MultiDimBijArray< GUM_SCALAR >::populate(std::initializer_list< GUM_SCALAR > l) const {
156 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.")
157 }
158
159 template < typename GUM_SCALAR >
160 INLINE GUM_SCALAR& MultiDimBijArray< GUM_SCALAR >::get_(const Instantiation& i) const {
161 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.")
162 }
163
164 template < typename GUM_SCALAR >
169
170} // namespace gum
Base class for discrete random variable.
Class for assigning/browsing values to tuples of discrete variables.
bool isMaster(const MultiDimAdressable *m) const
Indicates whether m is the master of this instantiation.
Multidimensional matrix stored as an array in memory.
Decorator of a MultiDimArray, using a bijection over the variables.
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
virtual void populate(const std::vector< GUM_SCALAR > &v) const
This will raise an exception: you can't change the variables in a MultiDimBijArray.
MultiDimBijArray(const VarBijection &bijection, const MultiDimArray< GUM_SCALAR > &array)
Class constructor.
MultiDimBijArray< GUM_SCALAR > & operator=(const MultiDimBijArray< GUM_SCALAR > &from)
virtual GUM_SCALAR & get_(const Instantiation &i) const
Return a data, given a Instantiation.
virtual void replace_(const DiscreteVariable *x, const DiscreteVariable *y)
Replace variable x by y.
virtual const std::string & name() const
Returns the real name of the multiDim implementation.
std::string _name_
The class name.
virtual void commitMultipleChanges_()
Synchronize content after MultipleChanges.
Bijection< const DiscreteVariable *, const DiscreteVariable * > VarBijection
virtual MultiDimBijArray< GUM_SCALAR > * newFactory() const
Class constructor.
virtual GUM_SCALAR get(const Instantiation &i) const
Returns the value pointed by i.
const MultiDimArray< GUM_SCALAR > & _array_
The true data.
virtual Size realSize() const
Returns the real number of parameters used for this table.
virtual void erase(const DiscreteVariable &v)
This will raise an exception: you can't change the variables in a MultiDimBijArray.
virtual ~MultiDimBijArray()
Class destructor.
virtual void add(const DiscreteVariable &v)
This will raise an exception: you can't change the variables in a MultiDimBijArray.
virtual void fill(const GUM_SCALAR &d) const
This will raise an exception: you can't change the data.
virtual void replace_(const DiscreteVariable *x, const DiscreteVariable *y) override
Replace variable x by y.
virtual const Sequence< const DiscreteVariable * > & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
HashTable< const Instantiation *, Size > offsets_
The position in the array of each slave Instantiation.
MultiDimWithOffset()
Class constructor.
Size getOffs_(const Instantiation &i) const
Compute the offset of a Instantiation.
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
Exception : operation not allowed.
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Headers of the MultiDimBijArray class.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46