MOOCHO (Single Doxygen Collection) Version of the Day
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 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00039 // 
00040 // ***********************************************************************
00041 // @HEADER
00042 */
00043 
00044 /* ///////////////////////////////////////////// */
00045 /* RTOp_ROp_fraction_to_zero_boundary.c */
00046 
00047 /* */
00048 /* Note: This file was created automatically by 'new_rtop.pl' */
00049 /*       on 7/8/2002 at 19:19 */
00050 /* */
00051 
00052 #define max(a,b) ( (a) > (b) ? (a) : (b) )
00053 #define min(a,b) ( (a) < (b) ? (a) : (b) )
00054 
00055 
00056 #include "RTOp_ROp_fraction_to_zero_boundary.h"
00057 #include "RTOp_obj_value_vtbl.h"  /* vtbl for operator object instance data */
00058 #include "RTOp_reduct_min_value.h"  /* Reduction of intermediate reduction objects */
00059 
00060 
00061 
00062 /* Implementation functions for RTOp_RTOp */
00063 
00064 static int RTOp_ROp_fraction_to_zero_boundary_apply_op(
00065   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
00066   , const int num_vecs, const struct RTOp_SubVector vecs[]
00067   , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
00068   , RTOp_ReductTarget reduct_obj )
00069 {
00070   /* */
00071   /* Declare local variables */
00072   /* */
00073 
00074   /* Access to the operator object instance data */
00075   RTOp_value_type *tau = (RTOp_value_type*)obj_data;
00076   /* Access to the reduction object data */
00077   RTOp_value_type *alpha_max = (RTOp_value_type*)reduct_obj;
00078   /* Vector data */
00079   RTOp_index_type           sub_dim;
00080   /* v0 */
00081   const RTOp_value_type     *v0_val;
00082   ptrdiff_t                 v0_val_s;
00083   /* v1 */
00084   const RTOp_value_type     *v1_val;
00085   ptrdiff_t                 v1_val_s;
00086 
00087   /* Automatic temporary variables */
00088   register RTOp_index_type  k;
00089   /* Temporary element-wise reduction object */
00090   RTOp_value_type alpha_max_ith;
00091 
00092   /* */
00093   /* Validate the input */
00094   /* */
00095   if( num_vecs != 2 || ( num_vecs && vecs == NULL ) )
00096     return RTOp_ERR_INVALID_NUM_VECS;
00097   if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
00098     return RTOp_ERR_INVALID_NUM_TARG_VECS;
00099   if( /* Validate sub_dim */
00100     vecs[1].sub_dim != vecs[0].sub_dim
00101     )
00102     return RTOp_ERR_INCOMPATIBLE_VECS;
00103   assert(obj_data);
00104   assert(reduct_obj);
00105 
00106   /* */
00107   /* Get pointers to data */
00108   /* */
00109   sub_dim       = vecs[0].sub_dim;
00110   /* v0 */
00111   v0_val        = vecs[0].values;
00112   v0_val_s      = vecs[0].values_stride;
00113   /* v1 */
00114   v1_val        = vecs[1].values;
00115   v1_val_s      = vecs[1].values_stride;
00116 
00117   /* */
00118   /* Apply the operator: */
00119   /* */
00120   for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s )
00121   {
00122     /* Element-wise reduction */
00123     alpha_max_ith = ((*v1_val) >= 0) ? 1.0 : (*tau)*(*v0_val)/(-(*v1_val));
00124     /* Reduction of intermediates */
00125     (*alpha_max) = min( (*alpha_max), alpha_max_ith );
00126   }
00127 
00128   return 0; /* success? */
00129 }
00130 
00131 static int RTOp_ROp_fraction_to_zero_boundary_reduct_obj_reinit(
00132   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
00133   ,RTOp_ReductTarget reduct_obj
00134   )
00135 {
00136   RTOp_value_type *alpha_max = (RTOp_value_type*)reduct_obj;
00137   *alpha_max = 1.0;
00138   return 0;
00139 }
00140 
00141 /* Virtual function table */
00142 const struct RTOp_RTOp_vtbl_t RTOp_ROp_fraction_to_zero_boundary_vtbl =
00143 {
00144   &RTOp_obj_value_vtbl
00145   ,&RTOp_obj_value_vtbl
00146   ,"ROp_fraction_to_zero_boundary"
00147   ,RTOp_ROp_fraction_to_zero_boundary_reduct_obj_reinit
00148   ,RTOp_ROp_fraction_to_zero_boundary_apply_op
00149   ,RTOp_reduct_min_value
00150   ,RTOp_get_reduct_min_value_op
00151 };
00152 
00153 /* Class specific functions */
00154 
00155 int RTOp_ROp_fraction_to_zero_boundary_construct( RTOp_value_type tau,  struct RTOp_RTOp* op )
00156 {
00157 #ifdef RTOp_DEBUG
00158   assert(op);
00159 #endif
00160   op->obj_data  = NULL;
00161   op->vtbl      = &RTOp_ROp_fraction_to_zero_boundary_vtbl;
00162   op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data);
00163   return RTOp_ROp_fraction_to_zero_boundary_init(tau,op);
00164 }
00165 
00166 int RTOp_ROp_fraction_to_zero_boundary_destroy( struct RTOp_RTOp* op )
00167 {
00168   op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data);
00169   op->obj_data  = NULL;
00170   op->vtbl      = NULL;
00171   return 0;
00172 }
00173 
00174 int RTOp_ROp_fraction_to_zero_boundary_init( RTOp_value_type tau, struct RTOp_RTOp* op )
00175 {
00176   RTOp_value_type *ptr_tau = (RTOp_value_type*)op->obj_data;
00177   *ptr_tau = tau;
00178   return 0;
00179 }
00180 RTOp_value_type RTOp_ROp_fraction_to_zero_boundary_val(RTOp_ReductTarget reduct_obj)
00181 {
00182   return *((RTOp_value_type*)reduct_obj);
00183 }
00184 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines