|
DenseLinAlgPack: Concreate C++ Classes for Dense Blas-Compatible Linear Algebra Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00005 // Copyright (2003) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 // 00029 00030 // See DenseLinAlgPack_DMatrixOp.hpp for description of naming convensions 00031 00032 #ifndef VECTOROP_H 00033 #define VECTOROP_H 00034 00035 #include "DenseLinAlgPack_DVectorAssign.hpp" 00036 00037 /* * @name {\bf Basic DVector Operation Functions (Level-1 BLAS)}. 00038 * 00039 * These are functions that perform basic operations with vectors such as element-wise 00040 * linear algebra operations (e.g. v1 = v2 + v3, v1 = sin(v2)) and other vector 00041 * related functions. The functions that have vectors as lhs arguments come in 00042 * two varieties: those with a DVector object as the lhs argument (v_lhs), those with 00043 * a DVectorSlice object as a lhs argument (vs_lhs). Having different functions 00044 * for DVector and DVectorSlice objects as lhs arguments is important because 00045 * Vectors resize to the rhs expression while DVectorSlice objects do not. 00046 * 00047 * Only DVectorSlice objects are used as rhs arguments however. When DVector objects 00048 * are used to call these fucntions as rhs arguments, the implicit type conversion 00049 * to a const temp DVectorSlice will be performed to make the call work. 00050 * 00051 * The implementations of these functions takes care of the following details: 00052 * 00053 * <ul> 00054 * <li> Resizing DVector LHS on assignment 00055 * <li> Test for aliasing of assign(...) but not other functions 00056 * <li> Check preconditions (sizes of arguments) if LINALGPACK_CHECK_RHS_SIZES is defined 00057 * </ul> 00058 * 00059 * These functions share common behavior and precondtions which are listed below. 00060 * 00061 * Preconditions for functions with a DVectorSlice object (vs_lhs) as a lhs argument 00062 * (e.g. vs_lhs = abs(vs_rhs), vs_lhs = vs_rhs1 + vs_rhs2). 00063 * <ul> 00064 * <li> #vs_lhs.size() ==# size of rhs expression (throw #std::length_error#) 00065 * </ul> 00066 * 00067 * Preconditions for functions with two DVectorSlice objects (vs_rhs1, vs_rhs2) rhs arguments 00068 * (e.g. v_lhs = pow(vs_rhs1,vs_rhs2), result = trans(vs_rhs1,vs_rhs2)): 00069 * <ul> 00070 * <li> #vs_rhs1.size() == vs_rhs2.size()# (throw #std::length_error#) 00071 * </ul> 00072 * 00073 * Algebric functions are named according to the types of their arguments. For example, 00074 * the function for the operation vs_lhs = vs_rhs1 - vs_rhs2 is named V_VmV(...). 00075 * For a description of this namming format see 00076 * \Ref{LinAlgOpPack} 00077 */ 00078 00079 // @{ 00080 // begin Basic DVector Operation Functions 00081 00082 namespace DenseLinAlgPack { 00083 00084 /* * @name {\bf Algebraic Functions}. 00085 * 00086 * The functions assign(...) are used by the implementation of the assignment operators for 00087 * DVector and DVectorSlice and therefore the user can use the assignment operator to 00088 * perform the copies. 00089 */ 00090 00091 // @{ 00092 // begin Algebraic Functions 00093 00094 00096 void Vp_S(DVectorSlice* vs_lhs, value_type alpha); 00098 void Vt_S(DVectorSlice* vs_lhs, value_type alpha); 00100 void Vp_StV(DVectorSlice* vs_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00101 00103 //void assign(DVector* v_lhs, value_type alpha); 00105 //void assign(DVector* v_lhs, const DVectorSlice& vs_rhs); 00107 void V_VpV(DVector* v_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00109 void V_VmV(DVector* v_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00111 void V_mV(DVector* v_lhs, const DVectorSlice& vs_rhs); 00113 void V_StV(DVector* v_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00114 00116 //void assign(DVectorSlice* vs_lhs, value_type alpha); 00118 //void assign(DVectorSlice* vs_lhs, const DVectorSlice& vx_rhs); 00120 void V_VpV(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00122 void V_VmV(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00124 void V_mV(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00126 void V_StV(DVectorSlice* vs_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00127 00129 /* Apply a plane (Givens) rotation. 00130 * 00131 * [ c s ] * [ x' ] -> [ x' ] 00132 * [ -s c ] [ y' ] [ y' ] 00133 * 00134 * See "Handbook for Matrix Computations" section 2.4 00135 */ 00136 void rot( const value_type c, const value_type s, DVectorSlice* x, DVectorSlice* y ); 00137 00138 // end Algebraic Functions 00139 // @} 00140 00141 /* * @name {\bf Elementwise Math DVector / DVectorSlice Functions}. */ 00142 00143 // @{ 00144 // begin Elementsize Math Functions 00145 00147 void abs(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00149 void asin(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00151 void acos(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00153 void atan(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00155 void atan2(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00157 void atan2(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs, value_type alpha); 00159 void atan2(DVectorSlice* vs_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00161 void cos(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00163 void cosh(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00165 void exp(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00167 void max(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00169 void max(DVectorSlice* vs_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00171 void min(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00173 void min(DVectorSlice* vs_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00175 void pow(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00177 void pow(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs, value_type alpha); 00179 void pow(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs, int n); 00181 void pow(DVectorSlice* vs_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00183 void prod(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00185 void sqrt(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00187 void sin(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00189 void sinh(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00191 void tan(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00193 void tanh(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00194 00196 void abs(DVector* v_lhs, const DVectorSlice& vs_rhs); 00198 void asin(DVector* v_lhs, const DVectorSlice& vs_rhs); 00200 void acos(DVector* v_lhs, const DVectorSlice& vs_rhs); 00202 void atan(DVector* v_lhs, const DVectorSlice& vs_rhs); 00204 void atan2(DVector* v_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00206 void atan2(DVector* v_lhs, const DVectorSlice& vs_rhs, value_type alpha); 00208 void atan2(DVector* v_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00210 void cos(DVector* v_lhs, const DVectorSlice& vs_rhs); 00212 void cosh(DVector* v_lhs, const DVectorSlice& vs_rhs); 00214 void exp(DVector* v_lhs, const DVectorSlice& vs_rhs); 00216 void max(DVector* v_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00218 void max(DVector* v_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00220 void min(DVector* v_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00222 void min(DVector* v_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00224 void pow(DVector* v_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00226 void pow(DVector* v_lhs, const DVectorSlice& vs_rhs, value_type alpha); 00228 void pow(DVector* v_lhs, const DVectorSlice& vs_rhs, int n); 00230 void pow(DVector* v_lhs, value_type alpha, const DVectorSlice& vs_rhs2); 00232 void sqrt(DVector* v_lhs, const DVectorSlice& vs_rhs); 00234 void sin(DVector* v_lhs, const DVectorSlice& vs_rhs); 00236 void sinh(DVector* v_lhs, const DVectorSlice& vs_rhs); 00238 void tan(DVector* v_lhs, const DVectorSlice& vs_rhs); 00240 void tanh(DVector* v_lhs, const DVectorSlice& vs_rhs); 00242 void prod( DVector* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2 ); 00243 00244 // end Elementsize Math Functions 00245 // @} 00246 00247 /* * @name {\bf Scalar Returning and Misc DVectorSlice Functions}. */ 00248 00249 // @{ 00250 // begin Scalar Returning DVectorSlice Functions} 00251 00253 value_type dot(const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00255 value_type max(const DVectorSlice& vs_rhs); 00257 value_type min(const DVectorSlice& vs_rhs); 00259 value_type norm_1(const DVectorSlice& vs_rhs); 00261 value_type norm_2(const DVectorSlice& vs_rhs); 00263 value_type norm_inf(const DVectorSlice& vs_rhs); 00264 00265 // Misc. operations 00266 00268 void swap(DVectorSlice* vs1, DVectorSlice* vs2); 00269 00270 // end Scalar Returning DVectorSlice Functions 00271 // @} 00272 00273 } // end namespace DenseLinAlgPack 00274 00275 // end Basic DVector Operation Functions 00276 // @} 00277 00278 #endif // VECTOROP_H
1.7.4