53 #include "RTOp_obj_null_vtbl.h"
54 #include "RTOp_obj_free_free.h"
58 struct RTOp_TOp_random_vector_bnd_t {
63 static int get_op_type_num_entries(
79 , RTOp_ReductTarget* obj )
81 *obj = malloc(
sizeof(
struct RTOp_TOp_random_vector_bnd_t));
85 static int extract_op_state(
90 ,RTOp_value_type value_data[]
92 ,RTOp_index_type index_data[]
94 ,RTOp_char_type char_data[]
97 const struct RTOp_TOp_random_vector_bnd_t *bnd = NULL;
99 assert( num_values == 2 );
100 assert( num_indexes == 0 );
101 assert( num_chars == 0 );
102 bnd = (
const struct RTOp_TOp_random_vector_bnd_t*)obj_data;
103 value_data[0] = bnd->l;
104 value_data[1] = bnd->u;
108 static int load_op_state(
112 ,
const RTOp_value_type value_data[]
114 ,
const RTOp_index_type index_data[]
116 ,
const RTOp_char_type char_data[]
120 struct RTOp_TOp_random_vector_bnd_t *bnd = NULL;
122 assert( num_values == 2 );
123 assert( num_indexes == 0 );
124 assert( num_chars == 0 );
125 if(*obj_data == NULL)
126 *obj_data = malloc(
sizeof(
struct RTOp_TOp_random_vector_bnd_t));
127 bnd = (
struct RTOp_TOp_random_vector_bnd_t*)*obj_data;
128 bnd->l = value_data[0];
129 bnd->u = value_data[1];
135 get_op_type_num_entries
145 static int RTOp_TOp_random_vector_apply_op(
149 , RTOp_ReductTarget targ_obj )
156 const struct RTOp_TOp_random_vector_bnd_t *bnd = (
const struct RTOp_TOp_random_vector_bnd_t*)obj_data;
159 RTOp_index_type z_sub_dim;
160 RTOp_value_type *z_val = NULL;
163 register RTOp_index_type k;
168 if( num_vecs != 0 || vecs != NULL )
169 return RTOp_ERR_INVALID_NUM_VECS;
170 if( num_targ_vecs != 1 || targ_vecs == NULL )
171 return RTOp_ERR_INVALID_NUM_TARG_VECS;
174 z_sub_dim = targ_vecs[0].sub_dim;
175 z_val = targ_vecs[0].values;
176 z_val_s = targ_vecs[0].values_stride;
182 for( k = 0; k < z_sub_dim; ++k, z_val += z_val_s )
183 *z_val = bnd->l + ((RTOp_value_type)rand())/RAND_MAX * (bnd->u - bnd->l);
195 ,RTOp_TOp_random_vector_apply_op
202 int RTOp_TOp_random_vector_construct( RTOp_value_type lbnd, RTOp_value_type ubnd
205 struct RTOp_TOp_random_vector_bnd_t *bnd = NULL;
206 op->vtbl = &RTOp_TOp_random_vector_vtbl;
207 op->vtbl->obj_data_vtbl->
obj_create(NULL,NULL,&op->obj_data);
208 bnd = (
struct RTOp_TOp_random_vector_bnd_t*)op->obj_data;
214 int RTOp_TOp_random_vector_destroy(
struct RTOp_RTOp* op )
216 free( op->obj_data );
222 int RTOp_TOp_random_vector_set_bounds( RTOp_value_type lbnd, RTOp_value_type ubnd
225 struct RTOp_TOp_random_vector_bnd_t *bnd = (
struct RTOp_TOp_random_vector_bnd_t*)op->obj_data;
int(* obj_create)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void **obj)