MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RTOp_ROp_find_nan_inf.c
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
6 // Copyright (2003) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 #include "RTOp_ROp_find_nan_inf.h"
45 #include "RTOp_obj_null_vtbl.h"
47 #include "check_nan_inf.h"
48 #include "RTOp_get_reduct_op.hpp"
49 
50 /* Implementation functions */
51 
53  const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
54  , const int num_vecs, const struct RTOp_SubVector vecs[]
55  , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
56  , RTOp_ReductTarget targ_obj )
57 {
59  *targ;
60  RTOp_index_type global_offset;
61  RTOp_index_type sub_dim;
62  const RTOp_value_type *v0_val;
63  ptrdiff_t v0_val_s;
65 
66  /* */
67  /* Validate the input */
68  /* */
69  if( num_vecs != 1 )
71  if( num_targ_vecs != 0 )
73  assert(targ_obj);
74  assert(vecs);
75 
76  /* */
77  /* Get pointers to data */
78  /* */
79 
80  /* {value,index} */
81  targ = (struct RTOp_value_index_type*)targ_obj;
82 
83  /* v0 */
84  global_offset = vecs[0].global_offset;
85  sub_dim = vecs[0].sub_dim;
86  v0_val = vecs[0].values;
87  v0_val_s = vecs[0].values_stride;
88 
89  /* */
90  /* Find a NaN or Inf element! */
91  /* */
92 
93  for( i = global_offset + 1; i <= global_offset + sub_dim; ++i, v0_val += v0_val_s ) {
94  if( RTOp_is_nan_inf(*v0_val) && ( targ->index == 0 || i < targ->index ) ) {
95  targ->value = *v0_val;
96  targ->index = i;
97  break;
98  }
99  }
100 
101  return 0; /* success? */
102 }
103 
105  const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data /* Can be NULL! */
106  , RTOp_ReductTarget in_reduct_obj, RTOp_ReductTarget inout_reduct_obj )
107 {
108  const struct RTOp_value_index_type
109  *i_targ = (const struct RTOp_value_index_type*)in_reduct_obj;
110  struct RTOp_value_index_type
111  *io_targ = (struct RTOp_value_index_type*)inout_reduct_obj;
112  if( io_targ->index == 0 || ( i_targ->index != 0 && i_targ->index < io_targ->index ) ) {
113  io_targ->index = i_targ->index;
114  io_targ->value = i_targ->value;
115  }
116  return 0;
117 }
118 
124 
125 /* Virtual function table */
127 {
128  &RTOp_obj_null_vtbl /* use null type for instance data */
129  ,&RTOp_obj_value_index_vtbl /* use {value,index} type for target object */
130  ,"ROp_find_nan_inf"
131  ,NULL
135 };
136 
137 /* Class specific functions */
138 
140 {
141  op->obj_data = NULL;
143  return 0;
144 }
145 
147 {
148  op->obj_data = NULL;
149  op->vtbl = NULL;
150  return 0;
151 }
152 
155 {
156  const struct RTOp_value_index_type *value_index;
157  struct RTOp_ROp_find_nan_inf_reduct_obj_t return_obj;
158 #ifdef RTOp_DEBUG
159  assert(targ_obj != RTOp_REDUCT_OBJ_NULL);
160 #endif
161  value_index = (const struct RTOp_value_index_type*)targ_obj;
162  return_obj.v0_i = value_index->value;
163  return_obj.i = value_index->index;
164  return return_obj;
165 }
ptrdiff_t values_stride
Definition: RTOp.h:305
double RTOp_value_type
Definition: RTOp.h:69
void * RTOp_ReductTarget
Definition: RTOp.h:191
const struct RTOp_RTOp_vtbl_t RTOp_ROp_find_nan_inf_vtbl
RTOp_index_type global_offset
Definition: RTOp.h:299
const struct RTOp_obj_type_vtbl_t RTOp_obj_value_index_vtbl
static int RTOp_ROp_find_nan_inf_apply_op(const struct RTOp_RTOp_vtbl_t *vtbl, const void *obj_data, const int num_vecs, const struct RTOp_SubVector vecs[], const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[], RTOp_ReductTarget targ_obj)
struct RTOp_ROp_find_nan_inf_reduct_obj_t RTOp_ROp_find_nan_inf_val(RTOp_ReductTarget targ_obj)
int(* extract_state)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void *obj, int num_values, RTOp_value_type value_data[], int num_indexes, RTOp_index_type index_data[], int num_chars, RTOp_char_type char_data[])
Definition: RTOp.h:1052
INSERT_GET_REDUCT_OP_FUNCS(1, 1, 0, RTOp_value_index_type, reduce_reduct_objs, RTOp_obj_value_index_vtbl.load_state, RTOp_obj_value_index_vtbl.extract_state, external_reduct_op, get_reduct_op) const struct RTOp_RTOp_vtbl_t RTOp_ROp_find_nan_inf_vtbl
const RTOp_value_type * values
Definition: RTOp.h:303
int RTOp_ROp_find_nan_inf_destroy(struct RTOp_RTOp *op)
static int get_reduct_op(const struct RTOp_RTOp_vtbl_t *vtbl, const void *obj_data, RTOp_reduct_op_func_ptr_t *reduct_op_func_ptr)
#define RTOp_ERR_INVALID_NUM_VECS
Definition: RTOp.h:266
int RTOp_ROp_find_nan_inf_construct(struct RTOp_RTOp *op)
const struct RTOp_obj_type_vtbl_t RTOp_obj_null_vtbl
static int reduce_reduct_objs(const struct RTOp_RTOp_vtbl_t *vtbl, const void *obj_data, RTOp_ReductTarget in_reduct_obj, RTOp_ReductTarget inout_reduct_obj)
void * obj_data
Definition: RTOp.h:800
const struct RTOp_RTOp_vtbl_t * vtbl
Definition: RTOp.h:802
int RTOp_is_nan_inf(RTOp_value_type val)
int(* load_state)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, int num_values, const RTOp_value_type value_data[], int num_indexes, const RTOp_index_type index_data[], int num_chars, const RTOp_char_type char_data[], void **obj)
Definition: RTOp.h:1097
RTOp_index_type sub_dim
Definition: RTOp.h:301
#define RTOp_ERR_INVALID_NUM_TARG_VECS
Definition: RTOp.h:268
static void CALL_API external_reduct_op(void *in_targ_array, void *inout_targ_array, int *len, RTOp_Datatype *datatype)
Teuchos_Ordinal RTOp_index_type
Definition: RTOp.h:68
#define RTOp_REDUCT_OBJ_NULL
Definition: RTOp.h:192