49 #define max(a,b) ( (a) > (b) ? (a) : (b) )
50 #define min(a,b) ( (a) < (b) ? (a) : (b) )
53 #include "RTOp_obj_value_vtbl.h"
59 static int RTOp_TOp_inv_of_difference_apply_op(
63 , RTOp_ReductTarget reduct_obj )
70 RTOp_value_type *alpha = (RTOp_value_type*)obj_data;
72 RTOp_index_type sub_dim;
74 RTOp_value_type *z0_val;
77 const RTOp_value_type *v0_val;
80 const RTOp_value_type *v1_val;
83 register RTOp_index_type k;
88 if( num_vecs != 2 || ( num_vecs && vecs == NULL ) )
89 return RTOp_ERR_INVALID_NUM_VECS;
90 if( num_targ_vecs != 1 || ( num_targ_vecs && targ_vecs == NULL ) )
91 return RTOp_ERR_INVALID_NUM_TARG_VECS;
93 vecs[1].sub_dim != vecs[0].sub_dim
94 || targ_vecs[0].sub_dim != vecs[0].sub_dim
96 return RTOp_ERR_INCOMPATIBLE_VECS;
103 sub_dim = vecs[0].sub_dim;
105 z0_val = targ_vecs[0].values;
106 z0_val_s = targ_vecs[0].values_stride;
108 v0_val = vecs[0].values;
109 v0_val_s = vecs[0].values_stride;
111 v1_val = vecs[1].values;
112 v1_val_s = vecs[1].values_stride;
120 for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s, z0_val += z0_val_s )
124 { (*z0_val) = (*alpha)/((*v0_val)-(*v1_val)); }
137 ,
"TOp_inv_of_difference"
139 ,RTOp_TOp_inv_of_difference_apply_op
146 int RTOp_TOp_inv_of_difference_construct( RTOp_value_type alpha,
struct RTOp_RTOp* op )
152 op->vtbl = &RTOp_TOp_inv_of_difference_vtbl;
153 op->vtbl->obj_data_vtbl->
obj_create(NULL,NULL,&op->obj_data);
154 return RTOp_TOp_inv_of_difference_init(alpha,op);
157 int RTOp_TOp_inv_of_difference_destroy(
struct RTOp_RTOp* op )
159 op->vtbl->obj_data_vtbl->
obj_free(NULL,NULL,&op->obj_data);
165 int RTOp_TOp_inv_of_difference_init( RTOp_value_type alpha,
struct RTOp_RTOp* op )
167 RTOp_value_type *ptr_alpha = (RTOp_value_type*)op->obj_data;
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)