Simbody 3.9
Loading...
Searching...
No Matches
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#include <initializer_list>
31
32namespace SimTK {
33
34//==============================================================================
35// VECTOR
36//==============================================================================
52template <class ELT> class Vector_ : public VectorBase<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 typedef VectorBase<ELT> Base;
59public:
60 // Uses default destructor.
61
69 Vector_() : Base() {}
70
73 Vector_(const Vector_& src) : Base(src) {}
74
79 Vector_(const Base& src) : Base(src) {} // e.g., VectorView
83 Vector_(const BaseNeg& src) : Base(src) {}
84
89 explicit Vector_(int m) : Base(m) { }
95
96 Vector_(std::initializer_list<ELT> init)
97 : Base(static_cast<int>(init.size()), init.begin()) {}
98
101 Vector_(int m, const ELT& initialValue) : Base(m, initialValue) {}
102
105 template <int M>
106 explicit Vector_(const Vec<M,ELT>& v) : Base(M) {
107 for (int i = 0; i < M; ++i)
108 this->updElt(i, 0) = v(i);
109 }
123 Vector_(int m, const S* cppData, bool)
129 Vector_(int m, S* cppData, bool)
131
135 Vector_(int m, int stride, const S* data, bool)
136 : Base(m, stride, data) {}
140 Vector_(int m, int stride, S* data, bool)
141 : Base(m, stride, data) {}
149 { Base::operator=(src); return*this; }
150
154 template <class EE> Vector_& operator=(const VectorBase<EE>& src)
155 { Base::operator=(src); return*this; }
156
158 Vector_& operator=(const ELT& v) { Base::operator=(v); return *this; }
159
163 template <class EE> Vector_& operator+=(const VectorBase<EE>& m)
164 { Base::operator+=(m); return*this; }
169 template <class EE> Vector_& operator-=(const VectorBase<EE>& m)
170 { Base::operator-=(m); return*this; }
171
174 Vector_& operator*=(const StdNumber& t) { Base::operator*=(t); return *this; }
177 Vector_& operator/=(const StdNumber& t) { Base::operator/=(t); return *this; }
178
183 { this->elementwiseAddScalarInPlace(b); return *this; }
188 { this->elementwiseSubtractScalarInPlace(b); return *this; }
197 std::string toString() const {
198 std::stringstream stream;
199 stream << (*this) ;
200 return stream.str();
201 }
203 const ELT& get(int i) const { return (*this)[i]; }
205 void set(int i, const ELT& value) { (*this)[i]=value; }
208private:
209 // NO DATA MEMBERS ALLOWED
210};
211
212} //namespace SimTK
213
214#endif // SimTK_SIMMATRIX_VECTOR_H_
K::StdNumber StdNumber
Definition CompositeNumericalTypes.h:163
K::TNeg TNeg
Definition CompositeNumericalTypes.h:139
K::Scalar Scalar
Definition CompositeNumericalTypes.h:160
K::Number Number
Definition CompositeNumericalTypes.h:162
@ CppNScalarsPerElement
Definition MatrixBase.h:154
MatrixBase & elementwiseSubtractScalarInPlace(const S &s)
Set M(i,j)-=s for every element of M and some value s.
MatrixBase & elementwiseAddScalarInPlace(const S &s)
Set M(i,j)+=s for every element of M and some value s.
ELT & updElt(int i, int j)
Definition MatrixBase.h:656
This is a fixed-length column vector designed for no-overhead inline computation.
Definition Vec.h:186
This is a dataless rehash of the MatrixBase class to specialize it for Vectors.
Definition VectorBase.h:44
VectorIterator< ELT, VectorBase< ELT > > begin()
Definition VectorBase.h:463
VectorBase & operator/=(const StdNumber &t)
Definition VectorBase.h:151
int size() const
Definition VectorBase.h:401
VectorBase & operator-=(const VectorBase &r)
Definition VectorBase.h:153
VectorBase & operator+=(const VectorBase &r)
Definition VectorBase.h:152
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:143
VectorBase & operator*=(const StdNumber &t)
Definition VectorBase.h:150
This is the vector class intended to appear in user code for large, variable size column vectors.
Definition Vector_.h:52
Vector_()
Default constructor creates a 0x1, reallocatable vector.
Definition Vector_.h:69
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:154
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:94
Vector_(int m)
Construct a Vector_ with a given preallocated size, but with uninitialized values.
Definition Vector_.h:89
Vector_ & operator=(const Vector_ &src)
Copy assignment is deep and can be reallocating if this Vector_ is an owner.
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:177
Vector_ & operator*=(const StdNumber &t)
In-place multiply of each element of this Vector_ by a scalar t.
Definition Vector_.h:174
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:163
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:140
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:123
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:135
Vector_(const Base &src)
This copy constructor serves as an implicit conversion from objects of the base class type (for examp...
Definition Vector_.h:79
const ELT & get(int i) const
Variant of operator[] that's scripting friendly to get ith element.
Definition Vector_.h:203
Vector_ & operator+=(const ELT &b)
In-place add to each element of this Vector_ the same given value b.
Definition Vector_.h:182
std::string toString() const
toString() returns a string representation of the Vector_.
Definition Vector_.h:197
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:106
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:169
Vector_ & operator=(const ELT &v)
Set all elements of this Vector_ to the same value v.
Definition Vector_.h:158
Vector_ & operator-=(const ELT &b)
In-place subtract from each element of this Vector_ the same given value b.
Definition Vector_.h:187
void set(int i, const ELT &value)
Variant of operator[] that's scripting friendly to set ith element.
Definition Vector_.h:205
Vector_(std::initializer_list< ELT > init)
Default constructor creates a 0x1, reallocatable vector.
Definition Vector_.h:96
Vector_(const BaseNeg &src)
This copy constructor serves as an implicit conversion from objects of the base class but with negate...
Definition Vector_.h:83
Vector_(const Vector_ &src)
Copy constructor is deep, that is the source Vector_ is copied, not referenced.
Definition Vector_.h:73
Vector_(int m, S *cppData, bool)
Construct a Vector_ which shares writable, borrowed space with assumed element-to-element stride equa...
Definition Vector_.h:129
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:101
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition Assembler.h:37