44 #include "RTOp_ROp_max_step.h"
45 #include "RTOp_obj_value_vtbl.h"
46 #include "RTOp_obj_free_free.h"
47 #include "RTOp_get_reduct_op.hpp"
48 #include "RTOp_reduct_min_value.h"
50 static int RTOp_ROp_max_step_reduct_obj_reinit(
52 , RTOp_ReductTarget reduct_obj )
54 *((RTOp_value_type*)reduct_obj) = RTOp_ROp_max_step_inf;
58 static int ROp_max_step_apply_op(
62 , RTOp_ReductTarget reduct_obj )
65 const RTOp_value_type beta = *(RTOp_value_type*)obj_data;
66 RTOp_value_type *alpha = (RTOp_value_type*)reduct_obj;
67 RTOp_index_type sub_dim = 0;
68 const RTOp_value_type *v0_val = NULL, *v1_val = NULL;
69 ptrdiff_t v0_val_s = 0, v1_val_s = 0;
70 register RTOp_index_type k;
71 RTOp_value_type alpha_tmp;
73 if( num_vecs != 2 )
return RTOp_ERR_INVALID_NUM_VECS;
74 if( num_targ_vecs != 0 )
return RTOp_ERR_INVALID_NUM_TARG_VECS;
75 if( vecs[0].sub_dim != vecs[1].sub_dim )
return RTOp_ERR_INCOMPATIBLE_VECS;
77 sub_dim = vecs[0].sub_dim;
78 v0_val = vecs[0].values; v0_val_s = vecs[0].values_stride;
79 v1_val = vecs[1].values; v1_val_s = vecs[1].values_stride;
82 for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s ) {
83 alpha_tmp = (beta - (*v0_val))/(*v1_val);
84 *alpha = ( (0 <= alpha_tmp && alpha_tmp < *alpha) ? alpha_tmp : *alpha );
95 ,RTOp_ROp_max_step_reduct_obj_reinit
96 ,ROp_max_step_apply_op
97 ,RTOp_reduct_min_value
98 ,RTOp_get_reduct_min_value_op
103 int RTOp_ROp_max_step_construct( RTOp_value_type beta,
struct RTOp_RTOp* op )
105 op->vtbl = &RTOp_ROp_max_step_vtbl;
106 op->vtbl->obj_data_vtbl->
obj_create(NULL,NULL,&op->obj_data);
107 *((RTOp_value_type*)op->obj_data) = beta;
111 int RTOp_ROp_max_step_destroy(
struct RTOp_RTOp* op )
113 op->vtbl->obj_data_vtbl->
obj_free(NULL,NULL,&op->obj_data);
118 int RTOp_ROp_max_step_set_beta( RTOp_value_type beta,
struct RTOp_RTOp* op )
120 *((RTOp_value_type*)op->obj_data) = beta;
124 RTOp_value_type RTOp_ROp_max_step_inf = +1e+50;
126 RTOp_value_type RTOp_ROp_max_step_val(RTOp_ReductTarget reduct_obj)
128 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)