|
RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators Version of the Day
|
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 20:41 */ 00034 /* */ 00035 00036 #define max(a,b) ( (a) > (b) ? (a) : (b) ) 00037 #define min(a,b) ( (a) < (b) ? (a) : (b) ) 00038 00039 #include "RTOp_TOp_inv_of_difference.h" 00040 #include "RTOp_obj_value_vtbl.h" /* vtbl for operator object instance data */ 00041 00042 00043 00044 /* Implementation functions for RTOp_RTOp */ 00045 00046 static int RTOp_TOp_inv_of_difference_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 operator object instance data */ 00057 RTOp_value_type *alpha = (RTOp_value_type*)obj_data; 00058 /* Vector data */ 00059 RTOp_index_type sub_dim; 00060 /* z0 */ 00061 RTOp_value_type *z0_val; 00062 ptrdiff_t z0_val_s; 00063 /* v0 */ 00064 const RTOp_value_type *v0_val; 00065 ptrdiff_t v0_val_s; 00066 /* v1 */ 00067 const RTOp_value_type *v1_val; 00068 ptrdiff_t v1_val_s; 00069 00070 register RTOp_index_type k; 00071 00072 /* */ 00073 /* Validate the input */ 00074 /* */ 00075 if( num_vecs != 2 || ( num_vecs && vecs == NULL ) ) 00076 return RTOp_ERR_INVALID_NUM_VECS; 00077 if( num_targ_vecs != 1 || ( num_targ_vecs && targ_vecs == NULL ) ) 00078 return RTOp_ERR_INVALID_NUM_TARG_VECS; 00079 if( /* Validate sub_dim */ 00080 vecs[1].sub_dim != vecs[0].sub_dim 00081 || targ_vecs[0].sub_dim != vecs[0].sub_dim 00082 ) 00083 return RTOp_ERR_INCOMPATIBLE_VECS; 00084 assert(obj_data); 00085 00086 00087 /* */ 00088 /* Get pointers to data */ 00089 /* */ 00090 sub_dim = vecs[0].sub_dim; 00091 /* z0 */ 00092 z0_val = targ_vecs[0].values; 00093 z0_val_s = targ_vecs[0].values_stride; 00094 /* v0 */ 00095 v0_val = vecs[0].values; 00096 v0_val_s = vecs[0].values_stride; 00097 /* v1 */ 00098 v1_val = vecs[1].values; 00099 v1_val_s = vecs[1].values_stride; 00100 00101 00102 /* */ 00103 /* Apply the operator: */ 00104 /* */ 00105 /* element-wise transformation : z0 = alpha/(v0-v1); */ 00106 /* */ 00107 for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s, z0_val += z0_val_s ) 00108 { 00109 /* Element-wise transformation */ 00110 /* if (fabs((*v0_val)-(*v1_val)) > 5.562685e-309) */ 00111 { (*z0_val) = (*alpha)/((*v0_val)-(*v1_val)); } 00112 /* else */ 00113 /* { (*z0_val) = 1.797693e+308; } */ 00114 } 00115 00116 return 0; /* success? */ 00117 } 00118 00119 /* Virtual function table */ 00120 const struct RTOp_RTOp_vtbl_t RTOp_TOp_inv_of_difference_vtbl = 00121 { 00122 &RTOp_obj_value_vtbl 00123 ,&RTOp_obj_null_vtbl 00124 ,"TOp_inv_of_difference" 00125 ,NULL 00126 ,RTOp_TOp_inv_of_difference_apply_op 00127 ,NULL 00128 ,NULL 00129 }; 00130 00131 /* Class specific functions */ 00132 00133 int RTOp_TOp_inv_of_difference_construct( RTOp_value_type alpha, struct RTOp_RTOp* op ) 00134 { 00135 #ifdef RTOp_DEBUG 00136 assert(op); 00137 #endif 00138 op->obj_data = NULL; 00139 op->vtbl = &RTOp_TOp_inv_of_difference_vtbl; 00140 op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data); 00141 return RTOp_TOp_inv_of_difference_init(alpha,op); 00142 } 00143 00144 int RTOp_TOp_inv_of_difference_destroy( struct RTOp_RTOp* op ) 00145 { 00146 op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data); 00147 op->obj_data = NULL; 00148 op->vtbl = NULL; 00149 return 0; 00150 } 00151 00152 int RTOp_TOp_inv_of_difference_init( RTOp_value_type alpha, struct RTOp_RTOp* op ) 00153 { 00154 RTOp_value_type *ptr_alpha = (RTOp_value_type*)op->obj_data; 00155 *ptr_alpha = alpha; 00156 return 0; 00157 } 00158
1.7.4