/[ascend]/trunk/base/generic/compiler/extfunc.c
ViewVC logotype

Diff of /trunk/base/generic/compiler/extfunc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1038 by johnpye, Wed Jan 3 15:33:23 2007 UTC revision 1039 by johnpye, Thu Jan 4 23:21:20 2007 UTC
# Line 23  Line 23 
23      Last in CVS: $Revision: 1.8 $ $Date: 1998/02/05 22:23:26 $ $Author: ballan $      Last in CVS: $Revision: 1.8 $ $Date: 1998/02/05 22:23:26 $ $Author: ballan $
24  */  */
25    
26  #include <utilities/ascConfig.h>  #include "extfunc.h"
27    
28  #include <utilities/ascMalloc.h>  #include <utilities/ascMalloc.h>
29  #include <utilities/ascPanic.h>  #include <utilities/ascPanic.h>
30  #include <general/hashpjw.h>  #include <general/hashpjw.h>
# Line 34  Line 35 
35  #include "symtab.h"  #include "symtab.h"
36  #include "instance_enum.h"  #include "instance_enum.h"
37  #include "instance_io.h"  #include "instance_io.h"
 #include "extfunc.h"  
38  #include "extcall.h"  #include "extcall.h"
39  #include "atomvalue.h"  #include "atomvalue.h"
40    #include "rel_blackbox.h"
41    
42  /*------------------------------------------------------------------------------  /*------------------------------------------------------------------------------
43    forward decls and typedefs etc    forward decls and typedefs etc
# Line 93  int CreateUserFunctionBlackBox(CONST cha Line 94  int CreateUserFunctionBlackBox(CONST cha
94    } else {    } else {
95      efunc->u.black.initial = DefaultExtBBoxInitFunc;      efunc->u.black.initial = DefaultExtBBoxInitFunc;
96    }    }
97    if (!value) {    if(!value){
98      efunc->u.black.value = ErrorExtBBoxValueFunc;      efunc->u.black.value = ErrorExtBBoxValueFunc;
99    } else {    }else{
100      efunc->u.black.value = value;      efunc->u.black.value = value;
101    }    }
102    efunc->u.black.deriv = deriv;    efunc->u.black.deriv = deriv;
103    if (!deriv) {    if(!deriv){
104      efunc->u.black.deriv = DefaultExtBBoxFuncDerivFD;      /*
105           this needs to be set to NULL, since we will automatically apply
106           finite difference if a deriv fn has not explicitly been provided.
107        */
108        efunc->u.black.deriv = NULL;
109    }    }
110    efunc->u.black.deriv2 = deriv2;    efunc->u.black.deriv2 = deriv2;
111    if (!deriv) {    if(!deriv){
112      efunc->u.black.deriv2 = DefaultExtBBoxFuncDeriv2FD;      efunc->u.black.deriv2 = DefaultExtBBoxFuncDeriv2FD;
113    }    }
114    efunc->u.black.final = final;    efunc->u.black.final = final;
115    if (final != NULL) {    if(final != NULL){
116      efunc->u.black.final = final;      efunc->u.black.final = final;
117    } else {    }else{
118      efunc->u.black.final = DefaultExtBBoxFinalFunc;      efunc->u.black.final = DefaultExtBBoxFinalFunc;
119    }    }
120    efunc->u.black.inputTolerance = inputTolerance;    efunc->u.black.inputTolerance = inputTolerance;
121    if (help) {    if(help){
122      if (efunc->help) ascfree((char *)efunc->help);      if (efunc->help) ascfree((char *)efunc->help);
123      efunc->help = ascstrdup(help);      efunc->help = ascstrdup(help);
124    }else{    }else{
# Line 135  ExtBBoxInitFunc * GetInitFunc(struct Ext Line 140  ExtBBoxInitFunc * GetInitFunc(struct Ext
140    return efunc->u.black.initial;    return efunc->u.black.initial;
141  }  }
142    
143  ExtBBoxFinalFunc * GetFinalFunc(struct ExternalFunc *efunc)  ExtBBoxFinalFunc * GetFinalFunc(struct ExternalFunc *efunc){
 {  
144    asc_assert(efunc!=NULL);    asc_assert(efunc!=NULL);
145    return efunc->u.black.final;    return efunc->u.black.final;
146  }  }
# Line 150  ExtBBoxFunc *GetValueFunc(struct Externa Line 154  ExtBBoxFunc *GetValueFunc(struct Externa
154    return efunc->u.black.value;    return efunc->u.black.value;
155  }  }
156    
157  double GetValueFuncTolerance(struct ExternalFunc *efunc)  double GetValueFuncTolerance(struct ExternalFunc *efunc){
 {  
158    asc_assert(efunc!=NULL);    asc_assert(efunc!=NULL);
159    asc_assert(efunc->etype == efunc_BlackBox);    asc_assert(efunc->etype == efunc_BlackBox);
160    return efunc->u.black.inputTolerance;    return efunc->u.black.inputTolerance;
161  }  }
162    
163  ExtBBoxFunc *GetDerivFunc(struct ExternalFunc *efunc)  ExtBBoxFunc *GetDerivFunc(struct ExternalFunc *efunc){
 {  
164    asc_assert(efunc!=NULL);    asc_assert(efunc!=NULL);
165    asc_assert(efunc->etype == efunc_BlackBox);    asc_assert(efunc->etype == efunc_BlackBox);
166    return efunc->u.black.deriv;    return efunc->u.black.deriv;
167  }  }
168    
169  ExtBBoxFunc *GetDeriv2Func(struct ExternalFunc *efunc)  ExtBBoxFunc *GetDeriv2Func(struct ExternalFunc *efunc){
 {  
170    asc_assert(efunc!=NULL);    asc_assert(efunc!=NULL);
171    asc_assert(efunc->etype == efunc_BlackBox);    asc_assert(efunc->etype == efunc_BlackBox);
172    return efunc->u.black.deriv2;    return efunc->u.black.deriv2;
# Line 173  ExtBBoxFunc *GetDeriv2Func(struct Extern Line 174  ExtBBoxFunc *GetDeriv2Func(struct Extern
174    
175  int DefaultExtBBoxInitFunc(struct BBoxInterp *interp,  int DefaultExtBBoxInitFunc(struct BBoxInterp *interp,
176                              struct Instance *data,                              struct Instance *data,
177                              struct gl_list_t *arglist)                              struct gl_list_t *arglist
178  {  ){
179    (void)arglist;    (void)arglist;
180    (void)data;    (void)data;
181  #if EFDEBUG  #if EFDEBUG
182    FPRINTF(ASCERR,"Default do-nothing DefaultExtBBoxInitFunc called.\n");    CONSOLE_DEBUG("Default do-nothing DefaultExtBBoxInitFunc called.");
183  #endif  #endif
184    interp->user_data = NULL;    interp->user_data = NULL;
185    return 0;    return 0;
# Line 191  int ErrorExtBBoxValueFunc( Line 192  int ErrorExtBBoxValueFunc(
192          double *inputs,          double *inputs,
193          double *outputs,          double *outputs,
194          double *jacobian          double *jacobian
195  )  ){
 {  
196    (void)interp;    (void)interp;
197    (void)ninputs;    (void)ninputs;
198    (void)noutputs;    (void)noutputs;
199    (void)inputs;    (void)inputs;
200    (void)outputs;    (void)outputs;
201    (void)jacobian;    (void)jacobian;
202    FPRINTF(ASCERR,"Do-nothing ErrorExtBBoxValueFunc called.\nBlackbox writer is an idiot or memory corrupted.\n");    CONSOLE_DEBUG("Do-nothing ErrorExtBBoxValueFunc called.\nBlackbox writer is an idiot or memory corrupted.");
203    return -1;    return -1;
204  }  }
205    
206  void DefaultExtBBoxFinalFunc(struct BBoxInterp *interp)  void DefaultExtBBoxFinalFunc(struct BBoxInterp *interp){
 {  
207  #if EFDEBUG  #if EFDEBUG
208    FPRINTF(ASCERR,"Default do-nothing DefaultExtBBoxFinalFunc called.\n");    CONSOLE_DEBUG("Default do-nothing DefaultExtBBoxFinalFunc called.");
209  #endif  #endif
210    (void)interp;    (void)interp;
211  }  }
212    
   
 int DefaultExtBBoxFuncDerivFD(  
         struct BBoxInterp *interp,  
         int ninputs,  
         int noutputs,  
         double *inputs,  
         double *outputs,  
         double *jacobian  
 )  
 {  
 #if EFDEBUG  
     FPRINTF(ASCERR,"Braindead DefaultExtBBoxFuncDerivFD called.\n");  
 #endif  
     (void)interp;  
     (void)ninputs;  
     (void)noutputs;  
     (void)inputs;  
     (void)outputs;  
     (void)jacobian;  
   
     ERROR_REPORTER_HERE(ASC_PROG_WARNING,"Blackbox fd gradients not implemented, returning -1");  
     return -1; /* FIXME */  
 }  
   
213  int DefaultExtBBoxFuncDeriv2FD(  int DefaultExtBBoxFuncDeriv2FD(
214          struct BBoxInterp *interp,          struct BBoxInterp *interp,
215          int ninputs,          int ninputs,
# Line 242  int DefaultExtBBoxFuncDeriv2FD( Line 217  int DefaultExtBBoxFuncDeriv2FD(
217          double *inputs,          double *inputs,
218          double *outputs,          double *outputs,
219          double *jacobian          double *jacobian
220  )  ){
 {  
221  #if EFDEBUG  #if EFDEBUG
222      FPRINTF(ASCERR,"Braindead DefaultExtBBoxFuncDeriv2FD called.\n");      CONSOLE_DEBUG("Braindead DefaultExtBBoxFuncDeriv2FD called.");
223  #endif  #endif
224      (void)interp;      (void)interp;
225      (void)ninputs;      (void)ninputs;
# Line 552  void PrintExtFuncLibraryFunc(void *efunc Line 526  void PrintExtFuncLibraryFunc(void *efunc
526    }    }
527  }  }
528    
529  void PrintExtFuncLibrary(FILE *fp)  void PrintExtFuncLibrary(FILE *fp){
530  {    if(!fp){
531    if (!fp) {      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Invalid file handle in PrintExtFuncLibrary");
     FPRINTF(ASCERR,"Invalid file handle in PrintExtFuncLibrary\n");  
532      return;      return;
533    }    }
534    TableApplyAllTwo(g_ExternalFuncLibrary, PrintExtFuncLibraryFunc,    TableApplyAllTwo(g_ExternalFuncLibrary, PrintExtFuncLibraryFunc,

Legend:
Removed from v.1038  
changed lines
  Added in v.1039

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22