RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators Version of the Day
RTOp_TOp_ele_wise_sqrt.c
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 #include <math.h>
00032 
00033 /* ///////////////////////////////////////////// */
00034 /* RTOp_TOp_ele_wise_sqrt.c */
00035 
00036 /* */
00037 /* Note: This file was created automatically by 'new_rtop.pl' */
00038 /*       on 7/2/2002 at 19:1 */
00039 /* */
00040 
00041 #define max(a,b) ( (a) > (b) ? (a) : (b) )
00042 #define min(a,b) ( (a) < (b) ? (a) : (b) )
00043 
00044 #include "RTOp_TOp_ele_wise_sqrt.h"
00045 #include "RTOp_obj_null_vtbl.h"  /* vtbl for operator object instance data */
00046 
00047 
00048 
00049 /* Implementation functions for RTOp_RTOp */
00050 
00051 static int RTOp_TOp_ele_wise_sqrt_apply_op(
00052   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
00053   , const int num_vecs, const struct RTOp_SubVector vecs[]
00054   , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
00055   , RTOp_ReductTarget reduct_obj )
00056 {
00057   /* */
00058   /* Declare local variables */
00059   /* */
00060 
00061   /* Vector data */
00062   RTOp_index_type           sub_dim;
00063   /* z0 */
00064   RTOp_value_type           *z0_val;
00065   ptrdiff_t                 z0_val_s;
00066 
00067   /* Automatic temporary variables */
00068   register RTOp_index_type  k;
00069 
00070   /* */
00071   /* Validate the input */
00072   /* */
00073   if( num_vecs != 0 || ( num_vecs && vecs == NULL ) )
00074     return RTOp_ERR_INVALID_NUM_VECS;
00075   if( num_targ_vecs != 1 || ( num_targ_vecs && targ_vecs == NULL ) )
00076     return RTOp_ERR_INVALID_NUM_TARG_VECS;
00077 
00078 
00079   /* */
00080   /* Get pointers to data */
00081   /* */
00082   sub_dim       = targ_vecs[0].sub_dim;
00083   /* z0 */
00084   z0_val        = targ_vecs[0].values;
00085   z0_val_s      = targ_vecs[0].values_stride;
00086 
00087 
00088   /* */
00089   /* Apply the operator: */
00090   /* */
00091   for( k = 0; k < sub_dim; ++k, z0_val += z0_val_s )
00092     {
00093     /* Element-wise transformation */
00094     assert(*z0_val >= 0);
00095     (*z0_val) = sqrt((*z0_val));
00096     }
00097 
00098   return 0; /* success? */
00099 }
00100 
00101 /* Virtual function table */
00102 const struct RTOp_RTOp_vtbl_t RTOp_TOp_ele_wise_sqrt_vtbl =
00103 {
00104   &RTOp_obj_null_vtbl
00105   ,&RTOp_obj_null_vtbl
00106   ,"TOp_ele_wise_sqrt"
00107   ,NULL
00108   ,RTOp_TOp_ele_wise_sqrt_apply_op
00109   ,NULL
00110   ,NULL
00111 };
00112 
00113 /* Class specific functions */
00114 
00115 int RTOp_TOp_ele_wise_sqrt_construct(  struct RTOp_RTOp* op )
00116 {
00117 #ifdef RTOp_DEBUG
00118   assert(op);
00119 #endif
00120   op->obj_data  = NULL;
00121   op->vtbl      = &RTOp_TOp_ele_wise_sqrt_vtbl;
00122   op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data);
00123   return 0;
00124 }
00125 
00126 int RTOp_TOp_ele_wise_sqrt_destroy( struct RTOp_RTOp* op )
00127 {
00128   op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data);
00129   op->obj_data  = NULL;
00130   op->vtbl      = NULL;
00131   return 0;
00132 }
00133 
00134 
00135 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends