queso-0.53.0
ConcatenationSubset.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2015 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/VectorSet.h>
26 #include <queso/VectorSpace.h>
27 #include <queso/ConcatenationSubset.h>
28 #include <queso/GslVector.h>
29 #include <queso/GslMatrix.h>
30 
31 namespace QUESO {
32 
33 // Default, shaped constructor
34 template<class V, class M>
36  const VectorSpace<V,M>& vectorSpace,
37  const VectorSet<V,M>& set1,
38  const VectorSet<V,M>& set2)
39  : VectorSubset<V,M>(prefix, vectorSpace, set1.volume()*set2.volume()),
40  m_sets(2, (const VectorSet<V,M>*) NULL)
41 {
42  m_sets[0] = &set1;
43  m_sets[1] = &set2;
44 }
45 
46 // Default, shaped constructor
47 template<class V, class M>
49  const VectorSpace<V,M>& vectorSpace,
50  double volume,
51  const std::vector<const VectorSet<V,M>* >& sets)
52  : VectorSubset<V,M>(prefix, vectorSpace, volume),
53  m_sets(sets.size(), (const VectorSet<V,M>*) NULL)
54 {
55  for (unsigned int i = 0; i < m_sets.size(); ++i) {
56  m_sets[i] = sets[i];
57  }
58 }
59 
60 // Destructor
61 template<class V, class M>
63 {
64 }
65 
66 // Mathematical methods
67 template<class V, class M>
68 bool ConcatenationSubset<V,M>::contains(const V& vec) const
69 {
70  bool result = true;
71 
72  std::vector<V*> vecs(m_sets.size(),(V*) NULL);
73  for (unsigned int i = 0; i < vecs.size(); ++i) {
74  vecs[i] = new V(m_sets[i]->vectorSpace().zeroVector());
75  }
76 
77  unsigned int cummulativeSize = 0;
78  for (unsigned int i = 0; i < vecs.size(); ++i) {
79  vec.cwExtract(cummulativeSize,*(vecs[i]));
80  cummulativeSize += vecs[i]->sizeLocal();
81  }
82 
83  queso_require_equal_to_msg(vec.sizeLocal(), cummulativeSize, "incompatible vector sizes");
84 
85  for (unsigned int i = 0; i < m_sets.size(); ++i) {
86  result = result && m_sets[i]->contains(*(vecs[i]));
87  }
88  for (unsigned int i = 0; i < vecs.size(); ++i) {
89  delete vecs[i];
90  }
91 
92  return (result);
93 }
94 
95 // I/O methods
96 template <class V, class M>
97 void ConcatenationSubset<V,M>::print(std::ostream& os) const
98 {
99  os << "In ConcatenationSubset<V,M>::print()"
100  << ": m_sets.size() = " << m_sets.size()
101  << std::endl;
102  for (unsigned int i = 0; i < m_sets.size(); ++i) {
103  os << "m_sets[" << i << "] = " << *(m_sets[i]);
104  if (i < (m_sets.size()-1)) {
105  os << ", ";
106  }
107  }
108  os << std::endl;
109 
110  return;
111 }
112 
113 } // End namespace QUESO
114 
std::vector< const VectorSet< V, M > * > m_sets
A templated class for handling sets.
Definition: VectorSet.h:52
A templated class representing the concatenation of two vector subsets.
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
ConcatenationSubset(const char *prefix, const VectorSpace< V, M > &vectorSpace, const VectorSet< V, M > &set1, const VectorSet< V, M > &set2)
Constructor - two sets only.
A templated class for handling subsets.
Definition: VectorSubset.h:46
void print(std::ostream &os) const
Prints the subsets (via protected attribute m_sets).
bool contains(const V &vec) const
Determines whether each one of the subsets m_sets (class&#39; private attributes) contains vector vec...
A class representing a vector space.
Definition: VectorSet.h:49

Generated on Thu Jun 11 2015 13:52:31 for queso-0.53.0 by  doxygen 1.8.5