44 #include "Teuchos_ConfigDefs.hpp"
45 #include "ExampleNLPDirectRTOps.h"
46 #include "RTOp_obj_null_vtbl.h"
47 #include "RTOp_obj_index_vtbl.h"
51 static int explnlp2_c_eval_apply_op(
55 , RTOp_ReductTarget targ_obj )
59 RTOp_value_type *c_val;
62 const RTOp_value_type *xD_val;
65 const RTOp_value_type *xI_val;
68 register RTOp_index_type k;
73 if( num_vecs != 2 || vecs == NULL )
74 return RTOp_ERR_INVALID_NUM_VECS;
75 if( num_targ_vecs != 1 || targ_vecs == NULL )
76 return RTOp_ERR_INVALID_NUM_TARG_VECS;
77 if( targ_vecs[0].sub_dim != vecs[0].sub_dim
78 || targ_vecs[0].sub_dim != vecs[1].sub_dim
79 || targ_vecs[0].global_offset != vecs[0].global_offset
80 || targ_vecs[0].global_offset != vecs[1].global_offset )
81 return RTOp_ERR_INCOMPATIBLE_VECS;
88 sub_dim = targ_vecs[0].sub_dim;
89 c_val = targ_vecs[0].values;
90 c_val_s = targ_vecs[0].values_stride;
92 xD_val = vecs[0].values;
93 xD_val_s = vecs[0].values_stride;
95 xI_val = vecs[1].values;
96 xI_val_s = vecs[1].values_stride;
102 if( c_val_s == 1 && xD_val_s == 1 && xI_val_s == 1 ) {
104 for( k = 0; k < sub_dim; ++k, ++xI_val )
105 *c_val++ = (*xD_val++) * (*xI_val - 1.0) - 10.0 * (*xI_val);
109 for( k = 0; k < sub_dim; ++k, c_val+=c_val_s, xD_val+=xD_val_s, xI_val+=xI_val_s )
110 *c_val = (*xD_val) * (*xI_val - 1.0) - 10.0 * (*xI_val);
120 ,
"TOp_explnlp2_c_eval"
122 ,explnlp2_c_eval_apply_op
143 static int explnlp2_calc_py_D_apply_op(
147 , RTOp_ReductTarget targ_obj )
151 const RTOp_value_type *xD_val;
154 const RTOp_value_type *xI_val;
157 const RTOp_value_type *c_val;
160 RTOp_value_type *d_val;
163 RTOp_value_type *py_val;
166 register RTOp_index_type k;
167 int all_unit_stride = 0;
168 RTOp_value_type denom;
173 task = *(
int*)obj_data;
174 assert(0 <= task && task <= 2);
179 if( ( (task == 0 || task == 1) && num_vecs != 2 )
180 || ( (task == 2) && num_vecs != 3 )
182 return RTOp_ERR_INVALID_NUM_VECS;
183 if( ( (task == 0 || task == 1) && num_targ_vecs != 1 )
184 || ( (task == 2) && num_targ_vecs != 2 )
185 || targ_vecs == NULL )
186 return RTOp_ERR_INVALID_NUM_TARG_VECS;
187 if( targ_vecs[0].sub_dim != vecs[0].sub_dim
188 || targ_vecs[0].sub_dim != vecs[1].sub_dim
189 || ( task == 2 && ( targ_vecs[0].sub_dim != vecs[2].sub_dim ) )
190 || ( task == 2 && ( targ_vecs[0].sub_dim != targ_vecs[1].sub_dim ) )
191 || targ_vecs[0].global_offset != vecs[0].global_offset
192 || targ_vecs[0].global_offset != vecs[1].global_offset
193 || ( task == 2 && (targ_vecs[0].global_offset != vecs[2].global_offset ) )
194 || ( task == 2 && ( targ_vecs[0].global_offset != targ_vecs[1].global_offset ) ) )
195 return RTOp_ERR_INCOMPATIBLE_VECS;
201 sub_dim = vecs[0].sub_dim;
205 xD_val = vecs[k].values;
206 xD_val_s = vecs[k].values_stride;
208 if( task == 1 || task == 2 ) {
210 xI_val = vecs[k].values;
211 xI_val_s = vecs[k].values_stride;
214 if( task == 0 || task == 2 ) {
216 c_val = vecs[k].values;
217 c_val_s = vecs[k].values_stride;
221 if( task == 1 || task == 2 ) {
223 d_val = targ_vecs[k].values;
224 d_val_s = targ_vecs[k].values_stride;
227 if( task == 0 || task == 2 ) {
229 py_val = targ_vecs[k].values;
230 py_val_s = targ_vecs[k].values_stride;
236 for( k = 0; k < num_vecs && !all_unit_stride; ++k )
237 if( vecs[k].values_stride != 1 )
239 for( k = 0; k < num_targ_vecs && !all_unit_stride; ++k )
240 if( targ_vecs[k].values_stride != 1 )
247 if( all_unit_stride) {
250 for( k = 0; k < sub_dim; ++k )
251 *py_val++ = *c_val++ / ( 1.0 - *xI_val++ );
255 for( k = 0; k < sub_dim; ++k )
256 *d_val++ = ( *xD_val++ - 10.0 ) / ( 1.0 - *xI_val++ );
260 for( k = 0; k < sub_dim; ++k ) {
261 denom = ( 1.0 - *xI_val++ );
262 *d_val++ = ( *xD_val++ - 10.0 ) / denom;
263 *py_val++ = *c_val++ / denom;
278 ,
"TOp_explnlp2_calc_py_D"
280 ,explnlp2_calc_py_D_apply_op
289 assert( 0 <= task && task <= 2 );
293 result = op->vtbl->obj_data_vtbl->obj_create( NULL, NULL, &op->obj_data );
294 if(result != 0)
return result;
296 assert(op->obj_data);
298 *((
int*)op->obj_data) = task;
305 assert( 0 <= task && task <= 2 );
306 assert(op->obj_data);
308 *((
int*)op->obj_data) = task;
315 result = op->vtbl->reduct_vtbl->obj_free( NULL, NULL, &op->obj_data );
316 if(result != 0)
return result;
const struct RTOp_RTOp_vtbl_t RTOp_TOp_explnlp2_c_eval_vtbl
int RTOp_TOp_explnlp2_calc_py_D_set_task(int task, struct RTOp_RTOp *op)
int RTOp_TOp_explnlp2_calc_py_D_destroy(struct RTOp_RTOp *op)
int RTOp_TOp_explnlp2_c_eval_destroy(struct RTOp_RTOp *op)
const struct RTOp_RTOp_vtbl_t RTOp_TOp_explnlp2_calc_py_D_vtbl
int RTOp_TOp_explnlp2_c_eval_construct(struct RTOp_RTOp *op)
int RTOp_TOp_explnlp2_calc_py_D_construct(int task, struct RTOp_RTOp *op)