aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
multiDimSparse_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Implementation of MultiDimSparse.
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
27  */
28 
29 namespace gum {
30 
31  // Default constructor: creates an empty null dimensional matrix
32 
33  template < typename GUM_SCALAR >
34  MultiDimSparse< GUM_SCALAR >::MultiDimSparse(const GUM_SCALAR& default_value) :
35  MultiDimWithOffset< GUM_SCALAR >(), default_(default_value) {
36  // for debugging purposes
37  GUM_CONSTRUCTOR(MultiDimSparse);
38  }
39 
40  // copy constructor
41 
42  template < typename GUM_SCALAR >
44  const MultiDimSparse< GUM_SCALAR >& from) :
47  // for debugging purposes
49  }
50 
51  // destructor
52 
53  template < typename GUM_SCALAR >
55  // for debugging purposes
57  // no need to unregister all slaves as it will be done by MultiDimWithOffset
58  }
59 
60  // data access operator
61 
62  template < typename GUM_SCALAR >
65  Size key;
66 
67  if (i.isMaster(this)) {
68  key = this->offsets_[&i];
69  } else {
70  key = this->getOffs_(i);
71  }
72 
73  return params_.exists(key) ? params_[key] : default_;
74  }
75 
76  template < typename GUM_SCALAR >
78  const GUM_SCALAR& value) const {
79  Size key;
80 
81  if (i.isMaster(this)) {
82  key = this->offsets_[&i];
83  } else {
84  key = this->getOffs_(i);
85  }
86 
87  if (value == default_) {
88  params_.reset(key);
89  } else {
90  params_.set(key, value);
91  }
92  }
93 
94  // add a new dimension, needed for updating the offsets_ & gaps_
95 
96  template < typename GUM_SCALAR >
99  fill(default_);
100  }
101 
102  // removes a dimension, needed for updating the offsets_ & gaps_
103 
104  template < typename GUM_SCALAR >
107  fill(default_);
108  }
109 
110  // synchronise content after MultipleChanges
111  template < typename GUM_SCALAR >
113  fill(default_);
114  }
115 
116  // fill the array with the arg
117  template < typename GUM_SCALAR >
118  INLINE void MultiDimSparse< GUM_SCALAR >::fill(const GUM_SCALAR& d) const {
119  params_.clear();
120  default_ = d;
121  }
122 
123  template < typename GUM_SCALAR >
125  return params_.size();
126  }
127 
128  template < typename GUM_SCALAR >
131  return new MultiDimSparse< GUM_SCALAR >(default_);
132  }
133 
134  // returns the name of the implementation
135  template < typename GUM_SCALAR >
137  static const std::string str = "MultiDimSparse";
138  return str;
139  }
140 
141  template < typename GUM_SCALAR >
143  const DiscreteVariable* y) {
145  }
146 
147  template < typename GUM_SCALAR >
151  "Do not use this with the MultiDimSparse class.");
152  }
153 
154 } /* namespace gum */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669