47 #include "RTOp_obj_null_vtbl.h" 
   48 #include "RTOp_obj_value_vtbl.h" 
   49 #include "RTOp_reduct_sum_value.h" 
   50 #include "RTOp_reduct_max_value.h" 
   52 #define MY_MAX(a,b) a > b ? a : b 
   56 static int RTOp_ROp_norms_apply_op_norm_1(
 
   60   , RTOp_ReductTarget targ_obj )
 
   62   RTOp_index_type        sub_dim;
 
   63   const RTOp_value_type  *v0_val;
 
   65   register RTOp_index_type k;
 
   66   RTOp_value_type        *norm = NULL;
 
   72     return RTOp_ERR_INVALID_NUM_VECS;
 
   73   if( num_targ_vecs != 0 )
 
   74     return RTOp_ERR_INVALID_NUM_TARG_VECS;
 
   83   sub_dim        = vecs[0].sub_dim;
 
   84   v0_val         = vecs[0].values;
 
   85   v0_val_s       = vecs[0].values_stride;
 
   90   norm = (RTOp_value_type*)targ_obj;
 
   91   for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s ) {
 
   92     *norm += fabs(*v0_val);  
 
  101   ,&RTOp_obj_value_vtbl 
 
  104   ,RTOp_ROp_norms_apply_op_norm_1
 
  105   ,RTOp_reduct_sum_value
 
  106   ,RTOp_get_reduct_sum_value_op
 
  109 int RTOp_ROp_norm_1_construct( 
struct RTOp_RTOp* op )
 
  111   op->vtbl     = &RTOp_ROp_norm_1_vtbl;
 
  116 RTOp_value_type RTOp_ROp_norm_1_val(RTOp_ReductTarget targ_obj)
 
  119   assert(targ_obj != RTOp_REDUCT_OBJ_NULL );
 
  121   return *(RTOp_value_type*)targ_obj;
 
  126 static int RTOp_ROp_norms_apply_op_norm_2(
 
  130   , RTOp_ReductTarget targ_obj )
 
  132   RTOp_index_type        sub_dim;
 
  133   const RTOp_value_type  *v0_val;
 
  135   register RTOp_index_type k;
 
  136   RTOp_value_type        *norm = NULL;
 
  142     return RTOp_ERR_INVALID_NUM_VECS;
 
  143   if( num_targ_vecs != 0 )
 
  144     return RTOp_ERR_INVALID_NUM_TARG_VECS;
 
  153   sub_dim        = vecs[0].sub_dim;
 
  154   v0_val         = vecs[0].values;
 
  155   v0_val_s       = vecs[0].values_stride;
 
  160   norm = (RTOp_value_type*)targ_obj;
 
  161   for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s )
 
  162     *norm += (*v0_val)*(*v0_val);  
 
  170   ,&RTOp_obj_value_vtbl 
 
  173   ,RTOp_ROp_norms_apply_op_norm_2
 
  174   ,RTOp_reduct_sum_value
 
  175   ,RTOp_get_reduct_sum_value_op
 
  178 int RTOp_ROp_norm_2_construct( 
struct RTOp_RTOp* op )
 
  180   op->vtbl     = &RTOp_ROp_norm_2_vtbl;
 
  185 RTOp_value_type RTOp_ROp_norm_2_val(RTOp_ReductTarget targ_obj)
 
  188   assert(targ_obj != RTOp_REDUCT_OBJ_NULL );
 
  190   return sqrt(*(RTOp_value_type*)targ_obj);
 
  195 static int RTOp_ROp_norms_apply_op_norm_inf(
 
  199   , RTOp_ReductTarget targ_obj )
 
  201   RTOp_index_type        sub_dim;
 
  202   const RTOp_value_type  *v0_val;
 
  204   register RTOp_index_type k;
 
  205   RTOp_value_type        *norm = NULL;
 
  211     return RTOp_ERR_INVALID_NUM_VECS;
 
  212   if( num_targ_vecs != 0 )
 
  213     return RTOp_ERR_INVALID_NUM_TARG_VECS;
 
  222   sub_dim        = vecs[0].sub_dim;
 
  223   v0_val         = vecs[0].values;
 
  224   v0_val_s       = vecs[0].values_stride;
 
  229   norm = (RTOp_value_type*)targ_obj;
 
  230   for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s )
 
  231     *norm = MY_MAX( fabs(*v0_val), (*(RTOp_value_type*)targ_obj) );  
 
  239   ,&RTOp_obj_value_vtbl 
 
  242   ,RTOp_ROp_norms_apply_op_norm_inf
 
  243   ,RTOp_reduct_max_value
 
  244   ,RTOp_get_reduct_max_value_op
 
  247 int RTOp_ROp_norm_inf_construct( 
struct RTOp_RTOp* op )
 
  249   op->vtbl     = &RTOp_ROp_norm_inf_vtbl;
 
  254 RTOp_value_type RTOp_ROp_norm_inf_val(RTOp_ReductTarget targ_obj)
 
  257   assert(targ_obj != RTOp_REDUCT_OBJ_NULL );
 
  259   return *(RTOp_value_type*)targ_obj;
 
  264 int RTOp_ROp_norm_destroy( 
struct RTOp_RTOp* op )