casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SparseDiffRep.h
Go to the documentation of this file.
00001 //# SparseDiffRep.h: Representation of an automatic differential class data
00002 //# Copyright (C) 2007
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id: SparseDiffRep.h,v 1.1 2007/11/16 04:34:46 wbrouw Exp $
00028 
00029 #ifndef SCIMATH_SPARSEDIFFREP_H
00030 #define SCIMATH_SPARSEDIFFREP_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/vector.h>
00035 #include <utility>
00036 
00037 // Using
00038 using std::pair;
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042   //# Forward declarations
00043 
00044   // <summary>
00045   // Representation of data for the spare automatic differentiation calss.
00046   // </summary>
00047   //
00048   // <use visibility=local>
00049   //
00050   // <reviewed reviewer="UNKNOWN" date="" tests="tSparseDiff.cc" demos="">
00051   // </reviewed>
00052   //
00053   // <prerequisite>
00054   // <li> <linkto class=SparseDiff>SparseDiff</linkto>
00055   // </prerequisite>
00056   //
00057   // <etymology>
00058   // Class that represents partial derivatives obtained by automatic
00059   // differentiation.
00060   // </etymology>
00061   //
00062   // <synopsis>
00063   // Class representing
00064   // the data necessary for automatic differentiation. The structure contains a
00065   // value, and the derivatives of the value with respect to a number of 
00066   // dependent variables.
00067   //
00068   // The actual differentiation and access is done through the 
00069   // <linkto class=SparseDiff>SparseDiff</linkto> class.
00070   //
00071   // <example>
00072   // See the example in <linkto class=SparseDiff>SparseDiff</linkto>
00073   // </example>
00074   //
00075   // <motivation>
00076   // To separate the data container from the actual calculations.
00077   // To be able to create special conatiners; constructors and destructors
00078   // (including memory allocation) to speed up processes.
00079   //
00080   // <templating arg=T>
00081   //  <li> any class that has the standard mathematical and comparison
00082   //    operators defined
00083   // </templating>
00084   //
00085   // <todo asof="2007/11/27">
00086   // <li> Nothing I know of
00087   // </todo>
00088 
00089   template <class T> class SparseDiffRep {
00090   public:
00091     //# Typedefs
00092     typedef T                   value_type;
00093     typedef value_type&         reference;
00094     typedef const value_type&   const_reference;
00095     typedef value_type*         iterator;
00096     typedef const value_type*   const_iterator;
00097 
00098     //# Constructors
00099     // Construct a constant with a value of zero.  Zero derivatives.
00100     SparseDiffRep();
00101 
00102     //# Operators
00103     // Assignment operators
00104     // <group>
00105     SparseDiffRep<T> &operator=(const T &v);
00106     SparseDiffRep<T> &operator=(const vector<pair<uInt, T> > &grad);
00107     SparseDiffRep<T> &operator=(const SparseDiffRep<T> &other);
00108     void operator*=(const T other);
00109     void operator/=(const T other);
00110     void operator+=(const T other);
00111     void operator-=(const T other);
00112     // </group>
00113 
00114     //# Member functions
00115   
00116     // Clear for reuse
00117     void clear() { grad_p.clear(); }
00118 
00119     //# Data
00120     // The function value
00121     T val_p;
00122     // The derivatives
00123     vector<pair<uInt, T> > grad_p;
00124     // Link to indicate its status (1=linked in stack; 2=used in modules)
00125     uInt link_p;
00126   };
00127 
00128 
00129 } //# NAMESPACE CASA - END
00130 
00131 #ifndef CASACORE_NO_AUTO_TEMPLATES
00132 #include <scimath/Mathematics/SparseDiffRep.tcc>
00133 #endif //# CASACORE_NO_AUTO_TEMPLATES
00134 #endif