52 #define max(a,b) ( (a) > (b) ? (a) : (b) )
53 #define min(a,b) ( (a) < (b) ? (a) : (b) )
56 #include "RTOp_obj_value_vtbl.h"
57 #include "RTOp_reduct_min_value.h"
63 static int RTOp_ROp_fraction_to_boundary_apply_op(
67 , RTOp_ReductTarget reduct_obj )
74 RTOp_value_type *tau = (RTOp_value_type*)obj_data;
76 RTOp_value_type *alpha_max = (RTOp_value_type*)reduct_obj;
78 RTOp_index_type sub_dim;
80 const RTOp_value_type *v0_val;
83 const RTOp_value_type *v1_val;
86 const RTOp_value_type *v2_val;
89 const RTOp_value_type *v3_val;
93 register RTOp_index_type k;
95 RTOp_value_type alpha_max_ith;
100 if( num_vecs != 4 || ( num_vecs && vecs == NULL ) )
101 return RTOp_ERR_INVALID_NUM_VECS;
102 if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
103 return RTOp_ERR_INVALID_NUM_TARG_VECS;
105 vecs[1].sub_dim != vecs[0].sub_dim
106 || vecs[2].sub_dim != vecs[0].sub_dim
107 || vecs[3].sub_dim != vecs[0].sub_dim
109 return RTOp_ERR_INCOMPATIBLE_VECS;
117 sub_dim = vecs[0].sub_dim;
119 v0_val = vecs[0].values;
120 v0_val_s = vecs[0].values_stride;
122 v1_val = vecs[1].values;
123 v1_val_s = vecs[1].values_stride;
125 v2_val = vecs[2].values;
126 v2_val_s = vecs[2].values_stride;
128 v3_val = vecs[3].values;
129 v3_val_s = vecs[3].values_stride;
135 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 )
139 { alpha_max_ith = (*tau)*((*v0_val)-(*v2_val))/(-(*v1_val)); }
141 { alpha_max_ith = (*tau)*((*v3_val)-(*v0_val))/((*v1_val)); }
144 (*alpha_max) = min( (*alpha_max), alpha_max_ith );
150 static int RTOp_ROp_fraction_to_boundary_reduct_obj_reinit(
152 ,RTOp_ReductTarget reduct_obj
155 RTOp_value_type *alpha_max = (RTOp_value_type*)reduct_obj;
164 ,&RTOp_obj_value_vtbl
165 ,
"ROp_fraction_to_boundary"
166 ,RTOp_ROp_fraction_to_boundary_reduct_obj_reinit
167 ,RTOp_ROp_fraction_to_boundary_apply_op
168 ,RTOp_reduct_min_value
169 ,RTOp_get_reduct_min_value_op
174 int RTOp_ROp_fraction_to_boundary_construct( RTOp_value_type tau,
struct RTOp_RTOp* op )
180 op->vtbl = &RTOp_ROp_fraction_to_boundary_vtbl;
181 op->vtbl->obj_data_vtbl->
obj_create(NULL,NULL,&op->obj_data);
182 return RTOp_ROp_fraction_to_boundary_init(tau,op);
185 int RTOp_ROp_fraction_to_boundary_destroy(
struct RTOp_RTOp* op )
187 op->vtbl->obj_data_vtbl->
obj_free(NULL,NULL,&op->obj_data);
193 int RTOp_ROp_fraction_to_boundary_init( RTOp_value_type tau,
struct RTOp_RTOp* op )
195 RTOp_value_type *ptr_tau = (RTOp_value_type*)op->obj_data;
199 RTOp_value_type RTOp_ROp_fraction_to_boundary_val(RTOp_ReductTarget reduct_obj)
201 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)