|
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 #include "RTOp_SparseSubVector.h" 00032 00033 void RTOp_sparse_sub_vector( 00034 RTOp_index_type global_offset, RTOp_index_type sub_dim 00035 ,RTOp_index_type sub_nz, const RTOp_value_type values[], ptrdiff_t values_stride 00036 ,const RTOp_index_type indices[], ptrdiff_t indices_stride 00037 ,ptrdiff_t local_offset, int is_sorted 00038 ,struct RTOp_SparseSubVector *sub_vec 00039 ) 00040 { 00041 /* Validate input */ 00042 #ifdef RTOp_DEBUG 00043 assert( sub_vec ); 00044 assert( 00045 ( sub_nz && ( values != NULL && indices != NULL && indices_stride != 0 && sub_nz <= sub_dim ) ) 00046 || !sub_nz || ( sub_nz == sub_dim && indices == NULL ) 00047 ); 00048 #endif 00049 /* Set members */ 00050 sub_vec->global_offset = global_offset; 00051 sub_vec->sub_dim = sub_dim; 00052 sub_vec->sub_nz = sub_nz; 00053 sub_vec->values = values; 00054 sub_vec->values_stride = values_stride; 00055 sub_vec->indices = indices; 00056 sub_vec->indices_stride = indices_stride; 00057 sub_vec->local_offset = local_offset; 00058 sub_vec->is_sorted = is_sorted; 00059 } 00060 00061 void RTOp_sparse_sub_vector_null( struct RTOp_SparseSubVector *sub_vec ) 00062 { 00063 sub_vec->global_offset = 0; 00064 sub_vec->sub_dim = 0; 00065 sub_vec->sub_nz = 0; 00066 sub_vec->values = NULL; 00067 sub_vec->values_stride = 0; 00068 sub_vec->indices = NULL; 00069 sub_vec->indices_stride = 0; 00070 sub_vec->local_offset = 0; 00071 sub_vec->is_sorted = 0; 00072 } 00073 00074 void RTOp_sparse_sub_vector_from_dense( 00075 const struct RTOp_SubVector *sub_vec 00076 ,struct RTOp_SparseSubVector *spc_sub_vec 00077 ) 00078 { 00079 spc_sub_vec->global_offset = sub_vec->global_offset; 00080 spc_sub_vec->sub_dim = sub_vec->sub_dim; 00081 spc_sub_vec->sub_nz = sub_vec->sub_dim; 00082 spc_sub_vec->values = sub_vec->values; 00083 spc_sub_vec->values_stride = sub_vec->values_stride; 00084 spc_sub_vec->indices = NULL; 00085 spc_sub_vec->indices_stride = 0; 00086 spc_sub_vec->local_offset = 0; 00087 spc_sub_vec->is_sorted = 0; 00088 }
1.7.4