49 #define max(a,b) ( (a) > (b) ? (a) : (b) )
50 #define min(a,b) ( (a) < (b) ? (a) : (b) )
53 #include "RTOp_obj_null_vtbl.h"
54 #include "RTOp_reduct_max_value.h"
59 static int RTOp_ROp_combined_nu_comp_err_apply_op(
63 , RTOp_ReductTarget reduct_obj )
70 RTOp_value_type *comp_err = (RTOp_value_type*)reduct_obj;
72 RTOp_index_type sub_dim;
74 const RTOp_value_type *v0_val;
77 const RTOp_value_type *v1_val;
80 const RTOp_value_type *v2_val;
83 const RTOp_value_type *v3_val;
86 register RTOp_index_type k;
91 if( num_vecs != 4 || ( num_vecs && vecs == NULL ) )
92 return RTOp_ERR_INVALID_NUM_VECS;
93 if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
94 return RTOp_ERR_INVALID_NUM_TARG_VECS;
96 vecs[1].sub_dim != vecs[0].sub_dim
97 || vecs[2].sub_dim != vecs[0].sub_dim
98 || vecs[3].sub_dim != vecs[0].sub_dim
100 return RTOp_ERR_INCOMPATIBLE_VECS;
107 sub_dim = vecs[0].sub_dim;
109 v0_val = vecs[0].values;
110 v0_val_s = vecs[0].values_stride;
112 v1_val = vecs[1].values;
113 v1_val_s = vecs[1].values_stride;
115 v2_val = vecs[2].values;
116 v2_val_s = vecs[2].values_stride;
118 v3_val = vecs[3].values;
119 v3_val_s = vecs[3].values_stride;
127 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 )
130 (*comp_err) = max( *comp_err, (*v0_val) * ((*v3_val) - (*v1_val)));
131 (*comp_err) = max( *comp_err, -(*v0_val) * ((*v1_val) - (*v2_val)));
141 ,&RTOp_obj_value_vtbl
142 ,
"ROp_combined_nu_comp_err"
144 ,RTOp_ROp_combined_nu_comp_err_apply_op
145 ,RTOp_reduct_max_value
146 ,RTOp_get_reduct_max_value_op
151 int RTOp_ROp_combined_nu_comp_err_construct(
struct RTOp_RTOp* op )
157 op->vtbl = &RTOp_ROp_combined_nu_comp_err_vtbl;
158 op->vtbl->obj_data_vtbl->
obj_create(NULL,NULL,&op->obj_data);
162 int RTOp_ROp_combined_nu_comp_err_destroy(
struct RTOp_RTOp* op )
164 op->vtbl->obj_data_vtbl->
obj_free(NULL,NULL,&op->obj_data);
171 RTOp_value_type RTOp_ROp_combined_nu_comp_err_val(RTOp_ReductTarget reduct_obj)
173 return *((RTOp_value_type*)reduct_obj);
180 static int RTOp_ROp_combined_nu_comp_err_one_only_apply_op(
184 , RTOp_ReductTarget reduct_obj )
191 RTOp_value_type *comp_err = (RTOp_value_type*)reduct_obj;
193 RTOp_index_type sub_dim;
195 const RTOp_value_type *v0_val;
198 const RTOp_value_type *v1_val;
201 const RTOp_value_type *v2_val;
204 register RTOp_index_type k;
209 if( num_vecs != 3 || ( num_vecs && vecs == NULL ) )
210 return RTOp_ERR_INVALID_NUM_VECS;
211 if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
212 return RTOp_ERR_INVALID_NUM_TARG_VECS;
214 vecs[1].sub_dim != vecs[0].sub_dim
215 || vecs[2].sub_dim != vecs[0].sub_dim
217 return RTOp_ERR_INCOMPATIBLE_VECS;
224 sub_dim = vecs[0].sub_dim;
226 v0_val = vecs[0].values;
227 v0_val_s = vecs[0].values_stride;
229 v1_val = vecs[1].values;
230 v1_val_s = vecs[1].values_stride;
232 v2_val = vecs[2].values;
233 v2_val_s = vecs[2].values_stride;
241 for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s, v2_val += v2_val_s )
244 (*comp_err) = max((*comp_err), (*v0_val)*((*v1_val)-(*v2_val)));
254 ,&RTOp_obj_value_vtbl
255 ,
"ROp_combined_nu_comp_err_one_only"
257 ,RTOp_ROp_combined_nu_comp_err_one_only_apply_op
258 ,RTOp_reduct_max_value
259 ,RTOp_get_reduct_max_value_op
264 int RTOp_ROp_combined_nu_comp_err_one_only_construct(
struct RTOp_RTOp* op )
271 op->vtbl->obj_data_vtbl->
obj_create(NULL,NULL,&op->obj_data);
275 int RTOp_ROp_combined_nu_comp_err_one_only_destroy(
struct RTOp_RTOp* op )
277 op->vtbl->obj_data_vtbl->
obj_free(NULL,NULL,&op->obj_data);
284 RTOp_value_type RTOp_ROp_combined_nu_comp_err_one_only_val(RTOp_ReductTarget reduct_obj)
286 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)
const struct RTOp_RTOp_vtbl_t RTOp_ROp_combined_nu_comp_err_one_only_vtbl