1#ifndef SimTK_SIMMATRIX_SMALLMATRIX_VEC_H_
2#define SimTK_SIMMATRIX_SMALLMATRIX_VEC_H_
48template <
class E1,
int S1,
class E2,
int S2>
void
50 Vec<1,
typename CNT<E1>::template Result<E2>::Add>& result) {
51 result[0] = r1[0] + r2[0];
53template <
int N,
class E1,
int S1,
class E2,
int S2>
void
55 Vec<N,
typename CNT<E1>::template Result<E2>::Add>& result) {
57 reinterpret_cast<const Vec<N-1,E2,S2
>&>(r2),
58 reinterpret_cast<Vec<N-1,typename CNT<E1>::
59 template Result<E2>::Add
>&>(result));
60 result[N-1] = r1[N-1] + r2[N-1];
63template <
class E1,
int S1,
class E2,
int S2>
void
65 Vec<1,
typename CNT<E1>::template Result<E2>::Sub>& result) {
66 result[0] = r1[0] - r2[0];
68template <
int N,
class E1,
int S1,
class E2,
int S2>
void
70 Vec<N,
typename CNT<E1>::template Result<E2>::Sub>& result) {
72 reinterpret_cast<const Vec<N-1,E2,S2
>&>(r2),
73 reinterpret_cast<Vec<N-1,typename CNT<E1>::
74 template Result<E2>::Sub
>&>(result));
75 result[N-1] = r1[N-1] - r2[N-1];
78template <
class E1,
int S1,
class E2,
int S2>
void
80 Vec<1,
typename CNT<E1>::template Result<E2>::Mul>& result) {
81 result[0] = r1[0] * r2[0];
83template <
int N,
class E1,
int S1,
class E2,
int S2>
void
85 Vec<N,
typename CNT<E1>::template Result<E2>::Mul>& result) {
87 reinterpret_cast<const Vec<N-1,E2,S2
>&>(r2),
88 reinterpret_cast<Vec<N-1,typename CNT<E1>::
89 template Result<E2>::Mul
>&>(result));
90 result[N-1] = r1[N-1] * r2[N-1];
93template <
class E1,
int S1,
class E2,
int S2>
void
95 Vec<1,
typename CNT<E1>::template Result<E2>::Dvd>& result) {
96 result[0] = r1[0] / r2[0];
98template <
int N,
class E1,
int S1,
class E2,
int S2>
void
100 Vec<N,
typename CNT<E1>::template Result<E2>::Dvd>& result) {
102 reinterpret_cast<const Vec<N-1,E2,S2
>&>(r2),
103 reinterpret_cast<Vec<N-1,typename CNT<E1>::
104 template Result<E2>::Dvd
>&>(result));
105 result[N-1] = r1[N-1] / r2[N-1];
108template <
class E1,
int S1,
class E2,
int S2>
void
109copy(Vec<1,E1,S1>& r1,
const Vec<1,E2,S2>& r2) {
112template <
int N,
class E1,
int S1,
class E2,
int S2>
void
113copy(Vec<N,E1,S1>& r1,
const Vec<N,E2,S2>& r2) {
114 copy(
reinterpret_cast<Vec<N-1,E1,S1
>&>(r1),
115 reinterpret_cast<const Vec<N-1,E2,S2
>&>(r2));
185template <
int M,
class ELT,
int STRIDE>
320 static int size() {
return M; }
322 static int nrow() {
return M; }
324 static int ncol() {
return 1; }
392 typedef typename MulOp::Type
Mul;
397 typedef typename MulOpNonConforming::Type
MulNon;
402 typedef typename DvdOp::Type
Dvd;
407 typedef typename AddOp::Type
Add;
412 typedef typename SubOp::Type
Sub;
441 assignElementsFromVec(
src);
448 assignElementsFromVec(
src);
456 assignElementsFromVec(
src);
463 assignElementsFromVec(
src);
468 template <
class EE,
int SS>
470 assignElementsFromVec(
src);
497 { assignElements(
e0,
e1);}
501 { assignElements(
e0,
e1,
e2); }
566 template <
class EE>
explicit Vec(
const EE* p)
584 {
for(
int i=0;
i<M;++
i) d[
i*
STRIDE] +=
r[
i];
return *
this; }
589 {
for(
int i=0;
i<M;++
i) d[
i*
STRIDE] -= -(
r[
i]);
return *
this; }
594 {
for(
int i=0;
i<M;++
i) d[
i*
STRIDE] -=
r[
i];
return *
this; }
599 {
for(
int i=0;
i<M;++
i) d[
i*
STRIDE] += -(
r[
i]);
return *
this; }
678 for (
int i=0;
i<M; ++
i)
722 {
return *
reinterpret_cast<const TPosTrans*
>(
this); }
725 {
return *
reinterpret_cast<TPosTrans*
>(
this); }
744 const EImag* p =
reinterpret_cast<const EImag*
>(
this);
745 return *
reinterpret_cast<const TImag*
>(p+
offs);
752 return *
reinterpret_cast<TImag*
>(p+
offs);
776 for (
int i=0;
i<M; ++
i) result[
i] = (*
this)[
i] * e;
782 for (
int i=0;
i<M; ++
i) result[
i] = e * (*
this)[
i];
791 for (
int i=0;
i<M; ++
i) result[
i] = (*
this)[
i] / e;
797 for (
int i=0;
i<M; ++
i) result[
i] = e / (*
this)[
i];
804 for (
int i=0;
i<M; ++
i) result[
i] = (*
this)[
i] + e;
812 for (
int i=0;
i<M; ++
i) result[
i] = (*
this)[
i] - e;
818 for (
int i=0;
i<M; ++
i) result[
i] = e - (*
this)[
i];
834 {
for(
int i=0;
i<M;++
i) d[
i*
STRIDE] =
ee;
return *
this; }
836 {
for(
int i=0;
i<M;++
i) d[
i*
STRIDE] +=
ee;
return *
this; }
838 {
for(
int i=0;
i<M;++
i) d[
i*
STRIDE] -=
ee;
return *
this; }
842 {
for(
int i=0;
i<M;++
i) d[
i*
STRIDE] *=
ee;
return *
this; }
846 {
for(
int i=0;
i<M;++
i) d[
i*
STRIDE] /=
ee;
return *
this; }
917 for (
int i=0;
i<M-1; ++
i, ++
nxt) {
945 for (
int i=0;
i<M; ++
i, ++
nxt) {
955 {
return *
reinterpret_cast<const Vec*
>(p); }
959 {
return *
reinterpret_cast<Vec*
>(p); }
969 for (
int i=0;
i<M; ++
i)
979 for (
int i=0;
i<M; ++
i) {
980 const ELT& e = (*this)[
i];
993 for (
int i=0;
i<M; ++
i)
1005 template <
class E2,
int RS2>
1007 for (
int i=0;
i<M; ++
i)
1016 template <
class E2,
int RS2>
1030 for (
int i=0;
i<M; ++
i)
1039 std::stringstream
stream;
1046 { (*this)[
i] = value; }
1054 requires (
sizeof...(Idx) == M)
1055 constexpr void assignElementsFromTuple(
1057 std::integer_sequence<int, Idx...>)
1059 (((*this)[
Idx] = std::get<Idx>(
els)) , ...);
1062 template<
typename R,
int...
Idx>
1063 requires (
sizeof...(Idx) == M)
1064 constexpr void assignElementsFromRange(
1066 std::integer_sequence<int, Idx...>)
1071 template <
class EE,
int SS>
1074 assignElementsFromRange(v, std::make_integer_sequence<int, M>{});
1077 template<
typename...
Els>
1078 requires (
sizeof...(Els) == M)
1079 constexpr void assignElements(
Els&&...
els)
1081 assignElementsFromTuple(
1082 std::make_tuple(std::forward<Els>(
els)...),
1083 std::make_integer_sequence<int, M>{}
1098template <
int M,
class E1,
int S1,
class E2,
int S2>
inline
1102 ::AddOp::perform(l,
r);
1106template <
int M,
class E1,
int S1,
class E2,
int S2>
inline
1110 ::SubOp::perform(l,
r);
1114template <
int M,
class E1,
int S1,
class E2,
int S2>
inline bool
1116{
for (
int i=0;
i < M; ++
i)
if (l[
i] !=
r[
i])
return false;
1119template <
int M,
class E1,
int S1,
class E2,
int S2>
inline bool
1123template <
int M,
class E1,
int S1,
class E2>
inline bool
1125{
for (
int i=0;
i < M; ++
i)
if (v[
i] != e)
return false;
1128template <
int M,
class E1,
int S1,
class E2>
inline bool
1132template <
int M,
class E1,
int S1,
class E2,
int S2>
inline bool
1134{
for (
int i=0;
i < M; ++
i)
if (l[
i] >=
r[
i])
return false;
1137template <
int M,
class E1,
int S1,
class E2>
inline bool
1139{
for (
int i=0;
i < M; ++
i)
if (v[
i] >= e)
return false;
1143template <
int M,
class E1,
int S1,
class E2,
int S2>
inline bool
1145{
for (
int i=0;
i < M; ++
i)
if (l[
i] <=
r[
i])
return false;
1148template <
int M,
class E1,
int S1,
class E2>
inline bool
1150{
for (
int i=0;
i < M; ++
i)
if (v[
i] <= e)
return false;
1155template <
int M,
class E1,
int S1,
class E2,
int S2>
inline bool
1157{
for (
int i=0;
i < M; ++
i)
if (l[
i] >
r[
i])
return false;
1161template <
int M,
class E1,
int S1,
class E2>
inline bool
1163{
for (
int i=0;
i < M; ++
i)
if (v[
i] > e)
return false;
1168template <
int M,
class E1,
int S1,
class E2,
int S2>
inline bool
1170{
for (
int i=0;
i < M; ++
i)
if (l[
i] <
r[
i])
return false;
1174template <
int M,
class E1,
int S1,
class E2>
inline bool
1176{
for (
int i=0;
i < M; ++
i)
if (v[
i] < e)
return false;
1190template <
int M,
class E,
int S>
inline
1194template <
int M,
class E,
int S>
inline
1198template <
int M,
class E,
int S>
inline
1202template <
int M,
class E,
int S>
inline
1207template <
int M,
class E,
int S>
inline
1210template <
int M,
class E,
int S>
inline
1217template <
int M,
class E,
int S,
class R>
inline
1221template <
int M,
class E,
int S,
class R>
inline
1226template <
int M,
class E,
int S,
class R>
inline
1229template <
int M,
class E,
int S,
class R>
inline
1234template <
int M,
class E,
int S,
class R>
inline
1237template <
int M,
class E,
int S,
class R>
inline
1247template <
int M,
class E,
int S>
inline
1251template <
int M,
class E,
int S>
inline
1256template <
int M,
class E,
int S>
inline
1260template <
int M,
class E,
int S>
inline
1266template <
int M,
class E,
int S>
inline
1269template <
int M,
class E,
int S>
inline
1277template <
int M,
class E,
int S,
class R>
inline
1281template <
int M,
class E,
int S,
class R>
inline
1287template <
int M,
class E,
int S,
class R>
inline
1290template <
int M,
class E,
int S,
class R>
inline
1295template <
int M,
class E,
int S,
class R>
inline
1298template <
int M,
class E,
int S,
class R>
inline
1310template <
int M,
class E,
int S>
inline
1314template <
int M,
class E,
int S>
inline
1318template <
int M,
class E,
int S>
inline
1322template <
int M,
class E,
int S>
inline
1327template <
int M,
class E,
int S>
inline
1330template <
int M,
class E,
int S>
inline
1337template <
int M,
class E,
int S,
class R>
inline
1341template <
int M,
class E,
int S,
class R>
inline
1346template <
int M,
class E,
int S,
class R>
inline
1349template <
int M,
class E,
int S,
class R>
inline
1354template <
int M,
class E,
int S,
class R>
inline
1357template <
int M,
class E,
int S,
class R>
inline
1364template <
int M,
class E,
int S>
inline
1368template <
int M,
class E,
int S>
inline
1373template <
int M,
class E,
int S>
inline
1377template <
int M,
class E,
int S>
inline
1383template <
int M,
class E,
int S>
inline
1386template <
int M,
class E,
int S>
inline
1394template <
int M,
class E,
int S,
class R>
inline
1398template <
int M,
class E,
int S,
class R>
inline
1404template <
int M,
class E,
int S,
class R>
inline
1407template <
int M,
class E,
int S,
class R>
inline
1412template <
int M,
class E,
int S,
class R>
inline
1415template <
int M,
class E,
int S,
class R>
inline
1420template <
int M,
class E,
int S,
class CHAR,
class TRAITS>
inline
1421std::basic_ostream<CHAR,TRAITS>&
1423 o <<
"~[" << v[0];
for(
int i=1;
i<M;++
i)
o<<
','<<v[
i];
o<<
']';
return o;
1428template <
int M,
class E,
int S,
class CHAR,
class TRAITS>
inline
1429std::basic_istream<CHAR,TRAITS>&
1435 is.unget();
if (
is.fail())
return is;
1446 is.unget();
if (
is.fail())
return is;
1452 is.setstate( std::ios::failbit );
1456 for (
int i=0;
i < M; ++
i) {
1458 if (
is.fail())
return is;
1461 if (
c !=
',')
is.unget();
1462 if (
is.fail())
return is;
1471 is.unget();
if (
is.fail())
return is;
1472 is.setstate( std::ios::failbit );
Mandatory first inclusion for any Simbody source or header file.
#define SimTK_NODISCARD
Warn if a caller fails to capture or use the return value of a method.
Definition SimTKcommon/include/SimTKcommon/internal/common.h:315
Specialized information about Composite Numerical Types which allows us to define appropriate templat...
Definition CompositeNumericalTypes.h:136
static K getNaN()
Definition CompositeNumericalTypes.h:246
K::ULessScalar ULessScalar
Definition CompositeNumericalTypes.h:161
static double getDefaultTolerance()
Definition CompositeNumericalTypes.h:269
K::ScalarNormSq ScalarNormSq
Definition CompositeNumericalTypes.h:166
K::StdNumber StdNumber
Definition CompositeNumericalTypes.h:163
static TSqrt sqrt(const K &t)
Definition CompositeNumericalTypes.h:239
K::TSqHermT TSqHermT
Definition CompositeNumericalTypes.h:146
K::TSqrt TSqrt
Definition CompositeNumericalTypes.h:154
K::TInvert TInvert
Definition CompositeNumericalTypes.h:157
K::TNormalize TNormalize
Definition CompositeNumericalTypes.h:158
K::TWithoutNegator TWithoutNegator
Definition CompositeNumericalTypes.h:140
K::TReal TReal
Definition CompositeNumericalTypes.h:141
static TStandard standardize(const K &t)
Definition CompositeNumericalTypes.h:241
K::THerm THerm
Definition CompositeNumericalTypes.h:144
K::TPosTrans TPosTrans
Definition CompositeNumericalTypes.h:145
K::TNeg TNeg
Definition CompositeNumericalTypes.h:139
K::TStandard TStandard
Definition CompositeNumericalTypes.h:156
K::TComplex TComplex
Definition CompositeNumericalTypes.h:143
K::TSqTHerm TSqTHerm
Definition CompositeNumericalTypes.h:147
K::TImag TImag
Definition CompositeNumericalTypes.h:142
K::Precision Precision
Definition CompositeNumericalTypes.h:164
K::Scalar Scalar
Definition CompositeNumericalTypes.h:160
K::TAbs TAbs
Definition CompositeNumericalTypes.h:155
K::Number Number
Definition CompositeNumericalTypes.h:162
This class represents a small matrix whose size is known at compile time, containing elements of any ...
Definition Mat.h:100
This is a fixed-length row vector designed for no-overhead inline computation.
Definition Row.h:132
This is a small, fixed-size symmetric or Hermitian matrix designed for no-overhead inline computation...
Definition SymMat.h:87
This is a fixed-length column vector designed for no-overhead inline computation.
Definition Vec.h:186
static const Vec & getAs(const ELT *p)
Recast an ordinary C++ array E[] to a const Vec<M,E,S>; assumes compatible length,...
Definition Vec.h:954
Vec & scalarMinusEq(const EE &ee)
Definition Vec.h:837
TSqrt sqrt() const
Elementwise square root; that is, the return value has the same length as this Vec but with each elem...
Definition Vec.h:339
bool isNumericallyEqual(const ELT &e, double tol=getDefaultTolerance()) const
Test whether every element of this vector is numerically equal to the given element,...
Definition Vec.h:1027
void setToNaN()
Set every scalar in this Vec to NaN; this is the default initial value in Debug builds,...
Definition Vec.h:862
static Vec & updAs(ELT *p)
Recast a writable ordinary C++ array E[] to a writable Vec<M,E,S>; assumes compatible length,...
Definition Vec.h:958
CNT< E >::TStandard EStandard
Return type of standardize(E) method; a packed type that can hold the value of an element after elimi...
Definition Vec.h:223
TPosTrans & updPositionalTranspose()
Positional transpose returning a writable reference.
Definition Vec.h:724
Row< M, EHerm, STRIDE > THerm
Type of this Vec after casting to its Hermitian transpose; that is, the Vec turns into a Row and each...
Definition Vec.h:286
CNT< E >::TWithoutNegator EWithoutNegator
Element type, stripped of negator<> if it has one.
Definition Vec.h:197
CNT< E >::Number ENumber
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:232
CNT< E >::TNeg ENeg
Negated version of this Vec's element type; ENeg==negator< E >.
Definition Vec.h:195
bool isInf() const
Return true if any element of this Vec contains a +Infinity or -Infinity somewhere but no element con...
Definition Vec.h:977
Vec< M+1, ELT, 1 > append1(const EE &v) const
Return a vector one larger than this one by adding an element to the end.
Definition Vec.h:927
ELT E
Element type of this Vec.
Definition Vec.h:193
Row< M, E, STRIDE > TPosTrans
Type of this Vec after casting to its positional transpose; that is, the Vec turns into a Row but the...
Definition Vec.h:289
Vec< M, E, STRIDE > T
The type of this Vec.
Definition Vec.h:267
void setToZero()
Set every scalar in this Vec to zero.
Definition Vec.h:867
constexpr Vec(const E &e0, const E &e1, const E &e2, const E &e3)
Definition Vec.h:503
EScalar Scalar
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:310
constexpr Vec(const E &e0, const E &e1, const E &e2, const E &e3, const E &e4, const E &e5)
Definition Vec.h:516
bool isNaN() const
Return true if any element of this Vec contains a NaN anywhere.
Definition Vec.h:968
Mat< M, M, typename CNT< E >::template Result< EE >::Mul > conformingMultiply(const Row< M, EE, SS > &r) const
Same as outer product (m = col*row) – use operator* or outer() instead.
Definition Vec.h:622
std::string toString() const
Print Vec into a string and return it.
Definition Vec.h:1038
Vec & operator-=(const EE &e)
Definition Vec.h:827
CNT< E >::StdNumber EStdNumber
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:233
constexpr Vec(const E &e0, const E &e1, const E &e2, const E &e3, const E &e4, const E &e5, const E &e6)
Definition Vec.h:526
E TElement
Element type of this Vec.
Definition Vec.h:291
Vec & scalarPlusEq(const EE &ee)
Definition Vec.h:835
TInvert invert() const
This method is not supported for Vec objects.
Definition Vec.h:685
CNT< ScalarNormSq >::TSqrt norm() const
Definition Vec.h:660
Vec< M, typename CNT< E >::template Result< EE >::Dvd > scalarDivide(const EE &e) const
Definition Vec.h:789
constexpr Vec(const Vec< M, ENeg, SS > &src)
This is an implicit conversion from a Vec of the same length and negated element type (possibly with ...
Definition Vec.h:462
Vec< M, EComplex, STRIDE > TComplex
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:282
Vec TCol
Type of a column of this CNT object (for a Vec, the whole thing).
Definition Vec.h:295
Vec< M, typename CNT< E >::template Result< EE >::Mul > elementwiseMultiply(const Vec< M, EE, SS > &r) const
Elementwise multiply (Matlab " .* " operator).
Definition Vec.h:630
Vec & scalarMinusEqFromLeft(int ee)
Definition Vec.h:856
const E & get(int i) const
Variant of operator[] that's scripting friendly to get const reference to ith entry.
Definition Vec.h:1049
Vec< M, typename CNT< E >::template Result< EE >::Add > scalarAdd(const EE &e) const
Definition Vec.h:802
Vec< M, EAbs, 1 > TAbs
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:300
const TReal & real() const
Return a reference to the real portion of this Vec if it has complex elements; otherwise the type doe...
Definition Vec.h:731
Vec< M, typename CNT< EE >::template Result< E >::Sub > scalarSubtractFromLeft(const EE &e) const
Definition Vec.h:816
CNT< E >::ULessScalar EULessScalar
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:231
bool isFinite() const
Return true if no element of this Vec contains an Infinity or a NaN anywhere.
Definition Vec.h:992
Vec & operator=(const EE *p)
Assignment to a pointer to elements of any type EE assumes we're pointing at a C++ array of EE's of t...
Definition Vec.h:573
CNT< E >::TNormalize ENormalize
Packed type that can hold the value returned from normalize(E).
Definition Vec.h:228
static int ncol()
The number of columns in a Vec is always 1.
Definition Vec.h:324
constexpr E & operator[](int i)
Select an element of this Vec and return a writable reference to it.
Definition Vec.h:654
constexpr const E & operator()(int i) const
Same as const operator[] above.
Definition Vec.h:649
TNeg & updNegate()
Non-operator version of unary negation; recasts and returns a writable reference.
Definition Vec.h:709
Vec & operator=(const Vec< M, EE, SS > &vv)
Assignment to a conforming Vec, of any element type and stride, provided that the element types are a...
Definition Vec.h:578
constexpr Vec(const Vec< M, E, SS > &src)
This is an implicit conversion from a Vec of the same length and element type but with a different st...
Definition Vec.h:455
Vec< M-1, ELT, 1 > drop1(int p) const
Return a vector one smaller than this one by dropping the element at the indicated position p.
Definition Vec.h:913
Vec(int i)
Given an int value, turn it into a suitable floating point number, convert that to element type E and...
Definition Vec.h:490
constexpr Vec & operator=(const Vec &src)
Copy assignment operator copies the logically-included elements from the source Vec; gaps due to stri...
Definition Vec.h:447
Vec< M, EWithoutNegator, STRIDE > TWithoutNegator
Type of this Vec with negator removed from its element type, if the element is negated.
Definition Vec.h:273
Vec< M, ENormalize, 1 > TNormalize
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:303
Vec< M, typename CNT< EE >::template Result< E >::Mul > scalarMultiplyFromLeft(const EE &e) const
Definition Vec.h:780
TImag & imag()
Recast to show only the imaginary portion of this Vec and return a writable reference.
Definition Vec.h:749
Vec & scalarTimesEqFromLeft(int ee)
Definition Vec.h:857
Vec< M, typename CNT< E >::template Result< EE >::Sub > conformingSubtract(const Vec< M, EE, SS > &r) const
Vector subtraction – use operator- instead.
Definition Vec.h:613
TWithoutNegator & updCastAwayNegatorIfAny()
Recast to remove negators from this Vec's type if present and return a writable reference.
Definition Vec.h:762
constexpr Vec(const Vec &src)
Copy constructor copies the logically-included elements from the source Vec; gaps due to stride are n...
Definition Vec.h:440
static const Vec & getSubVec(const Vec< MM, ELT, STRIDE > &v, int i)
Extract a subvector of type Vec from a longer one that has the same element type and stride,...
Definition Vec.h:897
Vec & operator+=(const EE &e)
Definition Vec.h:826
Vec< M, ESqrt, 1 > TSqrt
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:299
THerm & operator~()
Recast to Hermitian transposed type and return a writable reference; the effect is that writing to el...
Definition Vec.h:703
constexpr Vec(const E &e)
Construction from a single value of this Vec's element type assigns that value to each element.
Definition Vec.h:475
Vec & operator-=(const Vec< M, negator< EE >, SS > &r)
Subtract off a conforming Vec, of any negated element type and stride, provided that the element type...
Definition Vec.h:598
ScalarNormSq scalarNormSqr() const
Scalar norm square is sum( conjugate squares of all underlying scalars ), where conjugate square of s...
Definition Vec.h:329
Vec & scalarMinusEq(int ee)
Definition Vec.h:853
Vec< M, typename CNT< E >::template Result< EE >::Dvd > elementwiseDivide(const Vec< M, EE, SS > &r) const
Elementwise divide (Matlab " ./ " operator).
Definition Vec.h:637
static double getDefaultTolerance()
For approximate comparisons, the default tolerance to use for a vector is the same as its elements' d...
Definition Vec.h:1001
TNormalize normalize() const
If the elements of this Vec are scalars, the result is what you get by dividing each element by the n...
Definition Vec.h:673
const TWithoutNegator & castAwayNegatorIfAny() const
Recast to remove negators from this Vec's type if present; this is handy for simplifying operations w...
Definition Vec.h:758
static Vec< M, ELT, 1 > getNaN()
Return a Vec of the same length and element type as this one but with all elements set to NaN.
Definition Vec.h:965
constexpr const E & operator[](int i) const
Select an element of this Vec and return a const reference to it.
Definition Vec.h:646
Vec< M, typename CNT< E >::template Result< EE >::Add > conformingAdd(const Vec< M, EE, SS > &r) const
Vector addition – use operator+ instead.
Definition Vec.h:606
Vec & scalarEq(const EE &ee)
Definition Vec.h:833
bool isNumericallyEqual(const Vec< M, E2, RS2 > &v, double tol) const
Test whether this vector is numerically equal to some other vector with the same shape,...
Definition Vec.h:1006
Vec< M, typename CNT< E >::template Result< EE >::Sub > scalarSubtract(const EE &e) const
Definition Vec.h:810
ScalarNormSq normSqr() const
Definition Vec.h:658
EStandard sum() const
Sum just adds up all the elements into a single return element that is the same type as this Vec's el...
Definition Vec.h:368
TStandard standardize() const
Return a copy of this Vec but with the underlying scalar type converted (if necessary) to one of the ...
Definition Vec.h:359
Vec< M, typename CNT< EE >::template Result< E >::Dvd > scalarDivideFromLeft(const EE &e) const
Definition Vec.h:795
Vec & scalarMinusEqFromLeft(const EE &ee)
Definition Vec.h:839
const TNeg & negate() const
Non-operator version of unary negation; just a recast.
Definition Vec.h:706
void set(int i, const E &value)
Variant of operator[] that's scripting friendly to set ith entry.
Definition Vec.h:1045
constexpr E & operator()(int i)
Same as non-const operator[] above.
Definition Vec.h:656
CNT< E >::TAbs EAbs
Type required to hold the result of abs(E).
Definition Vec.h:220
Vec & scalarDivideEqFromLeft(int ee)
Definition Vec.h:858
const TNeg & operator-() const
Unary minus recasts this Vec to a type that has the opposite interpretation of the sign but is otherw...
Definition Vec.h:692
Vec & scalarDivideEq(const EE &ee)
Definition Vec.h:845
constexpr Vec(const Vec< M, EE, SS > &src)
Construct a Vec from a Vec of the same length, with any stride.
Definition Vec.h:469
Vec & operator+=(const Vec< M, EE, SS > &r)
Add in a conforming Vec, of any element type and stride, provided that the element types are addition...
Definition Vec.h:583
static int nrow()
The number of rows in a Vec is the number of elements.
Definition Vec.h:322
constexpr Vec(const E &e0, const E &e1, const E &e2)
Definition Vec.h:499
Vec & scalarTimesEq(int ee)
Definition Vec.h:854
Vec(const EE *p)
Construction from a pointer to elements of any type EE assumes we're pointing at a C++ array of EE's ...
Definition Vec.h:566
CNT< E >::TSqHermT ESqHermT
Type of the expression ~E*E (default vector and matrix square; symmetric).
Definition Vec.h:214
CNT< E >::TReal EReal
Type showing just the real part of an element of this Vec if elements are complex; otherwise just the...
Definition Vec.h:200
THerm & updTranspose()
Non-operator version of Hermitian transpose; recasts and returns a writable reference.
Definition Vec.h:715
constexpr Vec(const E &e0, const E &e1, const E &e2, const E &e3, const E &e4)
Definition Vec.h:507
constexpr Vec(const E &e0, const E &e1)
Construct a Vec<M,E> from M elements of type E, etc.
Definition Vec.h:495
CNT< E >::TComplex EComplex
Type that elements would have if complex, if E is currently real; otherwise just the element type E.
Definition Vec.h:207
CNT< E >::TPosTrans EPosTrans
Type of a positional transpose of an element of this Vec.
Definition Vec.h:211
Vec & operator+=(const Vec< M, negator< EE >, SS > &r)
Add in a conforming Vec, of any negated element type and stride, provided that the element types are ...
Definition Vec.h:588
static Vec & updSubVec(Vec< MM, ELT, STRIDE > &v, int i)
Extract a subvector of type Vec from a longer one that has the same element type and stride,...
Definition Vec.h:905
constexpr Vec(const E &e0, const E &e1, const E &e2, const E &e3, const E &e4, const E &e5, const E &e6, const E &e7, const E &e8)
Definition Vec.h:549
TReal & real()
Recast to show only the real portion of this Vec and return a writable reference.
Definition Vec.h:734
CNT< E >::Precision EPrecision
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:234
ESqHermT TSqHermT
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:305
CNT< E >::ScalarNormSq EScalarNormSq
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:235
const TImag & imag() const
Return a reference to the imaginary portion of this Vec if it has complex elements; otherwise the typ...
Definition Vec.h:742
Vec & scalarDivideEqFromLeft(const EE &ee)
Definition Vec.h:847
Vec & operator*=(const EE &e)
Definition Vec.h:828
Vec< M, typename CNT< E >::template Result< EE >::Mul > scalarMultiply(const EE &e) const
Definition Vec.h:774
EScalarNormSq ScalarNormSq
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:315
@ SignInterpretation
Definition Vec.h:259
@ IsStdNumber
Definition Vec.h:257
@ IsULessScalar
Definition Vec.h:255
@ NRows
Definition Vec.h:241
@ ArgDepth
Definition Vec.h:251
@ RealStrideFactor
Definition Vec.h:249
@ ColSpacing
Definition Vec.h:247
@ NPackedElements
Definition Vec.h:243
@ IsNumber
Definition Vec.h:256
@ IsPrecision
Definition Vec.h:258
@ RowSpacing
Definition Vec.h:246
@ NActualElements
Definition Vec.h:244
@ NCols
Definition Vec.h:242
@ ImagOffset
Definition Vec.h:248
@ IsScalar
Definition Vec.h:254
@ NActualScalars
Definition Vec.h:245
CNT< E >::TImag EImag
Type showing the imaginary part of an element of this Vec as real, if elements are complex; otherwise...
Definition Vec.h:204
const TPosTrans & positionalTranspose() const
Positional transpose turns this Vec into a Row but does not transpose the individual elements.
Definition Vec.h:721
TNeg & operator-()
Recast to negated type and return a writable reference; writing to this will cause the negated result...
Definition Vec.h:695
EULessScalar ULessScalar
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:311
Vec< M, EImag, STRIDE *CNT< E >::RealStrideFactor > TImag
Type of this Vec cast to show only the imaginary part of its element; this might affect the stride.
Definition Vec.h:281
Vec & scalarDivideEq(int ee)
Definition Vec.h:855
Vec< M, EStandard, 1 > TStandard
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:301
ENumber Number
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:312
Vec< MM, ELT, STRIDE > & updSubVec(int i)
Extract a writable reference to a sub-Vec with size known at compile time.
Definition Vec.h:887
Vec< M+1, ELT, 1 > insert1(int p, const EE &v) const
Return a vector one larger than this one by inserting an element before the indicated one.
Definition Vec.h:940
CNT< E >::TSqrt ESqrt
Type required to hold the result of sqrt(E).
Definition Vec.h:218
const THerm & operator~() const
The Hermitian transpose operator recasts this Vec to a type that specifies the opposite storage order...
Definition Vec.h:699
Vec< M, ENeg, STRIDE > TNeg
Type this Vec would have if its elements were interpreted as negated.
Definition Vec.h:270
TAbs abs() const
Elementwise absolute value; that is, the return value has the same dimension as this Vec but with eac...
Definition Vec.h:349
constexpr Vec(const E &e0, const E &e1, const E &e2, const E &e3, const E &e4, const E &e5, const E &e6, const E &e7)
Definition Vec.h:537
bool isNumericallyEqual(const Vec< M, E2, RS2 > &v) const
Test whether this vector is numerically equal to some other vector with the same shape,...
Definition Vec.h:1017
static int size()
The number of elements in this Vec (note that stride does not affect this number.)
Definition Vec.h:320
constexpr Vec(const ENeg &ne)
Construction from a single value of this Vec's negated element type assigns that value to each elemen...
Definition Vec.h:481
Row< M, EInvert, 1 > TInvert
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:302
E TRow
Type of a row of this CNT object (for a Vec, just its element type).
Definition Vec.h:293
const Vec & operator+() const
Unary plus does nothing.
Definition Vec.h:688
Vec & scalarTimesEqFromLeft(const EE &ee)
Definition Vec.h:843
Vec & scalarTimesEq(const EE &ee)
Definition Vec.h:841
Vec & scalarPlusEq(int ee)
Definition Vec.h:852
Vec & operator-=(const Vec< M, EE, SS > &r)
Subtract off a conforming Vec, of any element type and stride, provided that the element types are ad...
Definition Vec.h:593
Vec & operator/=(const EE &e)
Definition Vec.h:829
Vec< M, EReal, STRIDE *CNT< E >::RealStrideFactor > TReal
Type of this Vec cast to show only the real part of its element; this might affect the stride.
Definition Vec.h:277
constexpr Vec()
Default construction initializes Vec's elements to NaN when debugging but leaves them uninitialized g...
Definition Vec.h:427
EStdNumber StdNumber
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:313
CNT< E >::TSqTHerm ESqTHerm
Type of the expression E*~E ("row square"; symmetric).
Definition Vec.h:216
CNT< E >::TInvert EInvert
Packed type that can hold the value returned from invert(E), the inverse type of an element.
Definition Vec.h:226
const Vec< MM, ELT, STRIDE > & getSubVec(int i) const
Extract a const reference to a sub-Vec with size known at compile time.
Definition Vec.h:877
CNT< E >::THerm EHerm
Type of the Hermitian transpose of an element of this Vec.
Definition Vec.h:209
EPrecision Precision
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:314
Vec & scalarEq(int ee)
Definition Vec.h:851
const THerm & transpose() const
Non-operator version of Hermitian transpose; just a recast.
Definition Vec.h:712
SymMat< M, ESqTHerm > TSqTHerm
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:306
CNT< E >::Scalar EScalar
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition Vec.h:230
SimTK::conjugate<R> should be instantiated only for float, double.
Definition conjugate.h:178
negator<N>, where N is a number type (real, complex, conjugate), is represented in memory identically...
Definition negator.h:75
NTraits< N >::StdNumber StdNumber
Definition negator.h:107
void copy(Row< 1, E1, S1 > &r1, const Row< 1, E2, S2 > &r2)
Definition Row.h:105
void elementwiseDivide(const Row< 1, E1, S1 > &r1, const Row< 1, E2, S2 > &r2, Row< 1, typename CNT< E1 >::template Result< E2 >::Dvd > &result)
Definition Row.h:90
void conformingSubtract(const Row< 1, E1, S1 > &r1, const Row< 1, E2, S2 > &r2, Row< 1, typename CNT< E1 >::template Result< E2 >::Sub > &result)
Definition Row.h:60
void conformingAdd(const Row< 1, E1, S1 > &r1, const Row< 1, E2, S2 > &r2, Row< 1, typename CNT< E1 >::template Result< E2 >::Add > &result)
Definition Row.h:45
void elementwiseMultiply(const Row< 1, E1, S1 > &r1, const Row< 1, E2, S2 > &r2, Row< 1, typename CNT< E1 >::template Result< E2 >::Mul > &result)
Definition Row.h:75
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition Assembler.h:37
Matrix_< E > operator*(const MatrixBase< E > &l, const typename CNT< E >::StdNumber &r)
Definition BigMatrix.h:605
Matrix_< E > operator/(const MatrixBase< E > &l, const typename CNT< E >::StdNumber &r)
Definition BigMatrix.h:613
std::basic_istream< CHAR, TRAITS > & operator>>(std::basic_istream< CHAR, TRAITS > &is, conjugate< R > &c)
Definition conjugate.h:505
bool operator>(const L &left, const R &right)
Definition SimTKcommon/include/SimTKcommon/internal/common.h:670
@ MAX_RESOLVED_DEPTH
Definition CompositeNumericalTypes.h:120
std::ostream & operator<<(std::ostream &o, const ContactForce &f)
Definition CompliantContactSubsystem.h:387
bool operator>=(const L &left, const R &right)
Definition SimTKcommon/include/SimTKcommon/internal/common.h:682
bool operator<(const Row< N, E1, S1 > &l, const Row< N, E2, S2 > &r)
bool = v1[i] < v2[i], for all elements i
Definition Row.h:822
bool operator<=(const L &left, const R &right)
Definition SimTKcommon/include/SimTKcommon/internal/common.h:676
bool operator==(const PhiMatrix &p1, const PhiMatrix &p2)
Definition SpatialAlgebra.h:791
bool operator!=(const L &left, const R &right)
Definition SimTKcommon/include/SimTKcommon/internal/common.h:664
Vec< M, typename CNT< E >::template Result< P >::Sub, 1 > Sub
Definition Vec.h:383
Vec< M, typename CNT< E >::template Result< P >::Mul, 1 > Mul
Definition Vec.h:380
Vec< M, typename CNT< E >::template Result< P >::Dvd, 1 > Dvd
Definition Vec.h:381
Vec< M, typename CNT< E >::template Result< P >::Add, 1 > Add
Definition Vec.h:382
DvdOp::Type Dvd
Definition Vec.h:402
MulCNTsNonConforming< M, 1, ArgDepth, Vec, ColSpacing, RowSpacing, CNT< P >::NRows, CNT< P >::NCols, CNT< P >::ArgDepth, P, CNT< P >::ColSpacing, CNT< P >::RowSpacing > MulOpNonConforming
Definition Vec.h:396
DvdCNTs< M, 1, ArgDepth, Vec, ColSpacing, RowSpacing, CNT< P >::NRows, CNT< P >::NCols, CNT< P >::ArgDepth, P, CNT< P >::ColSpacing, CNT< P >::RowSpacing > DvdOp
Definition Vec.h:401
AddCNTs< M, 1, ArgDepth, Vec, ColSpacing, RowSpacing, CNT< P >::NRows, CNT< P >::NCols, CNT< P >::ArgDepth, P, CNT< P >::ColSpacing, CNT< P >::RowSpacing > AddOp
Definition Vec.h:406
MulOp::Type Mul
Definition Vec.h:392
MulCNTs< M, 1, ArgDepth, Vec, ColSpacing, RowSpacing, CNT< P >::NRows, CNT< P >::NCols, CNT< P >::ArgDepth, P, CNT< P >::ColSpacing, CNT< P >::RowSpacing > MulOp
Definition Vec.h:391
AddOp::Type Add
Definition Vec.h:407
SubCNTs< M, 1, ArgDepth, Vec, ColSpacing, RowSpacing, CNT< P >::NRows, CNT< P >::NCols, CNT< P >::ArgDepth, P, CNT< P >::ColSpacing, CNT< P >::RowSpacing > SubOp
Definition Vec.h:411
MulOpNonConforming::Type MulNon
Definition Vec.h:397
SubOp::Type Sub
Definition Vec.h:412
Shape-preserving element substitution (always packed).
Definition Vec.h:420
Vec< M, P > Type
Definition Vec.h:421