|
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 /* RTOp_TOp_sign.c */ 00033 00034 #include "RTOp_TOp_sign.h" 00035 #include "RTOp_obj_null_vtbl.h" /* vtbl for operator object instance data */ 00036 00037 /* Implementation functions for RTOp_RTOp */ 00038 00039 static int RTOp_TOp_sign_apply_op( 00040 const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data 00041 , const int num_vecs, const struct RTOp_SubVector vecs[] 00042 , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[] 00043 , RTOp_ReductTarget reduct_obj ) 00044 { 00045 /* */ 00046 /* Declare local variables */ 00047 /* */ 00048 00049 /* Vector data */ 00050 RTOp_index_type sub_dim; 00051 /* z0 */ 00052 RTOp_value_type *z0_val; 00053 ptrdiff_t z0_val_s; 00054 /* v0 */ 00055 const RTOp_value_type *v0_val; 00056 ptrdiff_t v0_val_s; 00057 00058 /* Automatic temporary variables */ 00059 register RTOp_index_type k; 00060 00061 /* */ 00062 /* Validate the input */ 00063 /* */ 00064 if( num_vecs != 1 || ( num_vecs && vecs == NULL ) ) 00065 return RTOp_ERR_INVALID_NUM_VECS; 00066 if( num_targ_vecs != 1 || ( num_targ_vecs && targ_vecs == NULL ) ) 00067 return RTOp_ERR_INVALID_NUM_TARG_VECS; 00068 if( /* Validate sub_dim */ 00069 targ_vecs[0].sub_dim != vecs[0].sub_dim 00070 ) 00071 return RTOp_ERR_INCOMPATIBLE_VECS; 00072 00073 00074 /* */ 00075 /* Get pointers to data */ 00076 /* */ 00077 sub_dim = vecs[0].sub_dim; 00078 /* z0 */ 00079 z0_val = targ_vecs[0].values; 00080 z0_val_s = targ_vecs[0].values_stride; 00081 /* v0 */ 00082 v0_val = vecs[0].values; 00083 v0_val_s = vecs[0].values_stride; 00084 00085 00086 /* */ 00087 /* Apply the operator: */ 00088 /* */ 00089 for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, z0_val += z0_val_s ) 00090 { 00091 /* Element-wise transformation */ 00092 (*z0_val) = ( (*v0_val) == 0.0 ? 0.0 : ( (*v0_val) < 0.0 ? -1.0 : +1.0 ) ); 00093 } 00094 00095 return 0; /* success? */ 00096 } 00097 00098 /* Virtual function table */ 00099 const struct RTOp_RTOp_vtbl_t RTOp_TOp_sign_vtbl = 00100 { 00101 &RTOp_obj_null_vtbl 00102 ,&RTOp_obj_null_vtbl 00103 ,"TOp_sign" 00104 ,NULL 00105 ,RTOp_TOp_sign_apply_op 00106 ,NULL 00107 ,NULL 00108 }; 00109 00110 /* Class specific functions */ 00111 00112 int RTOp_TOp_sign_construct( struct RTOp_RTOp* op ) 00113 { 00114 #ifdef RTOp_DEBUG 00115 assert(op); 00116 #endif 00117 op->obj_data = NULL; 00118 op->vtbl = &RTOp_TOp_sign_vtbl; 00119 op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data); 00120 return 0; 00121 } 00122 00123 int RTOp_TOp_sign_destroy( struct RTOp_RTOp* op ) 00124 { 00125 op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data); 00126 op->obj_data = NULL; 00127 op->vtbl = NULL; 00128 return 0; 00129 } 00130 00131 00132
1.7.4