/[ascend]/trunk/models/test/blackbox/bboxtest.c
ViewVC logotype

Diff of /trunk/models/test/blackbox/bboxtest.c

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

revision 1033 by johnpye, Thu Jan 4 01:51:38 2007 UTC revision 1034 by johnpye, Thu Jan 4 05:37:55 2007 UTC
# Line 63  struct BBOXTEST_problem { Line 63  struct BBOXTEST_problem {
63  static int GetCoef( struct Instance *data, struct BBOXTEST_problem *problem){  static int GetCoef( struct Instance *data, struct BBOXTEST_problem *problem){
64    
65      if (!data) {      if (!data) {
66          FPRINTF(stderr,"Error: bboxtest: expecting a data instance to be provided\n");          ERROR_REPORTER_HERE(ASC_USER_ERROR,"expecting a data instance to be provided");
67          return 1;          return 1;
68      }      }
69      if (InstanceKind(data)!=REAL_CONSTANT_INST) {      if (InstanceKind(data)!=REAL_CONSTANT_INST) {
70          FPRINTF(stderr,"Error: bboxtest: expecting a real constant instance.\n");          ERROR_REPORTER_HERE(ASC_USER_ERROR,"expecting a real constant instance.");
71          return 1;          return 1;
72      }      }
73    
# Line 84  static int CheckArgsOK(struct Instance * Line 84  static int CheckArgsOK(struct Instance *
84      int result;      int result;
85    
86      if (!arglist) {      if (!arglist) {
87          FPRINTF(stderr,"External function argument list does not exist\n");          ERROR_REPORTER_HERE(ASC_USER_ERROR,"External function argument list does not exist.");
88          return 1;          return 1;
89      }      }
90      len = gl_length(arglist);      len = gl_length(arglist);
91      if (!len) {      if (!len) {
92          FPRINTF(stderr,"No arguments to external function statement\n");          ERROR_REPORTER_HERE(ASC_USER_ERROR,"No arguments to external function statement.");
93          return 1;          return 1;
94      }      }
95      if ((len!=(N_INPUT_ARGS+N_OUTPUT_ARGS))) {      if ((len!=(N_INPUT_ARGS+N_OUTPUT_ARGS))) {
96          FPRINTF(stderr,"Number of arguments does not match\n");          ERROR_REPORTER_HERE(ASC_USER_ERROR,"Number of arguments does not match"
97          FPRINTF(stderr,"the external function prototype(array_of_realatom[set],array_of_realatom[set],real_constant\n");              " the external function"
98                " prototype(array_of_realatom[set],array_of_realatom[set],real_constant"
99            );
100          return 1;          return 1;
101      }      }
102    
# Line 102  static int CheckArgsOK(struct Instance * Line 104  static int CheckArgsOK(struct Instance *
104      noutputs = CountNumberOfArgs(arglist,N_INPUT_ARGS+1,      noutputs = CountNumberOfArgs(arglist,N_INPUT_ARGS+1,
105                      N_INPUT_ARGS+N_OUTPUT_ARGS);                      N_INPUT_ARGS+N_OUTPUT_ARGS);
106      if (ninputs != noutputs) {      if (ninputs != noutputs) {
107          FPRINTF(stderr,"bboxtest: Length of input, output arguments mismatched.\n");          ERROR_REPORTER_HERE(ASC_USER_ERROR,"Length of input, output arguments mismatched.");
108          return 1;          return 1;
109      }      }
110    
# Line 156  int bboxtest_preslv(struct BBoxInterp *i Line 158  int bboxtest_preslv(struct BBoxInterp *i
158      struct BBOXTEST_problem *problem;      struct BBOXTEST_problem *problem;
159    
160  #ifdef BBOXTEST_DEBUG  #ifdef BBOXTEST_DEBUG
161      FPRINTF(stdout,"bboxtest_preslv called (interp %p), (instance %p)\n",interp, interp->user_data);      CONSOLE_DEBUG("bboxtest_preslv called (interp %p), (instance %p)",interp, interp->user_data);
162  #endif  #endif
163      if (interp->task == bb_first_call) {      if (interp->task == bb_first_call) {
164  #ifdef BBOXTEST_DEBUG  #ifdef BBOXTEST_DEBUG
165      FPRINTF(stdout,"bboxtest_preslv called for bb_first_call");      CONSOLE_DEBUG("bboxtest_preslv called for bb_first_call");
166  #endif  #endif
167          if (interp->user_data!=NULL) {          if (interp->user_data!=NULL) {
168              /* we have been called before */              CONSOLE_DEBUG("We have been called before: not reallocating");
169              return 0;              return 0;
170              /* the problem structure exists */              /* the problem structure exists */
171          } else {          } else {
# Line 177  int bboxtest_preslv(struct BBoxInterp *i Line 179  int bboxtest_preslv(struct BBoxInterp *i
179          }          }
180      }      }
181  #ifdef BBOXTEST_DEBUG  #ifdef BBOXTEST_DEBUG
182      FPRINTF(stdout,"bboxtest_preslv called in fish circumstance.");      CONSOLE_DEBUG("bboxtest_preslv called in fish circumstance.");
183  #endif  #endif
184      return 1; /* shouldn't be here ever. */      return 1; /* shouldn't be here ever. */
185  }  }
# Line 201  static int DoCalculation(struct BBoxInte Line 203  static int DoCalculation(struct BBoxInte
203      int c;      int c;
204      double coef;      double coef;
205    
206      asc_assert(ninputs == noutputs);      if(ninputs != noutputs){
207            ERROR_REPORTER_HERE(ASC_PROG_ERR,"ninputs != noutputs");
208            return -1;
209        }
210      problem = (struct BBOXTEST_problem *)interp->user_data;      problem = (struct BBOXTEST_problem *)interp->user_data;
211      coef = problem->coef;      coef = problem->coef;
212    
# Line 210  static int DoCalculation(struct BBoxInte Line 215  static int DoCalculation(struct BBoxInte
215      }      }
216    
217  #ifdef BBOXTEST_DEBUG  #ifdef BBOXTEST_DEBUG
218      FPRINTF(stdout,"bboxtest_fex called (instance %p)\n",interp->user_data);      CONSOLE_DEBUG("instance = %p",interp->user_data);
219      for(c=0;c<ninputs;c++) {      for(c=0;c<ninputs;c++) {
220          FPRINTF(stdout,"x[%d]   = %12.8g\n",c,inputs[c]);          CONSOLE_DEBUG("x[%d]    = %12.8g",c,inputs[c]);
221      }      }
222      for (c=0;c<noutputs;c++) {      for (c=0;c<noutputs;c++) {
223          FPRINTF(stdout,"y[%d]   = %20.8g\n",c,outputs[c]);          CONSOLE_DEBUG("y[%d]    = %20.8g",c,outputs[c]);
224      }      }
225  #endif /* BBOXTEST_DEBUG */  #endif /* BBOXTEST_DEBUG */
226    
# Line 223  static int DoCalculation(struct BBoxInte Line 228  static int DoCalculation(struct BBoxInte
228      return 0;      return 0;
229  }  }
230    
231    /** return 0 on success */
232  int bboxtest_fex(struct BBoxInterp *interp,  int bboxtest_fex(struct BBoxInterp *interp,
233          int ninputs,          int ninputs,
234          int noutputs,          int noutputs,
# Line 230  int bboxtest_fex(struct BBoxInterp *inte Line 236  int bboxtest_fex(struct BBoxInterp *inte
236          double *outputs,          double *outputs,
237          double *jacobian          double *jacobian
238  ){  ){
     int nok;  
239      (void)jacobian;      (void)jacobian;
240      nok = DoCalculation(interp, ninputs, noutputs, inputs, outputs);      return DoCalculation(interp, ninputs, noutputs, inputs, outputs);
     if (nok) {  
         return 1;  
     } else {  
         return 0;  
     }  
241  }  }
242    
243  int DoDeriv(struct BBoxInterp *interp, int ninputs, double *jacobian)  int DoDeriv(struct BBoxInterp *interp, int ninputs, double *jacobian)
244  {  {
245      int i; int len;      int i; int len;
246      double coef;      double coef;
247      asc_assert(interp!=NULL);      if(interp==NULL){
248      asc_assert(interp->user_data!=NULL);          ERROR_REPORTER_HERE(ASC_PROG_ERR,"interp==NULL");
249            return -1;
250        }
251        if(interp->user_data==NULL){
252            ERROR_REPORTER_HERE(ASC_PROG_ERR,"interp->user_data==NULL");
253            return -2;
254        }
255      coef = ((struct BBOXTEST_problem *)interp->user_data)->coef;      coef = ((struct BBOXTEST_problem *)interp->user_data)->coef;
256      len = ninputs*ninputs;      len = ninputs*ninputs;
257    
258  #ifdef BBOXTEST_DEBUG  #ifdef BBOXTEST_DEBUG
259      FPRINTF(stdout,"bboxtest_jex called (instance %p)\n",interp->user_data);      CONSOLE_DEBUG("instance = %p",interp->user_data);
260  #endif  #endif
261      for (i = 0; i< len; i++) {      for (i = 0; i< len; i++) {
262          jacobian[i] = 0;          jacobian[i] = 0;
# Line 261  int DoDeriv(struct BBoxInterp *interp, i Line 267  int DoDeriv(struct BBoxInterp *interp, i
267      }      }
268  #ifdef BBOXTEST_DEBUG  #ifdef BBOXTEST_DEBUG
269      for(i=0; i<len; i++) {      for(i=0; i<len; i++) {
270          FPRINTF(stdout,"J[%d]   = %12.8g\n", i, jacobian[i]);          CONSOLE_DEBUG("J[%d]    = %12.8g", i, jacobian[i]);
271      }      }
272  #endif  #endif
273      return 0;      return 0;
274  }  }
275    
276    /* return 0 on success */
277  int bboxtest_jex(struct BBoxInterp *interp,  int bboxtest_jex(struct BBoxInterp *interp,
278          int ninputs,          int ninputs,
279          int noutputs,          int noutputs,
# Line 274  int bboxtest_jex(struct BBoxInterp *inte Line 281  int bboxtest_jex(struct BBoxInterp *inte
281          double *outputs,          double *outputs,
282          double *jacobian          double *jacobian
283  ){  ){
     int nok;  
284      (void)noutputs;      (void)noutputs;
285      (void)outputs;      (void)outputs;
286      (void)inputs;      (void)inputs;
287            
288      nok = DoDeriv(interp, ninputs, jacobian);      return DoDeriv(interp, ninputs, jacobian);
     if (nok) {  
         return 1;  
     } else {  
         return 0;  
     }  
289  }  }
290    
291  /**  /**

Legend:
Removed from v.1033  
changed lines
  Added in v.1034

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