| 
									
										
										
										
											2010-10-14 12:54:38 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation,  | 
					
						
							|  |  |  |  * Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  |  * All Rights Reserved | 
					
						
							|  |  |  |  * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |  * @file    VectorValues.h | 
					
						
							|  |  |  |  * @brief   Factor Graph Valuesuration | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |  * @author  Richard Roberts | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | #include <gtsam/base/Testable.h>
 | 
					
						
							|  |  |  | #include <gtsam/base/Vector.h>
 | 
					
						
							|  |  |  | #include <gtsam/base/types.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/foreach.hpp>
 | 
					
						
							|  |  |  | #include <boost/numeric/ublas/vector_proxy.hpp>
 | 
					
						
							|  |  |  | #include <boost/numeric/ublas/io.hpp>
 | 
					
						
							|  |  |  | #include <boost/shared_ptr.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | class VectorValues : public Testable<VectorValues> { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | protected: | 
					
						
							|  |  |  |   Vector values_; | 
					
						
							|  |  |  |   std::vector<size_t> varStarts_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |   template<class C> class _impl_iterator;  // Forward declaration of iterator implementation
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |   typedef boost::shared_ptr<VectorValues> shared_ptr; | 
					
						
							|  |  |  |   typedef _impl_iterator<VectorValues> iterator; | 
					
						
							|  |  |  |   typedef _impl_iterator<const VectorValues> const_iterator; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   typedef boost::numeric::ublas::vector_range<Vector> value_reference_type; | 
					
						
							|  |  |  |   typedef boost::numeric::ublas::vector_range<const Vector> const_value_reference_type; | 
					
						
							|  |  |  |   typedef boost::numeric::ublas::vector_range<Vector> mapped_type; | 
					
						
							|  |  |  |   typedef boost::numeric::ublas::vector_range<const Vector> const_mapped_type; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  /**
 | 
					
						
							|  |  |  | //   * Constructor requires an existing GaussianVariableIndex to get variable
 | 
					
						
							|  |  |  | //   * dimensions.
 | 
					
						
							|  |  |  | //   */
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | //  VectorValues(const GaussianVariableIndex& variableIndex);
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |    * Default constructor creates an empty VectorValues.  reserve(...) must be | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |    * called to allocate space before any values can be added.  This prevents | 
					
						
							|  |  |  |    * slow reallocation of space at runtime. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |   VectorValues() : varStarts_(1,0) {} | 
					
						
							| 
									
										
										
										
											2010-10-14 06:41:26 +08:00
										 |  |  |   VectorValues(const VectorValues &V) : values_(V.values_), varStarts_(V.varStarts_) {} | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** Construct from a container of variable dimensions (in variable order). */ | 
					
						
							|  |  |  |   template<class Container> | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |   VectorValues(const Container& dimensions); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-12 00:02:01 +08:00
										 |  |  |   /** Construct to hold nVars vectors of varDim dimension each. */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   VectorValues(Index nVars, size_t varDim); | 
					
						
							| 
									
										
										
										
											2010-10-12 00:02:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   /** Construct from a container of variable dimensions in variable order and
 | 
					
						
							|  |  |  |    * a combined Vector of all of the variables in order. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |   VectorValues(const std::vector<size_t>& dimensions, const Vector& values); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-14 04:43:58 +08:00
										 |  |  |   /** Named constructor to create a VectorValues that matches the structure of
 | 
					
						
							|  |  |  |    * the specified VectorValues, but do not initialize the new values. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   static VectorValues SameStructure(const VectorValues& otherValues); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   /** Element access */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   mapped_type operator[](Index variable); | 
					
						
							|  |  |  |   const_mapped_type operator[](Index variable) const; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** Number of elements */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   Index size() const { return varStarts_.size()-1; } | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** Total dimensionality used (could be smaller than what has been allocated
 | 
					
						
							|  |  |  |    * with reserve(...) ). | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   size_t dim() const { return varStarts_.back(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-14 06:41:26 +08:00
										 |  |  |   /* dot product */ | 
					
						
							|  |  |  |   double dot(const VectorValues& V) const { return gtsam::dot(this->values_, V.values_) ; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   /** Total dimensions capacity allocated */ | 
					
						
							|  |  |  |   size_t dimCapacity() const { return values_.size(); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Iterator access */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |   iterator begin() { return _impl_iterator<VectorValues>(*this, 0); } | 
					
						
							|  |  |  |   const_iterator begin() const { return _impl_iterator<const VectorValues>(*this, 0); } | 
					
						
							|  |  |  |   iterator end() { return _impl_iterator<VectorValues>(*this, varStarts_.size()-1); } | 
					
						
							|  |  |  |   const_iterator end() const { return _impl_iterator<const VectorValues>(*this, varStarts_.size()-1); } | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** Reserve space for a total number of variables and dimensionality */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   void reserve(Index nVars, size_t totalDims) { values_.resize(std::max(totalDims, values_.size())); varStarts_.reserve(nVars+1); } | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Append a variable using the next variable ID, and return that ID.  Space | 
					
						
							|  |  |  |    * must have been allocated ahead of time using reserve(...). | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   Index push_back_preallocated(const Vector& vector) { | 
					
						
							|  |  |  |     Index var = varStarts_.size()-1; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     varStarts_.push_back(varStarts_.back()+vector.size()); | 
					
						
							|  |  |  |     this->operator[](var) = vector;  // This will assert that values_ has enough allocated space.
 | 
					
						
							|  |  |  |     return var; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Set all elements to zero */ | 
					
						
							|  |  |  |   void makeZero() { boost::numeric::ublas::noalias(values_) = boost::numeric::ublas::zero_vector<double>(values_.size()); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** print required by Testable for unit testing */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |   void print(const std::string& str = "VectorValues: ") const { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     std::cout << str << ": " << varStarts_.size()-1 << " elements\n"; | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |     for(Index var=0; var<size(); ++var) { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       std::cout << "  " << var << " " << operator[](var) << "\n"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     std::cout.flush(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** equals required by Testable for unit testing */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |   bool equals(const VectorValues& expected, double tol=1e-9) const { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     if(size() != expected.size()) return false; | 
					
						
							|  |  |  |     // iterate over all elements
 | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |     for(Index var=0; var<size(); ++var) | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       if(!equal_with_abs_tol(expected[var],operator[](var),tol)) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** + operator simply adds Vectors.  This checks for structural equivalence
 | 
					
						
							|  |  |  |    * when NDEBUG is not defined. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |   VectorValues operator+(const VectorValues& c) const { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     assert(varStarts_ == c.varStarts_); | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |     VectorValues result; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     result.varStarts_ = varStarts_; | 
					
						
							|  |  |  |     result.values_ = boost::numeric::ublas::project(values_, boost::numeric::ublas::range(0, varStarts_.back())) + | 
					
						
							| 
									
										
										
										
											2010-10-15 00:08:16 +08:00
										 |  |  |     				 boost::numeric::ublas::project(c.values_, boost::numeric::ublas::range(0, c.varStarts_.back())); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     return result; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-15 00:08:16 +08:00
										 |  |  |   void operator+=(const VectorValues& c) { | 
					
						
							|  |  |  |     assert(varStarts_ == c.varStarts_); | 
					
						
							|  |  |  |     this->values_ = boost::numeric::ublas::project(this->values_, boost::numeric::ublas::range(0, varStarts_.back())) + | 
					
						
							|  |  |  |     				boost::numeric::ublas::project(c.values_, boost::numeric::ublas::range(0, c.varStarts_.back())); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * Iterator (handles both iterator and const_iterator depending on whether | 
					
						
							|  |  |  |    * the template type is const. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   template<class C> | 
					
						
							|  |  |  |   class _impl_iterator { | 
					
						
							|  |  |  |   protected: | 
					
						
							|  |  |  |     C& config_; | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |     Index curVariable_; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |     _impl_iterator(C& config, Index curVariable) : config_(config), curVariable_(curVariable) {} | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     void checkCompat(const _impl_iterator<C>& r) { assert(&config_ == &r.config_); } | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |     friend class VectorValues; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   public: | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |     typedef typename const_selector<C, VectorValues, VectorValues::mapped_type, VectorValues::const_mapped_type>::type value_type; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     _impl_iterator<C>& operator++() { ++curVariable_; return *this; } | 
					
						
							|  |  |  |     _impl_iterator<C>& operator--() { --curVariable_; return *this; } | 
					
						
							|  |  |  |     _impl_iterator<C>& operator++(int) { throw std::runtime_error("Use prefix ++ operator"); } | 
					
						
							|  |  |  |     _impl_iterator<C>& operator--(int) { throw std::runtime_error("Use prefix -- operator"); } | 
					
						
							|  |  |  |     _impl_iterator<C>& operator+=(ptrdiff_t step) { curVariable_ += step; return *this; } | 
					
						
							|  |  |  |     _impl_iterator<C>& operator-=(ptrdiff_t step) { curVariable_ += step; return *this; } | 
					
						
							|  |  |  |     ptrdiff_t operator-(const _impl_iterator<C>& r) { checkCompat(r); return curVariable_ - r.curVariable_; } | 
					
						
							|  |  |  |     bool operator==(const _impl_iterator<C>& r) { checkCompat(r); return curVariable_ == r.curVariable_; } | 
					
						
							|  |  |  |     bool operator!=(const _impl_iterator<C>& r) { checkCompat(r); return curVariable_ != r.curVariable_; } | 
					
						
							|  |  |  |     value_type operator*() { return config_[curVariable_]; } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-15 00:08:16 +08:00
										 |  |  |   static VectorValues zero(const VectorValues& x) { | 
					
						
							|  |  |  |   	VectorValues cloned(x); | 
					
						
							|  |  |  |   	cloned.makeZero(); | 
					
						
							|  |  |  |   	return cloned; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   void checkVariable(Index variable) const { assert(variable < varStarts_.size()-1); } | 
					
						
							| 
									
										
										
										
											2010-10-14 06:41:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2010-10-15 00:08:16 +08:00
										 |  |  |   friend size_t dim(const VectorValues& V) { return V.varStarts_.back(); } | 
					
						
							| 
									
										
										
										
											2010-10-14 06:41:26 +08:00
										 |  |  |   friend double dot(const VectorValues& V1, const VectorValues& V2) { return gtsam::dot(V1.values_, V2.values_) ; } | 
					
						
							|  |  |  |   friend void scal(double alpha, VectorValues& x) {	gtsam::scal(alpha, x.values_) ; } | 
					
						
							|  |  |  |   friend void axpy(double alpha, const VectorValues& x, VectorValues& y) { gtsam::axpy(alpha, x.values_, y.values_) ; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | //inline VectorValues::VectorValues(const GaussianVariableIndex& variableIndex) : varStarts_(variableIndex.size()+1) {
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | //  size_t varStart = 0;
 | 
					
						
							|  |  |  | //  varStarts_[0] = 0;
 | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  | //  for(Index var=0; var<variableIndex.size(); ++var) {
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | //    varStart += variableIndex.dim(var);
 | 
					
						
							|  |  |  | //    varStarts_[var+1] = varStart;
 | 
					
						
							|  |  |  | //  }
 | 
					
						
							|  |  |  | //  values_.resize(varStarts_.back(), false);
 | 
					
						
							|  |  |  | //}
 | 
					
						
							| 
									
										
										
										
											2009-12-12 05:38:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | template<class Container> | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | inline VectorValues::VectorValues(const Container& dimensions) : varStarts_(dimensions.size()+1) { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   varStarts_[0] = 0; | 
					
						
							|  |  |  |   size_t varStart = 0; | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   Index var = 0; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   BOOST_FOREACH(size_t dim, dimensions) { | 
					
						
							|  |  |  |     varStarts_[++var] = (varStart += dim); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   values_.resize(varStarts_.back(), false); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-01-30 12:01:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  | inline VectorValues::VectorValues(Index nVars, size_t varDim) : varStarts_(nVars+1) { | 
					
						
							| 
									
										
										
										
											2010-10-12 00:02:01 +08:00
										 |  |  |   varStarts_[0] = 0; | 
					
						
							|  |  |  |   size_t varStart = 0; | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   for(Index j=1; j<=nVars; ++j) | 
					
						
							| 
									
										
										
										
											2010-10-12 00:02:01 +08:00
										 |  |  |     varStarts_[j] = (varStart += varDim); | 
					
						
							|  |  |  |   values_.resize(varStarts_.back(), false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | inline VectorValues::VectorValues(const std::vector<size_t>& dimensions, const Vector& values) : | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     values_(values), varStarts_(dimensions.size()+1) { | 
					
						
							|  |  |  |   varStarts_[0] = 0; | 
					
						
							|  |  |  |   size_t varStart = 0; | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   Index var = 0; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   BOOST_FOREACH(size_t dim, dimensions) { | 
					
						
							|  |  |  |     varStarts_[++var] = (varStart += dim); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   assert(varStarts_.back() == values.size()); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-01-30 10:04:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-14 04:43:58 +08:00
										 |  |  | inline VectorValues VectorValues::SameStructure(const VectorValues& otherValues) { | 
					
						
							|  |  |  |   VectorValues ret; | 
					
						
							|  |  |  |   ret.varStarts_ = otherValues.varStarts_; | 
					
						
							|  |  |  |   ret.values_.resize(ret.varStarts_.back(), false); | 
					
						
							|  |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  | inline VectorValues::mapped_type VectorValues::operator[](Index variable) { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   checkVariable(variable); | 
					
						
							|  |  |  |   return boost::numeric::ublas::project(values_, | 
					
						
							|  |  |  |       boost::numeric::ublas::range(varStarts_[variable], varStarts_[variable+1])); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-12-28 20:37:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  | inline VectorValues::const_mapped_type VectorValues::operator[](Index variable) const { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   checkVariable(variable); | 
					
						
							|  |  |  |   return boost::numeric::ublas::project(values_, | 
					
						
							|  |  |  |       boost::numeric::ublas::range(varStarts_[variable], varStarts_[variable+1])); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-01-16 13:08:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-11 16:32:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | } |