54 #define max(a,b) ( (a) > (b) ? (a) : (b) )
55 #define min(a,b) ( (a) < (b) ? (a) : (b) )
58 #include "RTOp_obj_value_value_vtbl.h"
59 #include "RTOp_reduct_max_value.h"
64 static int RTOp_ROp_comp_err_with_mu_apply_op(
68 , RTOp_ReductTarget reduct_obj )
75 struct RTOp_value_value_type *data_cntr = (
struct RTOp_value_value_type*)obj_data;
76 RTOp_value_type *mu = &data_cntr->value1;
77 RTOp_value_type *inf_bound = &data_cntr->value2;
79 RTOp_value_type *comp_err = (RTOp_value_type*)reduct_obj;
81 RTOp_index_type sub_dim;
83 const RTOp_value_type *v0_val;
86 const RTOp_value_type *v1_val;
89 const RTOp_value_type *v2_val;
92 const RTOp_value_type *v3_val;
95 const RTOp_value_type *v4_val;
99 register RTOp_index_type k;
101 RTOp_value_type comp_err_ith;
106 if( num_vecs != 5 || ( num_vecs && vecs == NULL ) )
107 return RTOp_ERR_INVALID_NUM_VECS;
108 if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
109 return RTOp_ERR_INVALID_NUM_TARG_VECS;
111 vecs[1].sub_dim != vecs[0].sub_dim
112 || vecs[2].sub_dim != vecs[0].sub_dim
113 || vecs[3].sub_dim != vecs[0].sub_dim
114 || vecs[4].sub_dim != vecs[0].sub_dim
116 return RTOp_ERR_INCOMPATIBLE_VECS;
124 sub_dim = vecs[0].sub_dim;
126 v0_val = vecs[0].values;
127 v0_val_s = vecs[0].values_stride;
129 v1_val = vecs[1].values;
130 v1_val_s = vecs[1].values_stride;
132 v2_val = vecs[2].values;
133 v2_val_s = vecs[2].values_stride;
135 v3_val = vecs[3].values;
136 v3_val_s = vecs[3].values_stride;
138 v4_val = vecs[4].values;
139 v4_val_s = vecs[4].values_stride;
145 for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s, v2_val += v2_val_s, v3_val += v3_val_s, v4_val += v4_val_s )
149 if ((*v1_val) > -(*inf_bound))
150 { comp_err_ith = fabs((*v3_val)*((*v0_val)-(*v1_val))-(*mu)); }
152 if ((*v2_val) < (*inf_bound))
153 { comp_err_ith = max(comp_err_ith, fabs((*v4_val)*((*v2_val)-(*v0_val))-(*mu))); }
156 (*comp_err) = max( (*comp_err), comp_err_ith );
165 &RTOp_obj_value_value_vtbl
166 ,&RTOp_obj_value_vtbl
167 ,
"ROp_comp_err_with_mu"
169 ,RTOp_ROp_comp_err_with_mu_apply_op
170 ,RTOp_reduct_max_value
171 ,RTOp_get_reduct_max_value_op
176 int RTOp_ROp_comp_err_with_mu_construct( RTOp_value_type mu, RTOp_value_type inf_bound,
struct RTOp_RTOp* op )
182 op->vtbl = &RTOp_ROp_comp_err_with_mu_vtbl;
183 op->vtbl->obj_data_vtbl->
obj_create(NULL,NULL,&op->obj_data);
184 return RTOp_ROp_comp_err_with_mu_init(mu,inf_bound,op);
187 int RTOp_ROp_comp_err_with_mu_destroy(
struct RTOp_RTOp* op )
189 op->vtbl->obj_data_vtbl->
obj_free(NULL,NULL,&op->obj_data);
195 int RTOp_ROp_comp_err_with_mu_init( RTOp_value_type mu, RTOp_value_type inf_bound,
struct RTOp_RTOp* op )
197 struct RTOp_value_value_type *ptr_data_cntr = (
struct RTOp_value_value_type*)op->obj_data;
198 RTOp_value_type *ptr_mu = &ptr_data_cntr->value1;
199 RTOp_value_type *ptr_inf_bound = &ptr_data_cntr->value2;
201 *ptr_inf_bound = inf_bound;
204 RTOp_value_type RTOp_ROp_comp_err_with_mu_val(RTOp_ReductTarget reduct_obj)
206 return *((RTOp_value_type*)reduct_obj);
int(* obj_create)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void **obj)
int(* obj_free)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void **obj)