47 #include "RTOp_obj_null_vtbl.h"
48 #include "RTOp_obj_value_vtbl.h"
49 #include "RTOp_obj_free_free.h"
50 #include "RTOp_get_reduct_op.hpp"
58 static int CALL_API targ_extract_state(
60 ,
const void * instance_data
63 ,RTOp_value_type value_data[]
65 ,RTOp_index_type index_data[]
67 ,RTOp_char_type char_data[]
70 struct RTOp_value_index_type* vi_obj;
73 assert( num_values == 1 );
74 assert( num_indexes == 1 );
75 assert( num_chars == 0 );
77 vi_obj = (
struct RTOp_value_index_type*)obj;
78 value_data[0] = vi_obj->value;
79 index_data[0] = vi_obj->index;
83 static int CALL_API targ_load_state(
85 ,
const void * instance_data
87 ,
const RTOp_value_type value_data[]
89 ,
const RTOp_index_type index_data[]
91 ,
const RTOp_char_type char_data[]
95 struct RTOp_value_index_type* vi_obj;
99 assert( num_values == 1 );
100 assert( num_indexes == 1 );
101 assert( num_chars == 0 );
103 vi_obj = (
struct RTOp_value_index_type*)*obj;
104 vi_obj->value = value_data[0];
105 vi_obj->index = index_data[0];
111 static int RTOp_ROp_max_abs_ele_apply_op(
115 ,RTOp_ReductTarget targ_obj
123 struct RTOp_value_index_type
126 size_t global_offset;
130 const RTOp_value_type *v_val = NULL;
135 RTOp_value_type abs_v_i;
141 return RTOp_ERR_INVALID_NUM_VECS;
142 if( num_targ_vecs != 0 )
143 return RTOp_ERR_INVALID_NUM_TARG_VECS;
150 targ = (
struct RTOp_value_index_type*)targ_obj;
152 global_offset = vecs[0].global_offset;
154 sub_dim = vecs[0].sub_dim;
156 v_val = vecs[0].values;
157 v_val_s = vecs[0].values_stride;
163 i = global_offset + 1;
164 for( k = 0; k < sub_dim; ++k, ++i, v_val += v_val_s ) {
165 abs_v_i = fabs(*v_val);
166 if( abs_v_i > targ->value || ( abs_v_i == targ->value && i < targ->index ) || targ->index == 0 ) {
167 targ->value = *v_val;
175 static int reduce_reduct_objs(
177 , RTOp_ReductTarget in_reduct_obj, RTOp_ReductTarget inout_reduct_obj )
179 const struct RTOp_value_index_type
180 *i_targ = (
const struct RTOp_value_index_type*)in_reduct_obj;
181 struct RTOp_value_index_type
182 *io_targ = (
struct RTOp_value_index_type*)inout_reduct_obj;
184 i_abs_val = fabs(i_targ->value),
185 io_abs_val = fabs(io_targ->value);
187 ( i_abs_val > io_abs_val )
189 ( i_abs_val > io_abs_val && i_targ->index < io_targ->index )
192 io_targ->value = i_targ->value;
193 io_targ->index = i_targ->index;
198 INSERT_GET_REDUCT_OP_FUNCS(
199 1,1,0,RTOp_value_index_type,reduce_reduct_objs
200 ,targ_load_state,targ_extract_state
201 ,external_reduct_op,get_reduct_op)
206 ,&RTOp_obj_value_index_vtbl
209 ,RTOp_ROp_max_abs_ele_apply_op
216 int RTOp_ROp_max_abs_ele_construct(
struct RTOp_RTOp* op )
218 op->vtbl = &RTOp_ROp_max_abs_ele_vtbl;
223 int RTOp_ROp_max_abs_ele_destroy(
struct RTOp_RTOp* op )
230 struct RTOp_value_index_type
231 RTOp_ROp_max_abs_ele_val(RTOp_ReductTarget targ_obj)
233 return *(
struct RTOp_value_index_type*)targ_obj;