Changeset 418 for branches


Ignore:
Timestamp:
Mar 19, 2013 12:00:45 PM (5 years ago)
Author:
kulshres
Message:

New class advector for index lookup and subscripting

This is a container using std::vector<adouble>. The subscripting
operations return references to adoubles, nothing needs to be written
onto the tape for this since the following operation using the adouble
reference will do the right thing.
The index lookup operation uses a sequence of n condassign_s ops which
are taped, and returns the index which matches the requirement as another
adouble.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

Location:
branches/MPI/ADOL-C/src
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/MPI/ADOL-C/src/adouble.cpp

    r311 r418  
    13581358    /* y+0.0 is a hack since condassign is currently not defined for
    13591359       badoubles */
    1360     condassign( sy,  y+0.0,  1.0 , -1.0 );
    1361     condassign( a1,  x+0.0, (adouble) atan(y/x),
    1362                 (adouble)( atan(y/x)+sy*2*pihalf));
    1363     condassign( a2,  (adouble) fabs(y), (adouble) (sy*pihalf-atan(x/y)),
    1364                 (adouble) 0.0 );
    1365     condassign( ret, (adouble) (fabs(x) - fabs(y)), a1, a2 );
     1360    condassign( sy,  y,  (adouble)1.0 , (adouble)-1.0 );
     1361    condassign( a1,  x,  atan(y/x),  atan(y/x)+sy*2*pihalf);
     1362    condassign( a2,  fabs(y), sy*pihalf-atan(x/y), (adouble) 0.0 );
     1363    condassign( ret, fabs(x) - fabs(y), a1, a2 );
    13661364    return ret;
    13671365}
     
    14001398    }
    14011399
    1402     condassign (ret, coval, exp(y*ADOLC_MATH_NSP::log(coval)),
    1403             ADOLC_MATH_NSP::pow(coval,y.getValue()) );
     1400    condassign (ret, (adouble) coval, exp(y*ADOLC_MATH_NSP::log(coval)),
     1401                (adouble) ADOLC_MATH_NSP::pow(coval,y.getValue()) );
    14041402
    14051403    return ret;
     
    14191417            fprintf(DIAG_OUT,"\nADOL-C message: negative exponent and zero basis deactivated\n");
    14201418    }
    1421     condassign(a1,-y, ADOLC_MATH_NSP::pow(vx,vy), pow(x,vy));
    1422     condassign(a2, fabs(x), pow(x, vy),a1);
    1423     condassign(ret,x+0.0, exp(y*log(x)),a2);
     1419    condassign(a1, -y, (adouble) ADOLC_MATH_NSP::pow(vx,vy), pow(x,vy));
     1420    condassign(a2, fabs(x), pow(x, vy), a1);
     1421    condassign(ret, x, exp(y*log(x)),a2);
    14241422
    14251423    return ret;
     
    17771775
    17781776/*--------------------------------------------------------------------------*/
    1779 void condassign( adouble &res,        const adouble &cond,
    1780                  const adouble &arg1, const adouble &arg2 ) {
     1777void condassign( adouble &res,         const badouble &cond,
     1778                 const badouble &arg1, const badouble &arg2 ) {
    17811779    ADOLC_OPENMP_THREAD_NUMBER;
    17821780    ADOLC_OPENMP_GET_THREAD_NUMBER;
     
    18021800
    18031801/*--------------------------------------------------------------------------*/
    1804 void condassign( adouble &res, const adouble &cond, const adouble &arg ) {
     1802void condassign( adouble &res, const badouble &cond, const badouble &arg ) {
    18051803    ADOLC_OPENMP_THREAD_NUMBER;
    18061804    ADOLC_OPENMP_GET_THREAD_NUMBER;
  • branches/MPI/ADOL-C/src/adouble.h

    r327 r418  
    111111class adub;
    112112class badouble;
    113 class adubv;
    114 /* class doublev;  that's history */
    115113
    116114/*--------------------------------------------------------------------------*/
     
    138136*/
    139137class ADOLC_DLL_EXPORT badouble {
    140     friend ADOLC_DLL_EXPORT class badoublev;
     138    friend ADOLC_DLL_EXPORT class advector;
    141139protected:
    142140    locint location;
     
    146144    //
    147145    // badouble( const badouble& a ) {location = a.location;};
    148     badouble( locint lo ) {
     146    explicit badouble( locint lo ) {
    149147        location = lo;
    150148    };
     
    168166    badouble& operator = ( const adub& );
    169167    double getValue() const;
    170     inline double value() {
     168    inline double value() const {
    171169        return getValue();
    172170    }
     
    286284    /*--------------------------------------------------------------------------*/
    287285    /* Conditionals */
    288     friend ADOLC_DLL_EXPORT void condassign( adouble &res, const adouble &cond,
    289             const adouble &arg1, const adouble &arg2 );
    290     friend ADOLC_DLL_EXPORT void condassign( adouble &res, const adouble &cond,
    291             const adouble &arg );
     286    friend ADOLC_DLL_EXPORT void condassign( adouble &res, const badouble &cond,
     287            const badouble &arg1, const badouble &arg2 );
     288    friend ADOLC_DLL_EXPORT void condassign( adouble &res, const badouble &cond,
     289            const badouble &arg );
    292290};
    293291
     
    317315        exit(-2);
    318316    };
    319     adub( double ):badouble(0) {
     317    explicit adub( double ):badouble(0) {
    320318        fprintf(DIAG_OUT,"ADOL-C error: illegal  construction of adub variable"
    321319                " from double\n");
     
    402400*/
    403401class ADOLC_DLL_EXPORT adouble:public badouble {
     402    friend ADOLC_DLL_EXPORT class advector;
    404403public:
    405404    adouble( const adub& );
Note: See TracChangeset for help on using the changeset viewer.