Changeset 360


Ignore:
Timestamp:
Oct 19, 2012 5:22:43 AM (7 years ago)
Author:
kulshres
Message:

implement traced logical operators for condassign and advector

this will help to handle code branching as long as condassign or
advector based generalized conditional assignment is used.

These operators are only used if both operands are badoubles. If the
old behaviour is required then at least one of the two operands must
be a double.

For if-then-else branches the old behaviour should continue and we can do
nothing.

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

Location:
trunk/ADOL-C
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/ADOL-C/include/adolc/adouble.h

    r354 r360  
    136136    /*--------------------------------------------------------------------------*/
    137137    /* Comparison (friends) */
    138     inline friend int operator != ( const badouble&, const badouble& );
     138    friend ADOLC_DLL_EXPORT adub operator != ( const badouble&, const badouble& );
     139    //inline friend int operator != ( const badouble&, const badouble& );
    139140    inline friend int operator != ( double, const badouble& );
    140141    friend ADOLC_DLL_EXPORT int operator != ( const badouble&, double );
    141     inline friend int operator == ( const badouble&, const badouble& );
     142    friend ADOLC_DLL_EXPORT adub operator == ( const badouble&, const badouble& );
     143    //inline friend int operator == ( const badouble&, const badouble& );
    142144    inline friend int operator == ( double, const badouble& );
    143145    friend ADOLC_DLL_EXPORT int operator == ( const badouble&, double );
    144     inline friend int operator <= ( const badouble&, const badouble& );
     146    friend ADOLC_DLL_EXPORT adub operator <= ( const badouble&, const badouble& );
     147    //inline friend int operator <= ( const badouble&, const badouble& );
    145148    inline friend int operator <= ( double, const badouble& );
    146149    friend ADOLC_DLL_EXPORT int operator <= ( const badouble&, double );
    147     inline friend int operator >= ( const badouble&, const badouble& );
     150    friend ADOLC_DLL_EXPORT adub operator >= ( const badouble&, const badouble& );
     151    //inline friend int operator >= ( const badouble&, const badouble& );
    148152    inline friend int operator >= ( double, const badouble& );
    149153    friend ADOLC_DLL_EXPORT int operator >= ( const badouble&, double );
    150     inline friend int operator >  ( const badouble&, const badouble& );
     154    friend ADOLC_DLL_EXPORT adub operator >  ( const badouble&, const badouble& );
     155    //inline friend int operator >  ( const badouble&, const badouble& );
    151156    inline friend int operator >  ( double, const badouble& );
    152157    friend ADOLC_DLL_EXPORT int operator >  ( const badouble&, double );
    153     inline friend int operator <  ( const badouble&, const badouble& );
     158    friend ADOLC_DLL_EXPORT adub operator <  ( const badouble&, const badouble& );
     159    //inline friend int operator <  ( const badouble&, const badouble& );
    154160    inline friend int operator <  ( double, const badouble& );
    155161    friend ADOLC_DLL_EXPORT int operator <  ( const badouble&, double );
     
    269275public:
    270276
     277    /*--------------------------------------------------------------------------*/
     278    /* Comparison (friends) */
     279    friend ADOLC_DLL_EXPORT adub operator != ( const badouble&, const badouble& );
     280    friend ADOLC_DLL_EXPORT adub operator == ( const badouble&, const badouble& );
     281    friend ADOLC_DLL_EXPORT adub operator <= ( const badouble&, const badouble& );
     282    friend ADOLC_DLL_EXPORT adub operator >= ( const badouble&, const badouble& );
     283    friend ADOLC_DLL_EXPORT adub operator < ( const badouble&, const badouble& );
     284    friend ADOLC_DLL_EXPORT adub operator > ( const badouble&, const badouble& );
    271285    /*--------------------------------------------------------------------------*/
    272286    /* sign operators (friends) */
     
    379393/*--------------------------------------------------------------------------*/
    380394/* Comparison */
     395/*
    381396inline int operator != ( const badouble& u, const badouble& v ) {
    382397    return (u-v != 0);
    383398}
     399*/
    384400
    385401inline int operator != ( double coval, const badouble& v) {
     
    390406}
    391407
     408/*
    392409inline int operator == ( const badouble& u, const badouble& v ) {
    393410    return (u-v == 0);
    394411}
     412*/
    395413
    396414inline int operator == ( double coval, const badouble& v) {
     
    401419}
    402420
     421/*
    403422inline int operator <= ( const badouble& u, const badouble& v ) {
    404423    return (u-v <= 0);
    405424}
     425*/
    406426
    407427inline int operator <= ( double coval, const badouble& v ) {
     
    412432}
    413433
     434/*
    414435inline int operator >= ( const badouble& u, const badouble& v ) {
    415436    return (u-v >= 0);
    416437}
     438*/
    417439
    418440inline int operator >= ( double coval, const badouble& v ) {
     
    423445}
    424446
     447/*
    425448inline int operator > ( const badouble& u, const badouble& v ) {
    426449    return (u-v > 0);
    427450}
     451*/
    428452
    429453inline int operator > ( double coval, const badouble& v ) {
     
    434458}
    435459
     460/*
    436461inline int operator < ( const badouble& u, const badouble& v ) {
    437462    return (u-v < 0);
    438463}
     464*/
    439465
    440466inline int operator < ( double coval, const badouble& v ) {
  • trunk/ADOL-C/src/adouble.cpp

    r337 r360  
    17501750/****************************************************************************/
    17511751/*                                                             CONDITIONALS */
    1752 
    1753 /* For the time being condassign is defined using adoubles in two
    1754    versions with adouble and along as left hand side.  This implies
    1755    some problems when badoubles are used as arguments, e.g. inside
    1756    the pow definition. For later versions we will replace this with
    1757    complete definition for all parameter type constellations */
    1758 
     1752/*--------------------------------------------------------------------------*/
     1753adub operator != (const badouble& x, const badouble& y) {
     1754    ADOLC_OPENMP_THREAD_NUMBER;
     1755    ADOLC_OPENMP_GET_THREAD_NUMBER;
     1756    double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.location];
     1757    double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.location];
     1758    double res = (double)(xval != yval);
     1759    locint locat = next_loc();
     1760    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
     1761        put_op(neq_a_a);
     1762        ADOLC_PUT_LOCINT(x.location); // arg
     1763        ADOLC_PUT_LOCINT(y.location); // arg1
     1764        ADOLC_PUT_VAL(res);           // check for branch switch
     1765        ADOLC_PUT_LOCINT(locat);      // res
     1766
     1767        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
     1768        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
     1769            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
     1770    }
     1771    ADOLC_GLOBAL_TAPE_VARS.store[locat] = res;
     1772    return locat;
     1773}
     1774/*--------------------------------------------------------------------------*/
     1775adub operator == (const badouble& x, const badouble& y) {
     1776    ADOLC_OPENMP_THREAD_NUMBER;
     1777    ADOLC_OPENMP_GET_THREAD_NUMBER;
     1778    double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.location];
     1779    double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.location];
     1780    double res = (double)(xval == yval);
     1781    locint locat = next_loc();
     1782    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
     1783        put_op(eq_a_a);
     1784        ADOLC_PUT_LOCINT(x.location); // arg
     1785        ADOLC_PUT_LOCINT(y.location); // arg1
     1786        ADOLC_PUT_VAL(res);           // check for branch switch
     1787        ADOLC_PUT_LOCINT(locat);      // res
     1788
     1789        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
     1790        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
     1791            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
     1792    }
     1793    ADOLC_GLOBAL_TAPE_VARS.store[locat] = res;
     1794    return locat;
     1795}
     1796/*--------------------------------------------------------------------------*/
     1797adub operator <= (const badouble& x, const badouble& y) {
     1798    ADOLC_OPENMP_THREAD_NUMBER;
     1799    ADOLC_OPENMP_GET_THREAD_NUMBER;
     1800    double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.location];
     1801    double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.location];
     1802    double res = (double)(xval <= yval);
     1803    locint locat = next_loc();
     1804    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
     1805        put_op(le_a_a);
     1806        ADOLC_PUT_LOCINT(x.location); // arg
     1807        ADOLC_PUT_LOCINT(y.location); // arg1
     1808        ADOLC_PUT_VAL(res);           // check for branch switch
     1809        ADOLC_PUT_LOCINT(locat);      // res
     1810
     1811        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
     1812        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
     1813            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
     1814    }
     1815    ADOLC_GLOBAL_TAPE_VARS.store[locat] = res;
     1816    return locat;
     1817}
     1818/*--------------------------------------------------------------------------*/
     1819adub operator >= (const badouble& x, const badouble& y) {
     1820    ADOLC_OPENMP_THREAD_NUMBER;
     1821    ADOLC_OPENMP_GET_THREAD_NUMBER;
     1822    double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.location];
     1823    double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.location];
     1824    double res = (double)(xval >= yval);
     1825    locint locat = next_loc();
     1826    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
     1827        put_op(ge_a_a);
     1828        ADOLC_PUT_LOCINT(x.location); // arg
     1829        ADOLC_PUT_LOCINT(y.location); // arg1
     1830        ADOLC_PUT_VAL(res);           // check for branch switch
     1831        ADOLC_PUT_LOCINT(locat);      // res
     1832
     1833        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
     1834        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
     1835            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
     1836    }
     1837    ADOLC_GLOBAL_TAPE_VARS.store[locat] = res;
     1838    return locat;
     1839}
     1840/*--------------------------------------------------------------------------*/
     1841adub operator > (const badouble& x, const badouble& y) {
     1842    ADOLC_OPENMP_THREAD_NUMBER;
     1843    ADOLC_OPENMP_GET_THREAD_NUMBER;
     1844    double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.location];
     1845    double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.location];
     1846    double res = (double)(xval > yval);
     1847    locint locat = next_loc();
     1848    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
     1849        put_op(gt_a_a);
     1850        ADOLC_PUT_LOCINT(x.location); // arg
     1851        ADOLC_PUT_LOCINT(y.location); // arg1
     1852        ADOLC_PUT_VAL(res);           // check for branch switch
     1853        ADOLC_PUT_LOCINT(locat);      // res
     1854
     1855        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
     1856        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
     1857            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
     1858    }
     1859    ADOLC_GLOBAL_TAPE_VARS.store[locat] = res;
     1860    return locat;
     1861}
     1862/*--------------------------------------------------------------------------*/
     1863adub operator < (const badouble& x, const badouble& y) {
     1864    ADOLC_OPENMP_THREAD_NUMBER;
     1865    ADOLC_OPENMP_GET_THREAD_NUMBER;
     1866    double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.location];
     1867    double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.location];
     1868    double res = (double)(xval < yval);
     1869    locint locat = next_loc();
     1870    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
     1871        put_op(lt_a_a);
     1872        ADOLC_PUT_LOCINT(x.location); // arg
     1873        ADOLC_PUT_LOCINT(y.location); // arg1
     1874        ADOLC_PUT_VAL(res);           // check for branch switch
     1875        ADOLC_PUT_LOCINT(locat);      // res
     1876
     1877        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
     1878        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
     1879            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
     1880    }
     1881    ADOLC_GLOBAL_TAPE_VARS.store[locat] = res;
     1882    return locat;
     1883}
     1884/*--------------------------------------------------------------------------*/
    17591885/*--------------------------------------------------------------------------*/
    17601886void condassign( adouble &res,         const badouble &cond,
  • trunk/ADOL-C/src/fo_rev.c

    r337 r360  
    16671667
    16681668                /*--------------------------------------------------------------------------*/
     1669                /* NEW CONDITIONALS */
     1670                /*--------------------------------------------------------------------------*/
     1671            case neq_a_a:
     1672            case eq_a_a:
     1673            case le_a_a:
     1674            case ge_a_a:
     1675            case lt_a_a:
     1676            case gt_a_a:
     1677                res = get_locint_r();
     1678                arg1 = get_locint_r();
     1679                arg = get_locint_r();
     1680#if !defined(_NTIGHT_)
     1681                coval = get_val_r();
     1682#endif
     1683                ASSIGN_A( Ares, ADJOINT_BUFFER[res])
     1684
     1685                FOR_0_LE_l_LT_p
     1686#if defined(_INT_REV_)
     1687                ARES_INC = 0;
     1688#else
     1689                ARES_INC = 0.0;
     1690#endif
     1691
     1692#if !defined(_NTIGHT_)
     1693                ADOLC_GET_TAYLOR(res);
     1694#endif /* !_NTIGHT_ */
     1695
     1696                break;
     1697                /*--------------------------------------------------------------------------*/
    16691698            case subscript:
    16701699                {
  • trunk/ADOL-C/src/ho_rev.c

    r337 r360  
    20402040                        }
    20412041            break;
     2042                /*--------------------------------------------------------------------------*/
     2043                /* NEW CONDITIONALS */
     2044                /*--------------------------------------------------------------------------*/
     2045            case neq_a_a:
     2046            case eq_a_a:
     2047            case le_a_a:
     2048            case ge_a_a:
     2049            case lt_a_a:
     2050            case gt_a_a:
     2051                res = get_locint_r();
     2052                arg1 = get_locint_r();
     2053                arg = get_locint_r();
     2054                coval = get_val_r();
     2055                ASSIGN_A(Ares, rpp_A[res])
     2056
     2057                FOR_0_LE_l_LT_pk1
     2058                ARES_INC = 0.0;
     2059
     2060                GET_TAYL(res,k,p)
     2061                break;
    20422062
    20432063                /*--------------------------------------------------------------------------*/
  • trunk/ADOL-C/src/oplate.h

    r337 r360  
    100100  ref_copyout,
    101101  ref_cond_assign,
    102   ref_cond_assign_s
     102  ref_cond_assign_s,
     103  eq_a_a = 125,
     104  neq_a_a,
     105  le_a_a,
     106  gt_a_a,
     107  ge_a_a,
     108  lt_a_a
    103109};
    104110
  • trunk/ADOL-C/src/uni5_for.c

    r346 r360  
    38543854                break;
    38553855
     3856
     3857                /*--------------------------------------------------------------------------*/
     3858                /* NEW CONDITIONALS */
     3859                /*--------------------------------------------------------------------------*/
     3860            case neq_a_a:
     3861            case eq_a_a:
     3862            case le_a_a:
     3863            case ge_a_a:
     3864            case lt_a_a:
     3865            case gt_a_a:
     3866                coval = get_val_f();
     3867                arg = get_locint_f();
     3868                arg1 = get_locint_f();
     3869                res = get_locint_f();
     3870#if !defined(_NTIGHT_)
     3871                {
     3872                    revreal retval = -1;
     3873                    const char* opname = "";
     3874                    switch (operation) {
     3875                    case neq_a_a:
     3876                        retval = (revreal)(dp_T0[arg] != dp_T0[arg1]);
     3877                        opname = "neq_a_a";
     3878                        break;
     3879                    case eq_a_a:
     3880                        retval = (revreal)(dp_T0[arg] == dp_T0[arg1]);
     3881                        opname = "eq_a_a";
     3882                        break;
     3883                    case ge_a_a:
     3884                        retval = (revreal)(dp_T0[arg] >= dp_T0[arg1]);
     3885                        opname = "ge_a_a";
     3886                        break;
     3887                    case le_a_a:
     3888                        retval = (revreal)(dp_T0[arg] <= dp_T0[arg1]);
     3889                        opname = "le_a_a";
     3890                        break;
     3891                    case gt_a_a:
     3892                        retval = (revreal)(dp_T0[arg] > dp_T0[arg1]);
     3893                        opname = "gt_a_a";
     3894                        break;
     3895                    case lt_a_a:
     3896                        retval = (revreal)(dp_T0[arg] < dp_T0[arg1]);
     3897                        opname = "lt_a_a";
     3898                        break;
     3899                    }
     3900                    if (retval != coval && ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning)
     3901                        fprintf(DIAG_OUT,
     3902                                "ADOL-C Warning: Branch switch detected in comparison "
     3903                                "(operator %s).\n"
     3904                                "Results may be unpredictable! Retaping recommended!\n",opname);
     3905                    dp_T0[res] = retval;
     3906                }
     3907#endif
     3908#if defined(_INDO_)
     3909#if defined(_INDOPRO_)
     3910                ind_dom[res][0]=0;
     3911#endif
     3912#if defined(_NONLIND_)
     3913                fod[opind].entry = maxopind+2;
     3914                fod[opind].left = NULL;
     3915                fod[opind].right = NULL;
     3916                arg_index[res] = opind++;
     3917#endif
     3918#else
     3919#if !defined(_ZOS_) /* BREAK_ZOS */
     3920                ASSIGN_T(Tres, TAYLOR_BUFFER[res])
     3921
     3922                FOR_0_LE_l_LT_pk
     3923                TRES_INC = 0;
     3924#endif
     3925#endif /* ALL_TOGETHER_AGAIN */
     3926
     3927                break;
    38563928
    38573929                /*--------------------------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.