SundanceIntVec.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #ifndef SUNDANCE_INTVEC_H
00032 #define SUNDANCE_INTVEC_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "Teuchos_Array.hpp"
00036 #include "PlayaPrintable.hpp"
00037 
00038 namespace Sundance
00039 {
00040 using Teuchos::Array;
00041 using Teuchos::tuple;
00042 
00043 /** 
00044  * An integer vector class for use in the generalized chain rule
00045  * of Constantine and Savits (1996). See the paper by CS for 
00046  * definitions of the various operations.
00047  */
00048 class IntVec : public Playa::Printable
00049 {
00050 public:
00051   /** */
00052   IntVec(){}
00053   /** */
00054   IntVec(const Array<int>& d) : data_(d) {}
00055   /** */
00056   IntVec(int n);
00057 
00058   /** */
00059   int size() const {return data_.size();}
00060 
00061   /** */
00062   int operator[](int i) const {return data_[i];}
00063 
00064   /** */
00065   int& operator[](int i) {return data_[i];}
00066 
00067   /** */
00068   IntVec operator+(const IntVec& other) const ;
00069 
00070   /** */
00071   IntVec operator*(int alpha) const ;
00072 
00073   /** Return the factorial of this vector, as defined by CS */
00074   int factorial() const ;
00075 
00076   /** */
00077   int pow(const IntVec& other) const ;
00078 
00079   /** Return the sum of elements in this vector */
00080   int abs() const ;
00081 
00082   /** Return the infinity norm of this vector */
00083   int norm() const ;
00084 
00085   /** */
00086   bool operator==(const IntVec& other) const ;
00087 
00088   /** */
00089   bool operator<(const IntVec& other) const ;
00090 
00091   /** */
00092   void print(std::ostream& os) const ;
00093 
00094   /** Get the length-M partitions of this vector. These are all 
00095    * list of exactly M vectors \f$ v_i\f$ such that
00096    * \f[ \sum_{i=1}^M v_i = this. \f]
00097    */
00098   void getPartitions(int M, Array<Array<IntVec> >& parts) const ;
00099 
00100 private:
00101   Array<int> data_;
00102 };
00103 
00104 
00105 
00106 /** \relates IntVec */
00107 inline IntVec operator*(int a, const IntVec& x)
00108 {
00109   return x * a;
00110 }
00111 
00112 /** \relates IntVec*/
00113 inline std::ostream& operator<<(std::ostream& os, const IntVec& v)
00114 {
00115   v.print(os);
00116   return os;
00117 }
00118 
00119 /** */
00120 inline IntVec intVec(int a)
00121 {
00122   Array<int> dat = tuple(a);
00123   return dat;
00124 }
00125 
00126 /** */
00127 inline IntVec intVec(int a, int b)
00128 {
00129   Array<int> dat = tuple(a, b);
00130   return dat;
00131 }
00132 
00133 /** */
00134 inline IntVec intVec(int a, int b, int c)
00135 {
00136   Array<int> dat = tuple(a, b, c);
00137   return dat;
00138 }
00139 
00140 /** */
00141 inline IntVec intVec(int a, int b, int c, int d)
00142 {
00143   Array<int> dat = tuple(a, b, c, d);
00144   return dat;
00145 }
00146 
00147 /** */
00148 inline IntVec intVec(int a, int b, int c, int d, int e)
00149 {
00150   Array<int> dat = tuple(a, b, c, d, e);
00151   return dat;
00152 }
00153 
00154 
00155 
00156 }
00157 
00158 
00159 
00160 
00161 #endif

Site Contact