|
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 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 // 00042 00043 // See DenseLinAlgPack_DMatrixOp.hpp for description of naming convensions 00044 00045 #ifndef VECTOROP_H 00046 #define VECTOROP_H 00047 00048 #include "DenseLinAlgPack_DVectorAssign.hpp" 00049 00050 /* * @name {\bf Basic DVector Operation Functions (Level-1 BLAS)}. 00051 * 00052 * These are functions that perform basic operations with vectors such as element-wise 00053 * linear algebra operations (e.g. v1 = v2 + v3, v1 = sin(v2)) and other vector 00054 * related functions. The functions that have vectors as lhs arguments come in 00055 * two varieties: those with a DVector object as the lhs argument (v_lhs), those with 00056 * a DVectorSlice object as a lhs argument (vs_lhs). Having different functions 00057 * for DVector and DVectorSlice objects as lhs arguments is important because 00058 * Vectors resize to the rhs expression while DVectorSlice objects do not. 00059 * 00060 * Only DVectorSlice objects are used as rhs arguments however. When DVector objects 00061 * are used to call these fucntions as rhs arguments, the implicit type conversion 00062 * to a const temp DVectorSlice will be performed to make the call work. 00063 * 00064 * The implementations of these functions takes care of the following details: 00065 * 00066 * <ul> 00067 * <li> Resizing DVector LHS on assignment 00068 * <li> Test for aliasing of assign(...) but not other functions 00069 * <li> Check preconditions (sizes of arguments) if LINALGPACK_CHECK_RHS_SIZES is defined 00070 * </ul> 00071 * 00072 * These functions share common behavior and precondtions which are listed below. 00073 * 00074 * Preconditions for functions with a DVectorSlice object (vs_lhs) as a lhs argument 00075 * (e.g. vs_lhs = abs(vs_rhs), vs_lhs = vs_rhs1 + vs_rhs2). 00076 * <ul> 00077 * <li> #vs_lhs.size() ==# size of rhs expression (throw #std::length_error#) 00078 * </ul> 00079 * 00080 * Preconditions for functions with two DVectorSlice objects (vs_rhs1, vs_rhs2) rhs arguments 00081 * (e.g. v_lhs = pow(vs_rhs1,vs_rhs2), result = trans(vs_rhs1,vs_rhs2)): 00082 * <ul> 00083 * <li> #vs_rhs1.size() == vs_rhs2.size()# (throw #std::length_error#) 00084 * </ul> 00085 * 00086 * Algebric functions are named according to the types of their arguments. For example, 00087 * the function for the operation vs_lhs = vs_rhs1 - vs_rhs2 is named V_VmV(...). 00088 * For a description of this namming format see 00089 * \Ref{LinAlgOpPack} 00090 */ 00091 00092 // @{ 00093 // begin Basic DVector Operation Functions 00094 00095 namespace DenseLinAlgPack { 00096 00097 /* * @name {\bf Algebraic Functions}. 00098 * 00099 * The functions assign(...) are used by the implementation of the assignment operators for 00100 * DVector and DVectorSlice and therefore the user can use the assignment operator to 00101 * perform the copies. 00102 */ 00103 00104 // @{ 00105 // begin Algebraic Functions 00106 00107 00109 void Vp_S(DVectorSlice* vs_lhs, value_type alpha); 00111 void Vt_S(DVectorSlice* vs_lhs, value_type alpha); 00113 void Vp_StV(DVectorSlice* vs_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00114 00116 //void assign(DVector* v_lhs, value_type alpha); 00118 //void assign(DVector* v_lhs, const DVectorSlice& vs_rhs); 00120 void V_VpV(DVector* v_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00122 void V_VmV(DVector* v_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00124 void V_mV(DVector* v_lhs, const DVectorSlice& vs_rhs); 00126 void V_StV(DVector* v_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00127 00129 //void assign(DVectorSlice* vs_lhs, value_type alpha); 00131 //void assign(DVectorSlice* vs_lhs, const DVectorSlice& vx_rhs); 00133 void V_VpV(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00135 void V_VmV(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00137 void V_mV(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00139 void V_StV(DVectorSlice* vs_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00140 00142 /* Apply a plane (Givens) rotation. 00143 * 00144 * [ c s ] * [ x' ] -> [ x' ] 00145 * [ -s c ] [ y' ] [ y' ] 00146 * 00147 * See "Handbook for Matrix Computations" section 2.4 00148 */ 00149 void rot( const value_type c, const value_type s, DVectorSlice* x, DVectorSlice* y ); 00150 00151 // end Algebraic Functions 00152 // @} 00153 00154 /* * @name {\bf Elementwise Math DVector / DVectorSlice Functions}. */ 00155 00156 // @{ 00157 // begin Elementsize Math Functions 00158 00160 void abs(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00162 void asin(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00164 void acos(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00166 void atan(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00168 void atan2(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00170 void atan2(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs, value_type alpha); 00172 void atan2(DVectorSlice* vs_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00174 void cos(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00176 void cosh(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00178 void exp(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00180 void max(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00182 void max(DVectorSlice* vs_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00184 void min(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00186 void min(DVectorSlice* vs_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00188 void pow(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00190 void pow(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs, value_type alpha); 00192 void pow(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs, int n); 00194 void pow(DVectorSlice* vs_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00196 void prod(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00198 void sqrt(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00200 void sin(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00202 void sinh(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00204 void tan(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00206 void tanh(DVectorSlice* vs_lhs, const DVectorSlice& vs_rhs); 00207 00209 void abs(DVector* v_lhs, const DVectorSlice& vs_rhs); 00211 void asin(DVector* v_lhs, const DVectorSlice& vs_rhs); 00213 void acos(DVector* v_lhs, const DVectorSlice& vs_rhs); 00215 void atan(DVector* v_lhs, const DVectorSlice& vs_rhs); 00217 void atan2(DVector* v_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00219 void atan2(DVector* v_lhs, const DVectorSlice& vs_rhs, value_type alpha); 00221 void atan2(DVector* v_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00223 void cos(DVector* v_lhs, const DVectorSlice& vs_rhs); 00225 void cosh(DVector* v_lhs, const DVectorSlice& vs_rhs); 00227 void exp(DVector* v_lhs, const DVectorSlice& vs_rhs); 00229 void max(DVector* v_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00231 void max(DVector* v_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00233 void min(DVector* v_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00235 void min(DVector* v_lhs, value_type alpha, const DVectorSlice& vs_rhs); 00237 void pow(DVector* v_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00239 void pow(DVector* v_lhs, const DVectorSlice& vs_rhs, value_type alpha); 00241 void pow(DVector* v_lhs, const DVectorSlice& vs_rhs, int n); 00243 void pow(DVector* v_lhs, value_type alpha, const DVectorSlice& vs_rhs2); 00245 void sqrt(DVector* v_lhs, const DVectorSlice& vs_rhs); 00247 void sin(DVector* v_lhs, const DVectorSlice& vs_rhs); 00249 void sinh(DVector* v_lhs, const DVectorSlice& vs_rhs); 00251 void tan(DVector* v_lhs, const DVectorSlice& vs_rhs); 00253 void tanh(DVector* v_lhs, const DVectorSlice& vs_rhs); 00255 void prod( DVector* vs_lhs, const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2 ); 00256 00257 // end Elementsize Math Functions 00258 // @} 00259 00260 /* * @name {\bf Scalar Returning and Misc DVectorSlice Functions}. */ 00261 00262 // @{ 00263 // begin Scalar Returning DVectorSlice Functions} 00264 00266 value_type dot(const DVectorSlice& vs_rhs1, const DVectorSlice& vs_rhs2); 00268 value_type max(const DVectorSlice& vs_rhs); 00270 value_type min(const DVectorSlice& vs_rhs); 00272 value_type norm_1(const DVectorSlice& vs_rhs); 00274 value_type norm_2(const DVectorSlice& vs_rhs); 00276 value_type norm_inf(const DVectorSlice& vs_rhs); 00277 00278 // Misc. operations 00279 00281 void swap(DVectorSlice* vs1, DVectorSlice* vs2); 00282 00283 // end Scalar Returning DVectorSlice Functions 00284 // @} 00285 00286 } // end namespace DenseLinAlgPack 00287 00288 // end Basic DVector Operation Functions 00289 // @} 00290 00291 #endif // VECTOROP_H
1.7.6.1