51 #define max(a,b) ( (a) > (b) ? (a) : (b) )
52 #define min(a,b) ( (a) < (b) ? (a) : (b) )
55 #include "RTOp_obj_null_vtbl.h"
56 #include "RTOp_reduct_max_value.h"
60 static int RTOp_ROp_max_rel_step_apply_op(
64 , RTOp_ReductTarget reduct_obj )
71 RTOp_value_type *gamma = (RTOp_value_type*)reduct_obj;
73 RTOp_index_type sub_dim;
75 const RTOp_value_type *v0_val;
78 const RTOp_value_type *v1_val;
81 register RTOp_index_type k;
82 register RTOp_value_type gamma_i;
87 if( num_vecs != 2 || ( num_vecs && vecs == NULL ) )
88 return RTOp_ERR_INVALID_NUM_VECS;
89 if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
90 return RTOp_ERR_INVALID_NUM_TARG_VECS;
92 vecs[1].sub_dim != vecs[0].sub_dim
94 return RTOp_ERR_INCOMPATIBLE_VECS;
100 sub_dim = vecs[0].sub_dim;
102 v0_val = vecs[0].values;
103 v0_val_s = vecs[0].values_stride;
105 v1_val = vecs[1].values;
106 v1_val_s = vecs[1].values_stride;
113 for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s )
116 gamma_i = fabs((*v1_val)) / ( 1.0 + fabs((*v0_val)) );
117 (*gamma) = max( (*gamma), gamma_i );
127 ,&RTOp_obj_value_vtbl
130 ,RTOp_ROp_max_rel_step_apply_op
131 ,RTOp_reduct_max_value
132 ,RTOp_get_reduct_max_value_op
137 int RTOp_ROp_max_rel_step_construct(
struct RTOp_RTOp* op )
143 op->vtbl = &RTOp_ROp_max_rel_step_vtbl;
144 op->vtbl->obj_data_vtbl->
obj_create(NULL,NULL,&op->obj_data);
148 int RTOp_ROp_max_rel_step_destroy(
struct RTOp_RTOp* op )
150 op->vtbl->obj_data_vtbl->
obj_free(NULL,NULL,&op->obj_data);
156 RTOp_value_type RTOp_ROp_max_rel_step_val(RTOp_ReductTarget reduct_obj)
158 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)