45 #include "RTOp_obj_null_vtbl.h"
46 #include "RTOp_obj_value_vtbl.h"
50 static int RTOp_TOp_ele_wise_divide_apply_op(
54 , RTOp_ReductTarget targ_obj )
56 RTOp_value_type alpha;
57 RTOp_index_type sub_dim;
58 RTOp_value_type *z_val;
60 const RTOp_value_type *v0_val;
62 const RTOp_value_type *v1_val;
64 register RTOp_index_type k;
69 if( num_vecs != 2 || vecs == NULL )
70 return RTOp_ERR_INVALID_NUM_VECS;
71 if( num_targ_vecs != 1 || targ_vecs == NULL )
72 return RTOp_ERR_INVALID_NUM_TARG_VECS;
73 if( targ_vecs[0].sub_dim != vecs[0].sub_dim
74 || targ_vecs[0].sub_dim != vecs[1].sub_dim )
75 return RTOp_ERR_INCOMPATIBLE_VECS;
84 alpha = *(RTOp_value_type*)obj_data;
86 sub_dim = targ_vecs[0].sub_dim;
87 z_val = targ_vecs[0].values;
88 z_val_s = targ_vecs[0].values_stride;
90 v0_val = vecs[0].values;
91 v0_val_s = vecs[0].values_stride;
93 v1_val = vecs[1].values;
94 v1_val_s = vecs[1].values_stride;
100 if( z_val_s == 1 && v0_val_s == 1 && v1_val_s == 1 ) {
102 for( k = 0; k < sub_dim; ++k )
103 *z_val++ = alpha*(*v0_val++)/(*v1_val++);
107 for( k = 0; k < sub_dim; ++k, z_val+=z_val_s, v0_val+=v0_val_s, v1_val+=v1_val_s )
108 *z_val = alpha*(*v0_val)/(*v1_val);
119 ,
"TOp_ele_wise_divide"
121 ,RTOp_TOp_ele_wise_divide_apply_op
128 int RTOp_TOp_ele_wise_divide_construct( RTOp_value_type alpha,
struct RTOp_RTOp* op )
134 op->vtbl = &RTOp_TOp_ele_wise_divide_vtbl;
135 op->vtbl->obj_data_vtbl->
obj_create(NULL,NULL,&op->obj_data);
136 return RTOp_TOp_ele_wise_divide_set_alpha(alpha,op);
139 int RTOp_TOp_ele_wise_divide_set_alpha( RTOp_value_type alpha,
struct RTOp_RTOp* op )
143 assert(op->obj_data);
145 *(RTOp_value_type*)op->obj_data = alpha;
149 int RTOp_TOp_ele_wise_divide_destroy(
struct RTOp_RTOp* op )
int(* obj_create)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void **obj)