Changeset 456


Ignore:
Timestamp:
Jan 31, 2014 10:51:28 AM (6 years ago)
Author:
kulshres
Message:

add forward mode interfaces for piecewise linearization

new functions fos_an_forward and fov_an_forward to compute
piecewise linearisation in a single or multiple directions

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

Location:
trunk/ADOL-C
Files:
3 edited

Legend:

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

    r441 r456  
    435435/*--------------------------------------------------------------------------*/
    436436ADOLC_DLL_EXPORT int get_num_switches(short);
    437 ADOLC_DLL_EXPORT int zos_an_forward(short,int,int,int,double*,double*,double*);
     437ADOLC_DLL_EXPORT int zos_an_forward(short,int,int,int,const double*,double*,double*);
     438ADOLC_DLL_EXPORT double firstsign(int, double, double*);
     439ADOLC_DLL_EXPORT int fos_an_forward(short,int,int,const double*,double*,double*,double*);
     440ADOLC_DLL_EXPORT int fov_an_forward(short,int,int,int,const double*,double**,double*,double**);
    438441/*--------------------------------------------------------------------------*/
    439442ADOLC_DLL_EXPORT int fos_an_reverse(short,int,int,int,int,double*);
  • trunk/ADOL-C/src/Makefile.am

    r441 r456  
    5252                       fos_reverse.c fov_reverse.c \
    5353                       hos_reverse.c hos_ov_reverse.c hov_reverse.c \
    54                        forward_partx.c fos_an_reverse.c \
     54                       forward_partx.c zos_an_forward.c fos_an_reverse.c \
     55                       fos_an_forward.c fov_an_forward.c \
    5556                       externfcts.cpp checkpointing.cpp \
    5657                       fixpoint.cpp fov_offset_forward.c revolve.c \
  • trunk/ADOL-C/src/uni5_for.c

    r441 r456  
    5757/*--------------------------------------------------------------------------*/
    5858#if defined(_ZOS_)
     59#if defined(_ABS_NORM_)
     60#  define GENERATED_FILENAME "zos_an_forward"
     61#else
    5962#  define GENERATED_FILENAME "zos_forward"
    60 
     63#endif
    6164/*--------------------------------------------------------------------------*/
    6265#else
    6366#if defined(_FOS_)
     67#if defined(_ABS_NORM_)
     68#define GENERATED_FILENAME "fos_an_forward"
     69#else
    6470#define GENERATED_FILENAME "fos_forward"
     71#endif
    6572
    6673#define ARGUMENT(indexi,l,i) argument[indexi]
     
    7077#else
    7178#if defined(_FOV_)
     79#if defined(_ABS_NORM_)
     80#define GENERATED_FILENAME "fov_an_forward"
     81#else
    7282#define GENERATED_FILENAME "fov_forward"
     83#endif
    7384
    7485#define _ADOLC_VECTOR_
     
    408419#define FOR_0_LE_l_LT_p for (l=0; l<p; l++)
    409420#define FOR_p_GT_l_GE_0 for (l=p-1; l>=0; l--)
     421#if defined(_ABS_NORM_)
     422#define FIRSTSIGN_P(x,y) firstsign(p,x,y)
     423#endif
    410424#else
    411425#if defined(_INT_FOR_)
     
    415429#define FOR_0_LE_l_LT_p
    416430#define FOR_p_GT_l_GE_0
     431#if defined(_ABS_NORM_)
     432#define FIRSTSIGN_P(x,y) firstsign(1,x,y)
     433#endif
    417434#endif
    418435#endif
     
    481498/* Zero Order Scalar version of the forward mode.                           */
    482499/****************************************************************************/
     500#if defined(_ABS_NORM_)
     501int zos_an_forward(short tnum,
     502                  int depcheck,
     503                  int indcheck,
     504                  int keep,
     505                  const double *basepoint,
     506                  double *valuepoint,
     507                  double *swargs)
     508#else
    483509#if defined(_KEEP_)
    484510int  zos_forward(
     
    495521    double       *valuepoint) /* dependent variable values */
    496522
     523#endif
     524
    497525#else
    498526#if defined(_FOS_)
     
    500528/* First Order Scalar version of the forward mode.                          */
    501529/****************************************************************************/
     530#if defined(_ABS_NORM_)
     531int  fos_an_forward(short tnum,
     532                    int depcheck,
     533                    int indcheck,
     534                    const double* basepoint,
     535                    double *argument,
     536                    double *valuepoint,
     537                    double *taylors)
     538#else
    502539#if defined(_KEEP_)
    503540int  fos_forward(
     
    516553    double *taylors)    /* matrix of coefficient vectors */
    517554/* the order of the indices in argument and taylors is [var][taylor] */
     555#endif
    518556
    519557#else
     
    687725/* First Order Vector version of the forward mode.                          */
    688726/****************************************************************************/
     727#if defined(_ABS_NORM_)
     728int  fov_an_forward(
     729    short         tnum,        /* tape id */
     730    int           depcheck,    /* consistency chk on # of deps */
     731    int           indcheck,    /* consistency chk on # of indeps */
     732    int           p,           /* # of taylor series */
     733    const double *basepoint,   /* independent variable values */
     734    double      **argument,    /* Taylor coefficients (input) */
     735    double       *valuepoint,  /* Taylor coefficients (output) */
     736    double      **taylors)     /* matrix of coifficient vectors */
     737/* the order of the indices in argument and taylors is [var][taylor] */
     738#else
    689739int  fov_forward(
    690740    short         tnum,        /* tape id */
     
    697747    double      **taylors)     /* matrix of coifficient vectors */
    698748/* the order of the indices in argument and taylors is [var][taylor] */
     749#endif
    699750#endif
    700751
     
    10091060        exit (-1);
    10101061    }
    1011 
     1062#if defined(_ABS_NORM_)
     1063      if (! ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX] ) {
     1064          fprintf(DIAG_OUT,"ADOL-C error: tape %d was not created compatible "
     1065                  "with %s\n              Please call enableMinMaxUsingAbs() "
     1066                  "before trace_on(%d)\n", tag, __FUNCTION__, tag);
     1067          exit(-1);
     1068      }
     1069#endif
    10121070    /****************************************************************************/
    10131071    /*                                                        MEMORY ALLOCATION */
     
    37633821                if (ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) {
    37643822                    signature[switchnum] = dp_T0[arg];
     3823#if defined(_ZOS_) && defined(_ABS_NORM_)
     3824                    swargs[switchnum] = dp_T0[arg];
     3825#endif
    37653826                }
    37663827#endif /* !_NTIGHT_ */
     
    38003861                TRES_INC = TARG_INC;
    38013862#endif /* _NTIGHT_ */
     3863#else
     3864#ifdef _ABS_NORM_
     3865                y = FIRSTSIGN_P(dp_T0[arg],Targ);
     3866                FOR_0_LE_l_LT_p
     3867                    TRES_INC = y * TARG_INC;
    38023868#else
    38033869                y = 0.0;
     
    38223888                  }
    38233889                }
     3890#endif
    38243891#endif
    38253892#endif
     
    53065373
    53075374/****************************************************************************/
    5308 #if defined(_ZOS_)
     5375#if defined(_ZOS_) && defined(_ABS_NORM_)
    53095376int get_num_switches(short tapeID) {
    53105377    int nswitch;
     
    53235390    return nswitch;
    53245391}
    5325 
    5326 int zos_an_forward(short tag,
    5327                   int m,
    5328                   int n,
    5329                   int keep,
    5330                   double *argument,
    5331                   double *result,
    5332                   double *swargs) {
    5333     int rc;
    5334     TapeInfos *tinfos;
    5335     tinfos = getTapeInfos(tag);
    5336     if (! tinfos->stats[NO_MIN_MAX] ) {
    5337         fprintf(DIAG_OUT,"ADOL-C error: tape %d was not created compatible "
    5338                 "with %s\n              Please call enableMinMaxUsingAbs() "
    5339                 "before trace_on(%d)\n", tag, __FUNCTION__, tag);
    5340         exit(-1);
     5392#endif
     5393#if defined(_ABS_NORM_) && defined(_FOV_)
     5394double firstsign(int p, double u, double* du) {
     5395    int i=0;
     5396    double tmp;
     5397    tmp=(u>0.0)?1.0:0.0;
     5398    tmp=(u<0.0)?-1.0:0.0;
     5399    while(i<p && tmp==0.0) {
     5400        tmp=(du[i]>0.0)?1.0:0.0;
     5401        tmp=(du[i]<0.0)?-1.0:0.0;
     5402        i++;
    53415403    }
    5342     rc = zos_forward(tag,m,n,keep,argument,result);
    5343     tinfos = getTapeInfos(tag);
    5344     memcpy(swargs,tinfos->signature,tinfos->stats[NUM_SWITCHES]*sizeof(double));
     5404    return tmp;
    53455405}
    53465406#endif
Note: See TracChangeset for help on using the changeset viewer.