1 #ifndef SimTK_SIMMATRIX_VECTORBASE_H_
2 #define SimTK_SIMMATRIX_VECTORBASE_H_
42 template <
class ELT>
class VectorBase :
public MatrixBase<ELT> {
43 typedef MatrixBase<ELT> Base;
46 typedef typename CNT<ELT>::Scalar Scalar;
47 typedef typename CNT<ELT>::Number Number;
48 typedef typename CNT<ELT>::StdNumber StdNumber;
49 typedef VectorBase<ELT> T;
50 typedef VectorBase<typename CNT<ELT>::TAbs> TAbs;
51 typedef VectorBase<typename CNT<ELT>::TNeg> TNeg;
52 typedef RowVectorView_<typename CNT<ELT>::THerm> THerm;
169 { Base::template rowScaleInPlace<EE>(v);
return *
this; }
183 "Vector::normRMS() only defined for scalar elements.");
184 const int n =
nrow();
186 if (worstOne) *worstOne = -1;
190 ScalarNormSq sumsq = 0;
193 ScalarNormSq maxsq = 0;
194 for (
int i=0; i<n; ++i) {
195 const ScalarNormSq v2 =
square((*
this)[i]);
196 if (v2 > maxsq) maxsq=v2, *worstOne=i;
200 for (
int i=0; i<n; ++i) {
201 const ScalarNormSq v2 =
square((*
this)[i]);
219 "Vector::weightedNormRMS() only defined for scalar elements"
221 const int n =
nrow();
224 if (worstOne) *worstOne = -1;
228 ScalarNormSq sumsq = 0;
231 ScalarNormSq maxsq = 0;
232 for (
int i=0; i<n; ++i) {
233 const ScalarNormSq wv2 =
square(w[i]*(*
this)[i]);
234 if (wv2 > maxsq) maxsq=wv2, *worstOne=i;
238 for (
int i=0; i<n; ++i) {
239 const ScalarNormSq wv2 =
square(w[i]*(*
this)[i]);
254 "Vector::normInf() only defined for scalar elements.");
255 const int n =
nrow();
257 if (worstOne) *worstOne = -1;
264 for (
int i=0; i<n; ++i) {
265 const EAbs a =
std::abs((*
this)[i]);
266 if (a > maxabs) maxabs=a, *worstOne=i;
269 for (
int i=0; i<n; ++i) {
270 const EAbs a =
std::abs((*
this)[i]);
271 if (a > maxabs) maxabs=a;
287 "Vector::weightedNormInf() only defined for scalar elements"
289 const int n =
nrow();
292 if (worstOne) *worstOne = -1;
299 for (
int i=0; i<n; ++i) {
300 const EAbs wv =
std::abs(w[i]*(*
this)[i]);
301 if (wv > maxabs) maxabs=wv, *worstOne=i;
304 for (
int i=0; i<n; ++i) {
305 const EAbs wv =
std::abs(w[i]*(*
this)[i]);
306 if (wv > maxabs) maxabs=wv;
333 { Base::template elementwiseMultiplyInPlace<EE>(r);
return *
this; }
335 { Base::template elementwiseMultiply<EE>(v,out); }
337 {
typename EltResult<EE>::Mul out(
nrow()); Base::template elementwiseMultiply<EE>(v,out);
return out; }
341 { Base::template elementwiseMultiplyFromLeftInPlace<EE>(r);
return *
this; }
342 template <
class EE>
inline void
347 Base::template elementwiseMultiplyFromLeft<EE>(v,out);
353 Base::template elementwiseMultiplyFromLeft<EE>(v,out);
359 { Base::template elementwiseDivideInPlace<EE>(r);
return *
this; }
361 { Base::template elementwiseDivide<EE>(v,out); }
363 {
typename EltResult<EE>::Dvd out(
nrow()); Base::template elementwiseDivide<EE>(v,out);
return out; }
367 { Base::template elementwiseDivideFromLeftInPlace<EE>(r);
return *
this; }
368 template <
class EE>
inline void
373 Base::template elementwiseDivideFromLeft<EE>(v,out);
379 Base::template elementwiseDivideFromLeft<EE>(v,out);
445 const TNeg&
negate()
const {
return *
reinterpret_cast<const TNeg*
>(
this); }
446 TNeg&
updNegate() {
return *
reinterpret_cast<TNeg*
>(
this); }
475 #endif // SimTK_SIMMATRIX_VECTORBASE_H_
THerm transpose() const
Definition: VectorBase.h:435
MatrixView_< EHerm > updTranspose()
Definition: BigMatrix.h:230
VectorBase(MatrixHelperRep< Scalar > *hrep)
Definition: VectorBase.h:467
const VectorBase & operator+() const
Definition: VectorBase.h:441
VectorBase & elementwiseDivideInPlace(const VectorBase< EE > &r)
Definition: VectorBase.h:358
TAbs abs() const
Definition: VectorBase.h:406
TNeg & updNegate()
Definition: VectorBase.h:446
VectorBase & operator=(const ELT &t)
Fill current allocation with copies of element.
Definition: VectorBase.h:162
VectorBase(int m=0)
Default constructor makes a 0x1 matrix locked at 1 column; you can provide an initial allocation if y...
Definition: VectorBase.h:67
const TNeg & operator-() const
Definition: VectorBase.h:448
VectorBase & operator*=(const StdNumber &t)
Definition: VectorBase.h:145
const MatrixHelper< Scalar > & getHelper() const
Definition: MatrixBase.h:865
EAbs normInf(int *worstOne=0) const
Return the infinity norm (max absolute value) of a Vector of scalars, with optional return of the ind...
Definition: VectorBase.h:251
MatrixView_< EHerm > transpose() const
Definition: BigMatrix.h:222
THerm updTranspose()
Definition: VectorBase.h:436
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
K::TSqrt TSqrt
Definition: CompositeNumericalTypes.h:154
VectorView_< ELT > index(const Array_< int > &indices) const
Definition: VectorBase.h:420
static TSqrt sqrt(const K &t)
Definition: CompositeNumericalTypes.h:239
THerm operator~()
Definition: VectorBase.h:439
MatrixBase< typename CNT< E >::TInvert > elementwiseInvert() const
Definition: MatrixBase.h:453
A MatrixCharacter is a set containing a value for each of the matrix characteristics except element t...
Definition: MatrixCharacteristics.h:596
int size() const
Definition: VectorBase.h:396
VectorBase & resizeKeep(int m)
Definition: VectorBase.h:452
VectorBase & operator=(const VectorBase< EE > &b)
Definition: VectorBase.h:151
VectorView_< ELT > operator()(const Array_< int > &indices)
Definition: VectorBase.h:432
VectorBase & rowScaleInPlace(const VectorBase< EE > &v)
There's only one column here so it's a bit weird to use rowScale rather than elementwiseMultiply, but there's nothing really wrong with it.
Definition: VectorBase.h:168
VectorBase< typename CNT< ELT >::TInvert > elementwiseInvert() const
Return out[i]=this[i]^-1 as function return.
Definition: VectorBase.h:325
VectorBase & operator-=(const VectorBase< EE > &b)
Definition: VectorBase.h:155
CNT< ScalarNormSq >::TSqrt weightedNormRMS(const VectorBase< EE > &w, int *worstOne=0) const
Return the weighted root-mean-square (WRMS) norm of a Vector of scalars, with optional return of the ...
Definition: VectorBase.h:216
(Advanced) This class is identical to Matrix_ except that it has shallow (reference) copy and assignm...
Definition: BigMatrix.h:167
VectorBase< typename CNT< ELT >::template Result< P >::Add > Add
Definition: VectorBase.h:132
Definition: Exception.h:297
This is a dataless rehash of the MatrixBase class to specialize it for Vectors.
Definition: BigMatrix.h:164
MatrixBase & operator=(const MatrixBase &b)
Definition: MatrixBase.h:201
VectorBase< typename CNT< ELT >::template Result< P >::Mul > Mul
Definition: VectorBase.h:130
VectorBase(int m, int stride, Scalar *s)
Construct a writable view into existing data.
Definition: VectorBase.h:104
void elementwiseMultiply(const VectorBase< EE > &v, typename EltResult< EE >::Mul &out) const
Definition: VectorBase.h:334
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
MatrixBase & elementwiseInvertInPlace()
Set M(i,j) = M(i,j)^-1.
Definition: BigMatrix.h:361
VectorView_< ELT > operator()(int j) const
Definition: MatrixBase.h:595
ELT & operator[](int i)
Definition: VectorBase.h:410
VectorBase< EE >::template EltResult< ELT >::Mul elementwiseMultiplyFromLeft(const VectorBase< EE > &v) const
Definition: VectorBase.h:350
VectorIterator< ELT, VectorBase< ELT > > end()
Definition: VectorBase.h:461
VectorBase & operator+=(const VectorBase< EE > &b)
Definition: VectorBase.h:153
void elementwiseMultiplyFromLeft(const VectorBase< EE > &v, typename VectorBase< EE >::template EltResult< ELT >::Mul &out) const
Definition: VectorBase.h:343
TNeg & operator-()
Definition: VectorBase.h:449
EAbs weightedNormInf(const VectorBase< EE > &w, int *worstOne=0) const
Return the weighted infinity norm (max absolute value) WInf of a Vector of scalars, with optional return of the index of the weighted element of largest absolute value.
Definition: VectorBase.h:284
ELT & operator()(int i)
Definition: VectorBase.h:412
void elementwiseInvert(VectorBase< typename CNT< ELT >::TInvert > &out) const
Set supplied out[i] = this[i]^-1.
Definition: VectorBase.h:320
MatrixHelper< Scalar > & updHelper()
Definition: MatrixBase.h:866
VectorBase & elementwiseMultiplyFromLeftInPlace(const VectorBase< EE > &r)
Definition: VectorBase.h:340
unsigned char square(unsigned char u)
Definition: Scalar.h:351
MatrixBase & operator*=(const StdNumber &t)
Definition: MatrixBase.h:290
EltResult< EE >::Mul elementwiseMultiply(const VectorBase< EE > &v) const
Definition: VectorBase.h:336
ptrdiff_t nelt() const
Return the number of elements in the logical shape of this matrix.
Definition: MatrixBase.h:148
VectorBase & elementwiseMultiplyInPlace(const VectorBase< EE > &r)
Definition: VectorBase.h:332
VectorBase< typename CNT< ELT >::template Result< P >::Dvd > Dvd
Definition: VectorBase.h:131
VectorView_< ELT > operator()(const Array_< int > &indices) const
Definition: VectorBase.h:431
void elementwiseDivideFromLeft(const VectorBase< EE > &v, typename VectorBase< EE >::template EltResult< ELT >::Dvd &out) const
Definition: VectorBase.h:369
VectorBase(const MatrixHelper< Scalar > &h, const typename MatrixHelper< Scalar >::DeepCopy &d)
Construct a new owner vector initialized with the data from the source.
Definition: VectorBase.h:123
CNT< ScalarNormSq >::TSqrt normRMS(int *worstOne=0) const
Return the root-mean-square (RMS) norm of a Vector of scalars, with optional return of the index of t...
Definition: VectorBase.h:180
VectorIterator< ELT, VectorBase< ELT > > begin()
Definition: VectorBase.h:458
TAbs abs() const
abs() with the result as a function return.
Definition: MatrixBase.h:699
K::TInvert TInvert
Definition: CompositeNumericalTypes.h:157
THerm operator~() const
Definition: VectorBase.h:438
const ELT & operator()(int i) const
Definition: VectorBase.h:411
MatrixBase & operator/=(const StdNumber &t)
Definition: MatrixBase.h:291
MatrixBase & operator+=(const MatrixBase &r)
Definition: MatrixBase.h:292
VectorBase & operator/=(const StdNumber &t)
Definition: VectorBase.h:146
ELEM max(const VectorBase< ELEM > &v)
Definition: VectorMath.h:251
#define SimTK_THROW1(exc, a1)
Definition: Exception.h:311
MatrixBase & resize(int m, int n)
Change the size of this matrix.
Definition: MatrixBase.h:774
void clear()
This restores the MatrixBase to the state it would be in had it been constructed specifying only its ...
Definition: MatrixBase.h:288
VectorView_< ELT > updIndex(const Array_< int > &indices)
Definition: VectorBase.h:425
const TNeg & negate() const
Definition: VectorBase.h:445
void rowScale(const VectorBase< EE > &v, typename EltResult< EE >::Mul &out) const
Definition: VectorBase.h:170
MatrixBase & setTo(const ELT &t)
Fill every element in current allocation with given element (or NaN or 0).
Definition: MatrixBase.h:583
VectorBase & resize(int m)
Definition: VectorBase.h:451
int nrow() const
Return the number of rows m in the logical shape of this matrix.
Definition: MatrixBase.h:137
VectorBase & elementwiseDivideFromLeftInPlace(const VectorBase< EE > &r)
Definition: VectorBase.h:366
VectorBase(int m, const ELT &initialValue)
Construct an owner vector of length m, with each element initialized to the given value...
Definition: VectorBase.h:79
void rowScale(const VectorBase< EE > &r, typename EltResult< EE >::Mul &out) const
Return type is a new matrix which will have the same dimensions as 'this' but will have element types...
void elementwiseDivide(const VectorBase< EE > &v, typename EltResult< EE >::Dvd &out) const
Definition: VectorBase.h:360
VectorBase & elementwiseInvertInPlace()
Set this[i] = this[i]^-1.
Definition: VectorBase.h:314
int ncol() const
Return the number of columns n in the logical shape of this matrix.
Definition: MatrixBase.h:139
const S * getElt(int i, int j) const
RowVectorBase< typename CNT< ELEM >::TAbs > abs(const RowVectorBase< ELEM > &v)
Definition: VectorMath.h:120
MatrixBase & resizeKeep(int m, int n)
Change the size of this matrix, retaining as much of the old data as will fit.
Definition: MatrixBase.h:780
VectorBase & operator-=(const VectorBase &r)
Definition: VectorBase.h:148
Specialized information about Composite Numerical Types which allows us to define appropriate templat...
Definition: CompositeNumericalTypes.h:136
const MatrixCommitment & getCharacterCommitment() const
Definition: MatrixBase.h:119
VectorBase(const TNeg &source)
Implicit conversion from compatible vector with negated elements.
Definition: VectorBase.h:75
VectorBase(const VectorBase &source)
Copy constructor is a deep copy (not appropriate for views!).
Definition: VectorBase.h:72
int nrow() const
Definition: VectorBase.h:401
EltResult< EE >::Dvd elementwiseDivide(const VectorBase< EE > &v) const
Definition: VectorBase.h:362
A MatrixCommitment provides a set of acceptable matrix characteristics.
Definition: MatrixCharacteristics.h:831
MatrixBase & operator-=(const MatrixBase &r)
Definition: MatrixBase.h:293
VectorView_< ELT > operator()(int i, int m) const
Definition: VectorBase.h:415
(Advanced) This class is identical to Vector_ except that it has shallow (reference) copy and assignm...
Definition: BigMatrix.h:170
This is an iterator for iterating over the elements of a Vector_ or Vec object.
Definition: BigMatrix.h:176
VectorBase(const MatrixHelper< Scalar > &h, const typename MatrixHelper< Scalar >::ShallowCopy &s)
Construct a read-only view of the source data.
Definition: VectorBase.h:120
void clear()
Definition: VectorBase.h:455
VectorBase< EE >::template EltResult< ELT >::Dvd elementwiseDivideFromLeft(const VectorBase< EE > &v) const
Definition: VectorBase.h:376
VectorBase(int m, const ELT *cppInitialValues)
Construct an owner vector of length m, with the elements initialized sequentially from a C++ array of...
Definition: VectorBase.h:86
VectorBase & operator+=(const VectorBase &r)
Definition: VectorBase.h:147
VectorBase(int m, int stride, const Scalar *s)
Construct a read-only view of existing data.
Definition: VectorBase.h:101
VectorBase< typename CNT< ELT >::template Result< P >::Sub > Sub
Definition: VectorBase.h:133
VectorView_< ELT > operator()(int i, int m)
Definition: VectorBase.h:416
const ELT & operator[](int i) const
Definition: VectorBase.h:409
ptrdiff_t nelt() const
Definition: VectorBase.h:403
This is the matrix class intended to appear in user code for large, variable size matrices...
Definition: BigMatrix.h:168
EltResult< EE >::Mul rowScale(const VectorBase< EE > &v) const
Definition: VectorBase.h:172
Definition: VectorBase.h:129
int ncol() const
Definition: VectorBase.h:402
EScalarNormSq ScalarNormSq
Definition: MatrixBase.h:101
CNT< E >::TAbs EAbs
Definition: MatrixBase.h:84
VectorBase(MatrixHelper< Scalar > &h, const typename MatrixHelper< Scalar >::ShallowCopy &s)
Construct a writable view into the source data.
Definition: VectorBase.h:117
ELT sum() const
Definition: VectorBase.h:457