RTOp_ROp_combined_nu_comp_err.c

Go to the documentation of this file.
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 // 
00005 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00006 //                  Copyright (2003) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00026 // 
00027 // ***********************************************************************
00028 // @HEADER
00029 */
00030 
00031 /* */
00032 /* Note: This file was created automatically by 'new_rtop.pl' */
00033 /*       on 6/27/2002 at 15:7 */
00034 /* */
00035 
00036 #define max(a,b) ( (a) > (b) ? (a) : (b) )
00037 #define min(a,b) ( (a) < (b) ? (a) : (b) )
00038 
00039 #include "RTOp_ROp_combined_nu_comp_err.h"
00040 #include "RTOp_obj_null_vtbl.h"  /* vtbl for operator object instance data */
00041 #include "RTOp_reduct_max_value.h"
00042 
00043 
00044 /* Implementation functions for RTOp_RTOp */
00045 
00046 static int RTOp_ROp_combined_nu_comp_err_apply_op(
00047   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
00048   , const int num_vecs, const struct RTOp_SubVector vecs[]
00049   , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
00050   , RTOp_ReductTarget reduct_obj )
00051 {
00052   /* */
00053   /* Declare local variables */
00054   /* */
00055 
00056     /* Access to the reduction object data */
00057     RTOp_value_type *comp_err = (RTOp_value_type*)reduct_obj;
00058     /* Vector data */
00059     RTOp_index_type           sub_dim;
00060     /* v0 */
00061     const RTOp_value_type     *v0_val;
00062     ptrdiff_t                 v0_val_s;
00063     /* v1 */
00064     const RTOp_value_type     *v1_val;
00065     ptrdiff_t                 v1_val_s;
00066     /* v2 */
00067     const RTOp_value_type     *v2_val;
00068     ptrdiff_t                 v2_val_s;
00069     /* v3 */
00070     const RTOp_value_type     *v3_val;
00071     ptrdiff_t                 v3_val_s;
00072 
00073     register RTOp_index_type  k;
00074 
00075   /* */
00076   /* Validate the input */
00077   /* */
00078     if( num_vecs != 4 || ( num_vecs && vecs == NULL ) )
00079         return RTOp_ERR_INVALID_NUM_VECS;
00080     if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
00081         return RTOp_ERR_INVALID_NUM_TARG_VECS;
00082     if( /* Validate sub_dim */
00083         vecs[1].sub_dim != vecs[0].sub_dim
00084         || vecs[2].sub_dim != vecs[0].sub_dim
00085         || vecs[3].sub_dim != vecs[0].sub_dim
00086         )
00087         return RTOp_ERR_INCOMPATIBLE_VECS;
00088     assert(reduct_obj);
00089 
00090 
00091   /* */
00092   /* Get pointers to data */
00093   /* */
00094     sub_dim       = vecs[0].sub_dim;
00095     /* v0 */
00096     v0_val        = vecs[0].values;
00097     v0_val_s      = vecs[0].values_stride;
00098     /* v1 */
00099     v1_val        = vecs[1].values;
00100     v1_val_s      = vecs[1].values_stride;
00101     /* v2 */
00102     v2_val        = vecs[2].values;
00103     v2_val_s      = vecs[2].values_stride;
00104     /* v3 */
00105     v3_val        = vecs[3].values;
00106     v3_val_s      = vecs[3].values_stride;
00107 
00108 
00109   /* */
00110   /* Apply the operator: */
00111   /* */
00112     /*    element-wise reduction      : if (v0(i) < 0) */
00113     /* */
00114     for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s, v2_val += v2_val_s, v3_val += v3_val_s )
00115     {
00116         /* Element-wise reduction */
00117     (*comp_err) = max( *comp_err, (*v0_val) * ((*v3_val) - (*v1_val)));
00118     (*comp_err) = max( *comp_err, -(*v0_val) * ((*v1_val) - (*v2_val)));
00119     }
00120 
00121   return 0; /* success? */
00122 }
00123 
00124 /* Virtual function table */
00125 const struct RTOp_RTOp_vtbl_t RTOp_ROp_combined_nu_comp_err_vtbl =
00126 {
00127   &RTOp_obj_null_vtbl
00128   ,&RTOp_obj_value_vtbl
00129   ,"ROp_combined_nu_comp_err"
00130   ,NULL
00131   ,RTOp_ROp_combined_nu_comp_err_apply_op
00132   ,RTOp_reduct_max_value
00133   ,RTOp_get_reduct_max_value_op
00134 };
00135 
00136 /* Class specific functions */
00137 
00138 int RTOp_ROp_combined_nu_comp_err_construct(  struct RTOp_RTOp* op )
00139 {
00140 #ifdef RTOp_DEBUG
00141   assert(op);
00142 #endif
00143   op->obj_data  = NULL;
00144   op->vtbl      = &RTOp_ROp_combined_nu_comp_err_vtbl;
00145   op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data);
00146   return 0;
00147 }
00148 
00149 int RTOp_ROp_combined_nu_comp_err_destroy( struct RTOp_RTOp* op )
00150 {
00151   op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data);
00152   op->obj_data  = NULL;
00153   op->vtbl      = NULL;
00154   return 0;
00155 }
00156 
00157 
00158 RTOp_value_type RTOp_ROp_combined_nu_comp_err_val(RTOp_ReductTarget reduct_obj)
00159 {
00160     return *((RTOp_value_type*)reduct_obj);
00161 }
00162 
00163 
00164 
00165 /* Implementation functions for RTOp_RTOp */
00166 
00167 static int RTOp_ROp_combined_nu_comp_err_one_only_apply_op(
00168   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
00169   , const int num_vecs, const struct RTOp_SubVector vecs[]
00170   , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
00171   , RTOp_ReductTarget reduct_obj )
00172 {
00173   /* */
00174   /* Declare local variables */
00175   /* */
00176 
00177     /* Access to the reduction object data */
00178     RTOp_value_type *comp_err = (RTOp_value_type*)reduct_obj;
00179     /* Vector data */
00180     RTOp_index_type           sub_dim;
00181     /* v0 */
00182     const RTOp_value_type     *v0_val;
00183     ptrdiff_t                 v0_val_s;
00184     /* v1 */
00185     const RTOp_value_type     *v1_val;
00186     ptrdiff_t                 v1_val_s;
00187     /* v2 */
00188     const RTOp_value_type     *v2_val;
00189     ptrdiff_t                 v2_val_s;
00190 
00191     register RTOp_index_type  k;
00192 
00193   /* */
00194   /* Validate the input */
00195   /* */
00196     if( num_vecs != 3 || ( num_vecs && vecs == NULL ) )
00197         return RTOp_ERR_INVALID_NUM_VECS;
00198     if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
00199         return RTOp_ERR_INVALID_NUM_TARG_VECS;
00200     if( /* Validate sub_dim */
00201         vecs[1].sub_dim != vecs[0].sub_dim
00202         || vecs[2].sub_dim != vecs[0].sub_dim
00203         )
00204         return RTOp_ERR_INCOMPATIBLE_VECS;
00205     assert(reduct_obj);
00206 
00207 
00208   /* */
00209   /* Get pointers to data */
00210   /* */
00211     sub_dim       = vecs[0].sub_dim;
00212     /* v0 */
00213     v0_val        = vecs[0].values;
00214     v0_val_s      = vecs[0].values_stride;
00215     /* v1 */
00216     v1_val        = vecs[1].values;
00217     v1_val_s      = vecs[1].values_stride;
00218     /* v2 */
00219     v2_val        = vecs[2].values;
00220     v2_val_s      = vecs[2].values_stride;
00221 
00222 
00223   /* */
00224   /* Apply the operator: */
00225   /* */
00226     /*    element-wise reduction      : comp_err = max(comp_err, v0(i)*(v1(i)-v2(i))); */
00227     /* */
00228     for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s, v2_val += v2_val_s )
00229     {
00230         /* Element-wise reduction */
00231         (*comp_err) = max((*comp_err), (*v0_val)*((*v1_val)-(*v2_val)));
00232     }
00233 
00234   return 0; /* success? */
00235 }
00236 
00237 /* Virtual function table */
00238 const struct RTOp_RTOp_vtbl_t RTOp_ROp_combined_nu_comp_err_one_only_vtbl =
00239 {
00240   &RTOp_obj_null_vtbl
00241   ,&RTOp_obj_value_vtbl
00242   ,"ROp_combined_nu_comp_err_one_only"
00243   ,NULL
00244   ,RTOp_ROp_combined_nu_comp_err_one_only_apply_op
00245   ,RTOp_reduct_max_value
00246   ,RTOp_get_reduct_max_value_op
00247 };
00248 
00249 /* Class specific functions */
00250 
00251 int RTOp_ROp_combined_nu_comp_err_one_only_construct(  struct RTOp_RTOp* op )
00252 {
00253 #ifdef RTOp_DEBUG
00254   assert(op);
00255 #endif
00256   op->obj_data  = NULL;
00257   op->vtbl      = &RTOp_ROp_combined_nu_comp_err_one_only_vtbl;
00258   op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data);
00259   return 0;
00260 }
00261 
00262 int RTOp_ROp_combined_nu_comp_err_one_only_destroy( struct RTOp_RTOp* op )
00263 {
00264   op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data);
00265   op->obj_data  = NULL;
00266   op->vtbl      = NULL;
00267   return 0;
00268 }
00269 
00270 
00271 RTOp_value_type RTOp_ROp_combined_nu_comp_err_one_only_val(RTOp_ReductTarget reduct_obj)
00272 {
00273     return *((RTOp_value_type*)reduct_obj);
00274 }
00275 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:11:01 2011 for MOOCHO (Single Doxygen Collection) by  doxygen 1.6.3