45 #include "RTOp_obj_null_vtbl.h"
46 #include "RTOp_obj_value_value_vtbl.h"
48 #define max(a,b) ( (a) > (b) ? (a) : (b) )
49 #define min(a,b) ( (a) < (b) ? (a) : (b) )
53 static int RTOp_TOp_force_in_bounds_apply_op(
57 , RTOp_ReductTarget targ_obj )
59 RTOp_index_type sub_dim;
60 RTOp_value_type *x_val;
62 const RTOp_value_type *xl_val;
64 const RTOp_value_type *xu_val;
66 register RTOp_index_type k;
71 if( num_vecs != 2 || vecs == NULL )
72 return RTOp_ERR_INVALID_NUM_VECS;
73 if( num_targ_vecs != 1 || targ_vecs == NULL )
74 return RTOp_ERR_INVALID_NUM_TARG_VECS;
75 if( targ_vecs[0].sub_dim != vecs[0].sub_dim
76 || targ_vecs[0].sub_dim != vecs[1].sub_dim )
77 return RTOp_ERR_INCOMPATIBLE_VECS;
84 sub_dim = targ_vecs[0].sub_dim;
85 x_val = targ_vecs[0].values;
86 x_val_s = targ_vecs[0].values_stride;
88 xl_val = vecs[0].values;
89 xl_val_s = vecs[0].values_stride;
91 xu_val = vecs[1].values;
92 xu_val_s = vecs[1].values_stride;
98 if( x_val_s == 1 && xl_val_s == 1 && xu_val_s == 1 ) {
100 for( k = 0; k < sub_dim; ++k, ++x_val, ++xl_val, ++xu_val ) {
101 if( *x_val < *xl_val )
103 else if( *x_val > *xu_val )
109 for( k = 0; k < sub_dim; ++k, x_val+=x_val_s, xl_val+=xl_val_s, xu_val+=xu_val_s ) {
110 if( *x_val < *xl_val )
112 else if( *x_val > *xu_val )
125 ,
"TOp_force_in_bounds"
127 ,RTOp_TOp_force_in_bounds_apply_op
134 int RTOp_TOp_force_in_bounds_construct(
struct RTOp_RTOp* op )
137 op->vtbl = &RTOp_TOp_force_in_bounds_vtbl;
141 int RTOp_TOp_force_in_bounds_destroy(
struct RTOp_RTOp* op )
150 static int RTOp_TOp_force_in_bounds_buffer_apply_op(
154 , RTOp_ReductTarget reduct_obj )
161 struct RTOp_value_value_type *data_cntr = (
struct RTOp_value_value_type*)obj_data;
162 RTOp_value_type *rel_push = &data_cntr->value1;
163 RTOp_value_type *abs_push = &data_cntr->value2;
165 RTOp_index_type sub_dim;
167 RTOp_value_type *z0_val;
170 const RTOp_value_type *v0_val;
173 const RTOp_value_type *v1_val;
177 register RTOp_index_type k;
179 RTOp_value_type xl_sb;
180 RTOp_value_type xu_sb;
185 if( num_vecs != 2 || ( num_vecs && vecs == NULL ) )
186 return RTOp_ERR_INVALID_NUM_VECS;
187 if( num_targ_vecs != 1 || ( num_targ_vecs && targ_vecs == NULL ) )
188 return RTOp_ERR_INVALID_NUM_TARG_VECS;
190 vecs[1].sub_dim != vecs[0].sub_dim
191 || targ_vecs[0].sub_dim != vecs[0].sub_dim
193 return RTOp_ERR_INCOMPATIBLE_VECS;
200 sub_dim = vecs[0].sub_dim;
202 z0_val = targ_vecs[0].values;
203 z0_val_s = targ_vecs[0].values_stride;
205 v0_val = vecs[0].values;
206 v0_val_s = vecs[0].values_stride;
208 v1_val = vecs[1].values;
209 v1_val_s = vecs[1].values_stride;
215 for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s, z0_val += z0_val_s )
218 xl_sb = min((*v0_val) + (*rel_push)*((*v1_val)-(*v0_val)), (*v0_val) + (*abs_push));
219 xu_sb = max((*v1_val) - (*rel_push)*((*v1_val)-(*v0_val)), (*v1_val) - (*abs_push));
222 (*z0_val) = (*v0_val) + ((*v1_val)-(*v0_val))/2.0;
224 else if ((*z0_val) < xl_sb)
225 { (*z0_val) = xl_sb; }
226 else if ((*z0_val) > xu_sb)
227 { (*z0_val) = xu_sb; }
237 &RTOp_obj_value_value_vtbl
239 ,
"TOp_force_in_bounds_buffer"
241 ,RTOp_TOp_force_in_bounds_buffer_apply_op
248 int RTOp_TOp_force_in_bounds_buffer_construct( RTOp_value_type rel_push, RTOp_value_type abs_push,
struct RTOp_RTOp* op )
255 op->vtbl->obj_data_vtbl->
obj_create(NULL,NULL,&op->obj_data);
256 return RTOp_TOp_force_in_bounds_buffer_init(rel_push,abs_push,op);
259 int RTOp_TOp_force_in_bounds_buffer_destroy(
struct RTOp_RTOp* op )
261 op->vtbl->obj_data_vtbl->
obj_free(NULL,NULL,&op->obj_data);
267 int RTOp_TOp_force_in_bounds_buffer_init( RTOp_value_type rel_push, RTOp_value_type abs_push,
struct RTOp_RTOp* op )
269 struct RTOp_value_value_type *ptr_data_cntr = (
struct RTOp_value_value_type*)op->obj_data;
270 RTOp_value_type *ptr_rel_push = &ptr_data_cntr->value1;
271 RTOp_value_type *ptr_abs_push = &ptr_data_cntr->value2;
272 *ptr_rel_push = rel_push;
273 *ptr_abs_push = abs_push;
const struct RTOp_RTOp_vtbl_t RTOp_TOp_force_in_bounds_buffer_vtbl
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)