1 #ifndef SimTK_SIMMATRIX_ROWVECTOR_H_ 2 #define SimTK_SIMMATRIX_ROWVECTOR_H_ 3 4 /* -------------------------------------------------------------------------- * 5 * Simbody(tm): SimTKcommon * 6 * -------------------------------------------------------------------------- * 7 * This is part of the SimTK biosimulation toolkit originating from * 8 * Simbios, the NIH National Center for Physics-Based Simulation of * 9 * Biological Structures at Stanford, funded under the NIH Roadmap for * 10 * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. * 11 * * 12 * Portions copyright (c) 2005-13 Stanford University and the Authors. * 13 * Authors: Michael Sherman * 14 * Contributors: * 15 * * 16 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 17 * not use this file except in compliance with the License. You may obtain a * 18 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 19 * * 20 * Unless required by applicable law or agreed to in writing, software * 21 * distributed under the License is distributed on an "AS IS" BASIS, * 22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 23 * See the License for the specific language governing permissions and * 24 * limitations under the License. * 25 * -------------------------------------------------------------------------- */ 26 27 /** @file 28 Define the SimTK::RowVector_ class that is part of Simbody's BigMatrix 29 toolset. **/ 30 31 namespace SimTK { 32 33 //============================================================================== 34 // ROW VECTOR 35 //============================================================================== 36 /** @brief Represents a variable size row vector; much less common than the 37 column vector type Vector_. 38 39 @ingroup MatVecUtilities 40 41 Row vectors are much less commonly used than column vectors; they mostly arise 42 implicitly as the type of a transposed column vector (represented by Simbody's 43 Vector_ class). However, you want to use rows this is the class intended to 44 appear in user code. It can be a fixed-size view of someone else's data, or can 45 be a resizable data owner itself, although of course it will always have just 46 one row. 47 48 @see Row for handling of small, fixed-size row vectors with no runtime overhead 49 @see Matrix_ for variable %size, two-dimensional matrix. 50 @see RowVectorView_, RowVectorBase 51 **/ 52 template <class ELT> class RowVector_ : public RowVectorBase<ELT> { 53 typedef typename CNT<ELT>::Scalar S; 54 typedef typename CNT<ELT>::Number Number; 55 typedef typename CNT<ELT>::StdNumber StdNumber; 56 typedef typename CNT<ELT>::TNeg ENeg; 57 58 typedef RowVectorBase<ELT> Base; 59 typedef RowVectorBase<ENeg> BaseNeg; 60 public: RowVector_()61 RowVector_() : Base() {} // 1x0 reallocatable 62 // Uses default destructor. 63 64 // Copy constructor is deep. RowVector_(const RowVector_ & src)65 RowVector_(const RowVector_& src) : Base(src) {} 66 67 // Implicit conversions. RowVector_(const Base & src)68 RowVector_(const Base& src) : Base(src) {} // e.g., RowVectorView RowVector_(const BaseNeg & src)69 RowVector_(const BaseNeg& src) : Base(src) {} 70 71 // Copy assignment is deep and can be reallocating if this RowVector 72 // has no View. 73 RowVector_& operator=(const RowVector_& src) { 74 Base::operator=(src); return*this; 75 } 76 77 RowVector_(int n)78 explicit RowVector_(int n) : Base(n) { } RowVector_(int n,const ELT * cppInitialValues)79 RowVector_(int n, const ELT* cppInitialValues) : Base(n, cppInitialValues) {} RowVector_(int n,const ELT & initialValue)80 RowVector_(int n, const ELT& initialValue) : Base(n, initialValue) {} 81 82 /// Construct a Vector which uses borrowed space with assumed 83 /// element-to-element stride equal to the C++ element spacing. 84 /// Last parameter is a dummy to avoid overload conflicts when ELT=S; 85 /// pass it as "true". RowVector_(int n,const S * cppData,bool)86 RowVector_(int n, const S* cppData, bool): Base(n, Base::CppNScalarsPerElement, cppData) {} RowVector_(int n,S * cppData,bool)87 RowVector_(int n, S* cppData, bool): Base(n, Base::CppNScalarsPerElement, cppData) {} 88 89 /// Borrowed-space construction with explicit stride supplied as 90 /// "number of scalars between elements". Last parameter is a 91 /// dummy to avoid overload conflicts; pass it as "true". RowVector_(int n,int stride,const S * data,bool)92 RowVector_(int n, int stride, const S* data, bool) : Base(n, stride, data) {} RowVector_(int n,int stride,S * data,bool)93 RowVector_(int n, int stride, S* data, bool) : Base(n, stride, data) {} 94 95 /// Convert a Row to a RowVector_. 96 template <int M> RowVector_(const Row<M,ELT> & v)97 explicit RowVector_(const Row<M,ELT>& v) : Base(M) { 98 for (int i = 0; i < M; ++i) 99 this->updElt(0, i) = v(i); 100 } 101 102 RowVector_& operator=(const ELT& v) { Base::operator=(v); return *this; } 103 104 template <class EE> RowVector_& operator=(const RowVectorBase<EE>& b) 105 { Base::operator=(b); return*this; } 106 template <class EE> RowVector_& operator+=(const RowVectorBase<EE>& b) 107 { Base::operator+=(b); return*this; } 108 template <class EE> RowVector_& operator-=(const RowVectorBase<EE>& b) 109 { Base::operator-=(b); return*this; } 110 111 RowVector_& operator*=(const StdNumber& t) { Base::operator*=(t); return *this; } 112 RowVector_& operator/=(const StdNumber& t) { Base::operator/=(t); return *this; } 113 RowVector_& operator+=(const ELT& b) { this->elementwiseAddScalarInPlace(b); return *this; } 114 RowVector_& operator-=(const ELT& b) { this->elementwiseSubtractScalarInPlace(b); return *this; } 115 116 private: 117 // NO DATA MEMBERS ALLOWED 118 }; 119 120 } //namespace SimTK 121 122 #endif // SimTK_SIMMATRIX_ROWVECTOR_H_ 123