Simbody  3.6
Vector_.h
Go to the documentation of this file.
1 #ifndef SimTK_SIMMATRIX_VECTOR_H_
2 #define SimTK_SIMMATRIX_VECTOR_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 
30 namespace SimTK {
31 
32 //==============================================================================
33 // VECTOR
34 //==============================================================================
50 template <class ELT> class Vector_ : public VectorBase<ELT> {
51  typedef typename CNT<ELT>::Scalar S;
52  typedef typename CNT<ELT>::Number Number;
53  typedef typename CNT<ELT>::StdNumber StdNumber;
54  typedef typename CNT<ELT>::TNeg ENeg;
55  typedef VectorBase<ELT> Base;
56  typedef VectorBase<ENeg> BaseNeg;
57 public:
58  // Uses default destructor.
59 
67  Vector_() : Base() {}
68 
71  Vector_(const Vector_& src) : Base(src) {}
72 
77  Vector_(const Base& src) : Base(src) {} // e.g., VectorView
81  Vector_(const BaseNeg& src) : Base(src) {}
82 
87  explicit Vector_(int m) : Base(m) { }
92  Vector_(int m, const ELT* cppInitialValues) : Base(m, cppInitialValues) {}
95  Vector_(int m, const ELT& initialValue) : Base(m, initialValue) {}
96 
99  template <int M>
100  explicit Vector_(const Vec<M,ELT>& v) : Base(M) {
101  for (int i = 0; i < M; ++i)
102  this->updElt(i, 0) = v(i);
103  }
117  Vector_(int m, const S* cppData, bool)
118  : Base(m, Base::CppNScalarsPerElement, cppData) {}
123  Vector_(int m, S* cppData, bool)
124  : Base(m, Base::CppNScalarsPerElement, cppData) {}
125 
129  Vector_(int m, int stride, const S* data, bool)
130  : Base(m, stride, data) {}
134  Vector_(int m, int stride, S* data, bool)
135  : Base(m, stride, data) {}
142  Vector_& operator=(const Vector_& src)
143  { Base::operator=(src); return*this; }
144 
148  template <class EE> Vector_& operator=(const VectorBase<EE>& src)
149  { Base::operator=(src); return*this; }
150 
152  Vector_& operator=(const ELT& v) { Base::operator=(v); return *this; }
153 
157  template <class EE> Vector_& operator+=(const VectorBase<EE>& m)
158  { Base::operator+=(m); return*this; }
163  template <class EE> Vector_& operator-=(const VectorBase<EE>& m)
164  { Base::operator-=(m); return*this; }
165 
168  Vector_& operator*=(const StdNumber& t) { Base::operator*=(t); return *this; }
171  Vector_& operator/=(const StdNumber& t) { Base::operator/=(t); return *this; }
172 
176  Vector_& operator+=(const ELT& b)
177  { this->elementwiseAddScalarInPlace(b); return *this; }
181  Vector_& operator-=(const ELT& b)
182  { this->elementwiseSubtractScalarInPlace(b); return *this; }
191  std::string toString() const {
192  std::stringstream stream;
193  stream << (*this) ;
194  return stream.str();
195  }
197  const ELT& get(int i) const { return (*this)[i]; }
199  void set(int i, const ELT& value) { (*this)[i]=value; }
202 private:
203  // NO DATA MEMBERS ALLOWED
204 };
205 
206 } //namespace SimTK
207 
208 #endif // SimTK_SIMMATRIX_VECTOR_H_
Vector_(int m, S *cppData, bool)
Construct a Vector_ which shares writable, borrowed space with assumed element-to-element stride equa...
Definition: Vector_.h:123
VectorBase & operator-=(const VectorBase &r)
Definition: VectorBase.h:148
Vector_ & operator=(const VectorBase< EE > &src)
Like copy assignment but the source can be any object of the base type, even with a different element...
Definition: Vector_.h:148
Vector_ & operator/=(const StdNumber &t)
In-place divide of each element of this Vector_ by a scalar t.
Definition: Vector_.h:171
VectorBase & operator/=(const StdNumber &t)
Definition: VectorBase.h:146
This is the vector class intended to appear in user code for large, variable size column vectors...
Definition: BigMatrix.h:171
Vector_(const Vec< M, ELT > &v)
This constructor creates a new owner Vector_ that is the same length and has a copy of the contents o...
Definition: Vector_.h:100
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
MatrixBase & elementwiseSubtractScalarInPlace(const S &s)
Set M(i,j)-=s for every element of M and some value s.
VectorBase & operator=(const VectorBase &b)
Copy assignment is deep copy but behavior depends on type of lhs: if view, rhs must match...
Definition: VectorBase.h:138
K::Scalar Scalar
Definition: CompositeNumericalTypes.h:160
Vector_ & operator-=(const VectorBase< EE > &m)
In-place subtract of a conforming vector of the base type even if it has a different element type EE...
Definition: Vector_.h:163
ELT & updElt(int i, int j)
Definition: MatrixBase.h:656
Vector_ & operator=(const ELT &v)
Set all elements of this Vector_ to the same value v.
Definition: Vector_.h:152
Vector_(const Vector_ &src)
Copy constructor is deep, that is the source Vector_ is copied, not referenced.
Definition: Vector_.h:71
VectorBase & operator+=(const VectorBase &r)
Definition: VectorBase.h:147
This is a fixed-length column vector designed for no-overhead inline computation. ...
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:618
Vector_ & operator+=(const ELT &b)
In-place add to each element of this Vector_ the same given value b.
Definition: Vector_.h:176
Vector_(int m, int stride, const S *data, bool)
Borrowed-space read-only construction with explicit stride supplied as "number of scalars between ele...
Definition: Vector_.h:129
Vector_(int m)
Construct a Vector_ with a given preallocated size, but with uninitialized values.
Definition: Vector_.h:87
Vector_ & operator-=(const ELT &b)
In-place subtract from each element of this Vector_ the same given value b.
Definition: Vector_.h:181
Vector_ & operator*=(const StdNumber &t)
In-place multiply of each element of this Vector_ by a scalar t.
Definition: Vector_.h:168
Definition: MatrixBase.h:154
MatrixBase & elementwiseAddScalarInPlace(const S &s)
Set M(i,j)+=s for every element of M and some value s.
K::StdNumber StdNumber
Definition: CompositeNumericalTypes.h:163
Vector_(const BaseNeg &src)
This copy constructor serves as an implicit conversion from objects of the base class but with negate...
Definition: Vector_.h:81
Vector_(int m, const ELT &initialValue)
Construct an owner Vector_ of a given size m and initialize all the elements to the given ELT value i...
Definition: Vector_.h:95
Vector_(int m, int stride, S *data, bool)
Borrowed-space writable construction with explicit stride supplied as "number of scalars between elem...
Definition: Vector_.h:134
Vector_(int m, const S *cppData, bool)
Construct a Vector_ which shares read-only, borrowed space with assumed element-to-element stride equ...
Definition: Vector_.h:117
K::TNeg TNeg
Definition: CompositeNumericalTypes.h:139
This is a dataless rehash of the MatrixBase class to specialize it for Vectors.
Definition: BigMatrix.h:164
std::string toString() const
toString() returns a string representation of the Vector_.
Definition: Vector_.h:191
K::Number Number
Definition: CompositeNumericalTypes.h:162
Vector_()
Default constructor creates a 0x1, reallocatable vector.
Definition: Vector_.h:67
Vector_ & operator+=(const VectorBase< EE > &m)
Add in a conforming vector of the base type even if it has a different element type EE...
Definition: Vector_.h:157
Vector_(int m, const ELT *cppInitialValues)
Construct an owner Vector_ of a given size m and initialize it from a C++ array of m ELT values point...
Definition: Vector_.h:92
Vector_ & operator=(const Vector_ &src)
Copy assignment is deep and can be reallocating if this Vector_ is an owner.
Definition: Vector_.h:142
VectorBase & operator*=(const StdNumber &t)
Definition: VectorBase.h:145
Vector_(const Base &src)
This copy constructor serves as an implicit conversion from objects of the base class type (for examp...
Definition: Vector_.h:77