RTOp_ROp_fraction_to_zero_boundary.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 /* RTOp_ROp_fraction_to_zero_boundary.c */
00033 
00034 /* */
00035 /* Note: This file was created automatically by 'new_rtop.pl' */
00036 /*       on 7/8/2002 at 19:19 */
00037 /* */
00038 
00039 #define max(a,b) ( (a) > (b) ? (a) : (b) )
00040 #define min(a,b) ( (a) < (b) ? (a) : (b) )
00041 
00042 #include "RTOp_ROp_fraction_to_zero_boundary.h"
00043 #include "RTOp_obj_value_vtbl.h"  /* vtbl for operator object instance data */
00044 #include "RTOp_reduct_min_value.h"  /* Reduction of intermediate reduction objects */
00045 
00046 
00047 
00048 /* Implementation functions for RTOp_RTOp */
00049 
00050 static int RTOp_ROp_fraction_to_zero_boundary_apply_op(
00051   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
00052   , const int num_vecs, const struct RTOp_SubVector vecs[]
00053   , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
00054   , RTOp_ReductTarget reduct_obj )
00055 {
00056   /* */
00057   /* Declare local variables */
00058   /* */
00059 
00060   /* Access to the operator object instance data */
00061   RTOp_value_type *tau = (RTOp_value_type*)obj_data;
00062   /* Access to the reduction object data */
00063   RTOp_value_type *alpha_max = (RTOp_value_type*)reduct_obj;
00064   /* Vector data */
00065   RTOp_index_type           sub_dim;
00066   /* v0 */
00067   const RTOp_value_type     *v0_val;
00068   ptrdiff_t                 v0_val_s;
00069   /* v1 */
00070   const RTOp_value_type     *v1_val;
00071   ptrdiff_t                 v1_val_s;
00072 
00073   /* Automatic temporary variables */
00074   register RTOp_index_type  k;
00075   /* Temporary element-wise reduction object */
00076   RTOp_value_type alpha_max_ith;
00077 
00078   /* */
00079   /* Validate the input */
00080   /* */
00081   if( num_vecs != 2 || ( num_vecs && vecs == NULL ) )
00082     return RTOp_ERR_INVALID_NUM_VECS;
00083   if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
00084     return RTOp_ERR_INVALID_NUM_TARG_VECS;
00085   if( /* Validate sub_dim */
00086     vecs[1].sub_dim != vecs[0].sub_dim
00087     )
00088     return RTOp_ERR_INCOMPATIBLE_VECS;
00089   assert(obj_data);
00090   assert(reduct_obj);
00091 
00092   /* */
00093   /* Get pointers to data */
00094   /* */
00095   sub_dim       = vecs[0].sub_dim;
00096   /* v0 */
00097   v0_val        = vecs[0].values;
00098   v0_val_s      = vecs[0].values_stride;
00099   /* v1 */
00100   v1_val        = vecs[1].values;
00101   v1_val_s      = vecs[1].values_stride;
00102 
00103   /* */
00104   /* Apply the operator: */
00105   /* */
00106   for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s )
00107   {
00108     /* Element-wise reduction */
00109     alpha_max_ith = ((*v1_val) >= 0) ? 1.0 : (*tau)*(*v0_val)/(-(*v1_val));
00110     /* Reduction of intermediates */
00111     (*alpha_max) = min( (*alpha_max), alpha_max_ith );
00112   }
00113 
00114   return 0; /* success? */
00115 }
00116 
00117 static int RTOp_ROp_fraction_to_zero_boundary_reduct_obj_reinit(
00118   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
00119   ,RTOp_ReductTarget reduct_obj
00120   )
00121 {
00122   RTOp_value_type *alpha_max = (RTOp_value_type*)reduct_obj;
00123   *alpha_max = 1.0;
00124   return 0;
00125 }
00126 
00127 /* Virtual function table */
00128 const struct RTOp_RTOp_vtbl_t RTOp_ROp_fraction_to_zero_boundary_vtbl =
00129 {
00130   &RTOp_obj_value_vtbl
00131   ,&RTOp_obj_value_vtbl
00132   ,"ROp_fraction_to_zero_boundary"
00133   ,RTOp_ROp_fraction_to_zero_boundary_reduct_obj_reinit
00134   ,RTOp_ROp_fraction_to_zero_boundary_apply_op
00135   ,RTOp_reduct_min_value
00136   ,RTOp_get_reduct_min_value_op
00137 };
00138 
00139 /* Class specific functions */
00140 
00141 int RTOp_ROp_fraction_to_zero_boundary_construct( RTOp_value_type tau,  struct RTOp_RTOp* op )
00142 {
00143 #ifdef RTOp_DEBUG
00144   assert(op);
00145 #endif
00146   op->obj_data  = NULL;
00147   op->vtbl      = &RTOp_ROp_fraction_to_zero_boundary_vtbl;
00148   op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data);
00149   return RTOp_ROp_fraction_to_zero_boundary_init(tau,op);
00150 }
00151 
00152 int RTOp_ROp_fraction_to_zero_boundary_destroy( struct RTOp_RTOp* op )
00153 {
00154   op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data);
00155   op->obj_data  = NULL;
00156   op->vtbl      = NULL;
00157   return 0;
00158 }
00159 
00160 int RTOp_ROp_fraction_to_zero_boundary_init( RTOp_value_type tau, struct RTOp_RTOp* op )
00161 {
00162   RTOp_value_type *ptr_tau = (RTOp_value_type*)op->obj_data;
00163   *ptr_tau = tau;
00164   return 0;
00165 }
00166 RTOp_value_type RTOp_ROp_fraction_to_zero_boundary_val(RTOp_ReductTarget reduct_obj)
00167 {
00168   return *((RTOp_value_type*)reduct_obj);
00169 }
00170 

Generated on Thu Sep 18 12:35:19 2008 for MOOCHO (Single Doxygen Collection) by doxygen 1.3.9.1