aGrUM 3.1.1
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-2026 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-2026 *
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
41#pragma once
42
43
51
53
54namespace gum {
55
56 template < typename GUM_ELEMENT >
65
66 template < typename GUM_ELEMENT >
68 const MultiDimArray< GUM_ELEMENT >& array) :
69 MultiDimWithOffset< GUM_ELEMENT >(), _array_(array), _name_("MultiDimBijArray") {
70 GUM_CONSTRUCTOR(MultiDimBijArray);
71
72 for (auto var: array.variablesSequence()) {
74 }
75 }
76
77 template < typename GUM_ELEMENT >
80 MultiDimWithOffset< GUM_ELEMENT >(), _array_(array._array_), _name_("MultiDimBijArray") {
81 GUM_CONSTRUCTOR(MultiDimBijArray);
82
83 for (auto var: array.variablesSequence()) {
85 }
86 }
87
88 template < typename GUM_ELEMENT >
92
93 template < typename GUM_ELEMENT >
98
99 template < typename GUM_ELEMENT >
103
104 template < typename GUM_ELEMENT >
105 const std::string& MultiDimBijArray< GUM_ELEMENT >::name() const {
106 return _name_;
107 }
108
109 template < typename GUM_ELEMENT >
111 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_ELEMENT> are read only.")
112 }
113
114 template < typename GUM_ELEMENT >
116 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_ELEMENT> are read only.")
117 }
118
119 template < typename GUM_ELEMENT >
123
124 template < typename GUM_ELEMENT >
125 void MultiDimBijArray< GUM_ELEMENT >::fill(const GUM_ELEMENT& d) const {
126 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_ELEMENT> are read only.")
127 }
128
129 template < typename GUM_ELEMENT >
133
134 template < typename GUM_ELEMENT >
136 if (i.isMaster(this)) {
137 return _array_.values_[this->offsets_[&i]];
138 } else {
139 return _array_.values_[this->getOffs_(i)];
140 }
141 }
142
143 template < typename GUM_ELEMENT >
145 const GUM_ELEMENT& value) const {
146 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_ELEMENT> are read only.")
147 }
148
149 template < typename GUM_ELEMENT >
150 void MultiDimBijArray< GUM_ELEMENT >::populate(const std::vector< GUM_ELEMENT >& v) const {
151 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_ELEMENT> are read only.")
152 }
153
154 template < typename GUM_ELEMENT >
155 void MultiDimBijArray< GUM_ELEMENT >::populate(std::initializer_list< GUM_ELEMENT > l) const {
156 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_ELEMENT> are read only.")
157 }
158
159 template < typename GUM_ELEMENT >
161 GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_ELEMENT> are read only.")
162 }
163
164 template < typename GUM_ELEMENT >
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.
GUM_ELEMENT & get_(const Instantiation &i) const override
Return a data, given a Instantiation.
void set(const Instantiation &i, const GUM_ELEMENT &value) const override
MultiDimBijArray< GUM_ELEMENT > * newFactory() const override
Class constructor.
const std::string & name() const override
Returns the real name of the multiDim implementation.
GUM_ELEMENT get(const Instantiation &i) const override
Returns the value pointed by i.
std::string _name_
The class name.
void add(const DiscreteVariable &v) override
This will raise an exception: you can't change the variables in a MultiDimBijArray.
void commitMultipleChanges_() override
Synchronize content after MultipleChanges.
Bijection< const DiscreteVariable *, const DiscreteVariable * > VarBijection
Size realSize() const override
Returns the real number of parameters used for this table.
const MultiDimArray< GUM_ELEMENT > & _array_
The true data.
MultiDimBijArray< GUM_ELEMENT > & operator=(const MultiDimBijArray< GUM_ELEMENT > &from)
~MultiDimBijArray() override
Class destructor.
MultiDimBijArray(const VarBijection &bijection, const MultiDimArray< GUM_ELEMENT > &array)
Class constructor.
void erase(const DiscreteVariable &v) override
This will raise an exception: you can't change the variables in a MultiDimBijArray.
void populate(const std::vector< GUM_ELEMENT > &v) const override
This will raise an exception: you can't change the variables in a MultiDimBijArray.
void replace_(const DiscreteVariable *x, const DiscreteVariable *y) override
This is called by MultiDimContainer::replace() to proceed with the replacing between x and y.
void fill(const GUM_ELEMENT &d) const override
This will raise an exception: you can't change the data.
const Sequence< const DiscreteVariable * > & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
void replace_(const DiscreteVariable *x, const DiscreteVariable *y) override
Replace variable x by y.
Size getOffs_(const Instantiation &i) const
Compute the offset of a Instantiation.
MultiDimWithOffset()
Class constructor.
HashTable< const Instantiation *, Size > offsets_
The position in the array of each slave Instantiation.
void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
Exception : operation not allowed.
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
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