Simbody  3.6
Vec.h
Go to the documentation of this file.
1 #ifndef SimTK_SIMMATRIX_SMALLMATRIX_VEC_H_
2 #define SimTK_SIMMATRIX_SMALLMATRIX_VEC_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-12 Stanford University and the Authors. *
13  * Authors: Michael Sherman *
14  * Contributors: Peter Eastman *
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 
32 
33 namespace SimTK {
34 
35 
36 // The following functions are used internally by Vec.
37 
38 // Hide from Doxygen.
40 namespace Impl {
41 
42 // For those wimpy compilers that don't unroll short, constant-limit loops,
43 // Peter Eastman added these recursive template implementations of
44 // elementwise add, subtract, and copy. Sherm added multiply and divide.
45 
46 template <class E1, int S1, class E2, int S2> void
47 conformingAdd(const Vec<1,E1,S1>& r1, const Vec<1,E2,S2>& r2,
48  Vec<1,typename CNT<E1>::template Result<E2>::Add>& result) {
49  result[0] = r1[0] + r2[0];
50 }
51 template <int N, class E1, int S1, class E2, int S2> void
52 conformingAdd(const Vec<N,E1,S1>& r1, const Vec<N,E2,S2>& r2,
53  Vec<N,typename CNT<E1>::template Result<E2>::Add>& result) {
54  conformingAdd(reinterpret_cast<const Vec<N-1,E1,S1>&>(r1),
55  reinterpret_cast<const Vec<N-1,E2,S2>&>(r2),
56  reinterpret_cast<Vec<N-1,typename CNT<E1>::
57  template Result<E2>::Add>&>(result));
58  result[N-1] = r1[N-1] + r2[N-1];
59 }
60 
61 template <class E1, int S1, class E2, int S2> void
62 conformingSubtract(const Vec<1,E1,S1>& r1, const Vec<1,E2,S2>& r2,
63  Vec<1,typename CNT<E1>::template Result<E2>::Sub>& result) {
64  result[0] = r1[0] - r2[0];
65 }
66 template <int N, class E1, int S1, class E2, int S2> void
67 conformingSubtract(const Vec<N,E1,S1>& r1, const Vec<N,E2,S2>& r2,
68  Vec<N,typename CNT<E1>::template Result<E2>::Sub>& result) {
69  conformingSubtract(reinterpret_cast<const Vec<N-1,E1,S1>&>(r1),
70  reinterpret_cast<const Vec<N-1,E2,S2>&>(r2),
71  reinterpret_cast<Vec<N-1,typename CNT<E1>::
72  template Result<E2>::Sub>&>(result));
73  result[N-1] = r1[N-1] - r2[N-1];
74 }
75 
76 template <class E1, int S1, class E2, int S2> void
77 elementwiseMultiply(const Vec<1,E1,S1>& r1, const Vec<1,E2,S2>& r2,
78  Vec<1,typename CNT<E1>::template Result<E2>::Mul>& result) {
79  result[0] = r1[0] * r2[0];
80 }
81 template <int N, class E1, int S1, class E2, int S2> void
82 elementwiseMultiply(const Vec<N,E1,S1>& r1, const Vec<N,E2,S2>& r2,
83  Vec<N,typename CNT<E1>::template Result<E2>::Mul>& result) {
84  elementwiseMultiply(reinterpret_cast<const Vec<N-1,E1,S1>&>(r1),
85  reinterpret_cast<const Vec<N-1,E2,S2>&>(r2),
86  reinterpret_cast<Vec<N-1,typename CNT<E1>::
87  template Result<E2>::Mul>&>(result));
88  result[N-1] = r1[N-1] * r2[N-1];
89 }
90 
91 template <class E1, int S1, class E2, int S2> void
92 elementwiseDivide(const Vec<1,E1,S1>& r1, const Vec<1,E2,S2>& r2,
93  Vec<1,typename CNT<E1>::template Result<E2>::Dvd>& result) {
94  result[0] = r1[0] / r2[0];
95 }
96 template <int N, class E1, int S1, class E2, int S2> void
97 elementwiseDivide(const Vec<N,E1,S1>& r1, const Vec<N,E2,S2>& r2,
98  Vec<N,typename CNT<E1>::template Result<E2>::Dvd>& result) {
99  elementwiseDivide(reinterpret_cast<const Vec<N-1,E1,S1>&>(r1),
100  reinterpret_cast<const Vec<N-1,E2,S2>&>(r2),
101  reinterpret_cast<Vec<N-1,typename CNT<E1>::
102  template Result<E2>::Dvd>&>(result));
103  result[N-1] = r1[N-1] / r2[N-1];
104 }
105 
106 template <class E1, int S1, class E2, int S2> void
107 copy(Vec<1,E1,S1>& r1, const Vec<1,E2,S2>& r2) {
108  r1[0] = r2[0];
109 }
110 template <int N, class E1, int S1, class E2, int S2> void
111 copy(Vec<N,E1,S1>& r1, const Vec<N,E2,S2>& r2) {
112  copy(reinterpret_cast<Vec<N-1,E1,S1>&>(r1),
113  reinterpret_cast<const Vec<N-1,E2,S2>&>(r2));
114  r1[N-1] = r2[N-1];
115 }
116 
117 }
183 template <int M, class ELT, int STRIDE>
184 class Vec {
185 public:
191  typedef ELT E;
193  typedef typename CNT<E>::TNeg ENeg;
198  typedef typename CNT<E>::TReal EReal;
202  typedef typename CNT<E>::TImag EImag;
205  typedef typename CNT<E>::TComplex EComplex;
207  typedef typename CNT<E>::THerm EHerm;
209  typedef typename CNT<E>::TPosTrans EPosTrans;
212  typedef typename CNT<E>::TSqHermT ESqHermT;
214  typedef typename CNT<E>::TSqTHerm ESqTHerm;
216  typedef typename CNT<E>::TSqrt ESqrt;
218  typedef typename CNT<E>::TAbs EAbs;
221  typedef typename CNT<E>::TStandard EStandard;
224  typedef typename CNT<E>::TInvert EInvert;
226  typedef typename CNT<E>::TNormalize ENormalize;
227 
228  typedef typename CNT<E>::Scalar EScalar;
230  typedef typename CNT<E>::Number ENumber;
231  typedef typename CNT<E>::StdNumber EStdNumber;
232  typedef typename CNT<E>::Precision EPrecision;
234 
237  #ifndef SWIG
238  enum {
239  NRows = M,
240  NCols = 1,
241  NPackedElements = M,
242  NActualElements = M * STRIDE, // includes trailing gap
243  NActualScalars = CNT<E>::NActualScalars * NActualElements,
244  RowSpacing = STRIDE,
245  ColSpacing = NActualElements,
247  RealStrideFactor = 1, // composite types don't change size when
248  // cast from complex to real or imaginary
249  ArgDepth = ((int)CNT<E>::ArgDepth < (int)MAX_RESOLVED_DEPTH
250  ? CNT<E>::ArgDepth + 1
252  IsScalar = 0,
253  IsULessScalar = 0,
254  IsNumber = 0,
255  IsStdNumber = 0,
256  IsPrecision = 0,
257  SignInterpretation = CNT<E>::SignInterpretation
258  };
259  #endif
260 
261  // These are reinterpretations of the current data, so have the
262  // same packing (stride).
263 
289  typedef E TElement;
291  typedef E TRow;
293  typedef Vec TCol;
294 
295  // These are the results of calculations, so are returned in new, packed
296  // memory. Be sure to refer to element types here which are also packed.
297  typedef Vec<M,ESqrt,1> TSqrt; // Note stride
298  typedef Vec<M,EAbs,1> TAbs; // Note stride
302 
303  typedef ESqHermT TSqHermT; // result of self dot product
304  typedef SymMat<M,ESqTHerm> TSqTHerm; // result of self outer product
305 
306  // These recurse right down to the underlying scalar type no matter how
307  // deep the elements are.
308  typedef EScalar Scalar;
309  typedef EULessScalar ULessScalar;
310  typedef ENumber Number;
311  typedef EStdNumber StdNumber;
312  typedef EPrecision Precision;
313  typedef EScalarNormSq ScalarNormSq;
318  static int size() { return M; }
320  static int nrow() { return M; }
322  static int ncol() { return 1; }
323 
324 
327  ScalarNormSq scalarNormSqr() const {
328  ScalarNormSq sum(0);
329  for(int i=0;i<M;++i) sum += CNT<E>::scalarNormSqr(d[i*STRIDE]);
330  return sum;
331  }
332 
337  TSqrt sqrt() const {
338  TSqrt vsqrt;
339  for(int i=0;i<M;++i) vsqrt[i] = CNT<E>::sqrt(d[i*STRIDE]);
340  return vsqrt;
341  }
342 
347  TAbs abs() const {
348  TAbs vabs;
349  for(int i=0;i<M;++i) vabs[i] = CNT<E>::abs(d[i*STRIDE]);
350  return vabs;
351  }
352 
357  TStandard standardize() const {
358  TStandard vstd;
359  for(int i=0;i<M;++i) vstd[i] = CNT<E>::standardize(d[i*STRIDE]);
360  return vstd;
361  }
362 
366  EStandard sum() const {
367  E sum(0);
368  for (int i=0;i<M;++i) sum += d[i*STRIDE];
369  return CNT<E>::standardize(sum);
370  }
371 
372 
373  // This gives the resulting vector type when (v[i] op P) is applied to
374  // each element of v. It is a vector of length M, stride 1, and element
375  // types which are the regular composite result of E op P. Typically P is
376  // a scalar type but it doesn't have to be.
377  template <class P> struct EltResult {
382  };
383 
384  // This is the composite result for v op P where P is some kind of
385  // appropriately shaped non-scalar type.
386  template <class P> struct Result {
387  typedef MulCNTs<M,1,ArgDepth,Vec,ColSpacing,RowSpacing,
390  typedef typename MulOp::Type Mul;
391 
392  typedef MulCNTsNonConforming<M,1,ArgDepth,Vec,ColSpacing,RowSpacing,
393  CNT<P>::NRows, CNT<P>::NCols, CNT<P>::ArgDepth,
394  P, CNT<P>::ColSpacing, CNT<P>::RowSpacing> MulOpNonConforming;
395  typedef typename MulOpNonConforming::Type MulNon;
396 
397  typedef DvdCNTs<M,1,ArgDepth,Vec,ColSpacing,RowSpacing,
398  CNT<P>::NRows, CNT<P>::NCols, CNT<P>::ArgDepth,
399  P, CNT<P>::ColSpacing, CNT<P>::RowSpacing> DvdOp;
400  typedef typename DvdOp::Type Dvd;
401 
402  typedef AddCNTs<M,1,ArgDepth,Vec,ColSpacing,RowSpacing,
403  CNT<P>::NRows, CNT<P>::NCols, CNT<P>::ArgDepth,
404  P, CNT<P>::ColSpacing, CNT<P>::RowSpacing> AddOp;
405  typedef typename AddOp::Type Add;
406 
407  typedef SubCNTs<M,1,ArgDepth,Vec,ColSpacing,RowSpacing,
408  CNT<P>::NRows, CNT<P>::NCols, CNT<P>::ArgDepth,
409  P, CNT<P>::ColSpacing, CNT<P>::RowSpacing> SubOp;
410  typedef typename SubOp::Type Sub;
411  };
412 
418  template <class P> struct Substitute {
419  typedef Vec<M,P> Type;
420  };
421 
425  Vec(){
426  #ifndef NDEBUG
427  setToNaN();
428  #endif
429  }
430 
431  // It's important not to use the default copy constructor or copy
432  // assignment because the compiler doesn't understand that we may
433  // have noncontiguous storage and will try to copy the whole array.
434 
438  Vec(const Vec& src) {
439  Impl::copy(*this, src);
440  }
445  Vec& operator=(const Vec& src) {
446  Impl::copy(*this, src);
447  return *this;
448  }
449 
452  template <int SS> Vec(const Vec<M,E,SS>& src) {
453  Impl::copy(*this, src);
454  }
455 
458  template <int SS> Vec(const Vec<M,ENeg,SS>& src) {
459  Impl::copy(*this, src);
460  }
461 
464  template <class EE, int SS> explicit Vec(const Vec<M,EE,SS>& src) {
465  Impl::copy(*this, src);
466  }
467 
470  explicit Vec(const E& e) {for (int i=0;i<M;++i) d[i*STRIDE]=e;}
471 
476  explicit Vec(const ENeg& ne) {
477  const E e = ne; // requires floating point negation
478  for (int i=0;i<M;++i) d[i*STRIDE]=e;
479  }
480 
485  explicit Vec(int i) {new (this) Vec(E(Precision(i)));}
486 
487  // A bevy of constructors for Vecs up to length 9.
488 
490  Vec(const E& e0,const E& e1)
491  { assert(M==2);(*this)[0]=e0;(*this)[1]=e1; }
492  Vec(const E& e0,const E& e1,const E& e2)
493  { assert(M==3);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2; }
494  Vec(const E& e0,const E& e1,const E& e2,const E& e3)
495  { assert(M==4);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2;(*this)[3]=e3; }
496  Vec(const E& e0,const E& e1,const E& e2,const E& e3,const E& e4)
497  { assert(M==5);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2;
498  (*this)[3]=e3;(*this)[4]=e4; }
499  Vec(const E& e0,const E& e1,const E& e2,const E& e3,const E& e4,const E& e5)
500  { assert(M==6);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2;
501  (*this)[3]=e3;(*this)[4]=e4;(*this)[5]=e5; }
502  Vec(const E& e0,const E& e1,const E& e2,const E& e3,const E& e4,const E& e5, const E& e6)
503  { assert(M==7);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2;
504  (*this)[3]=e3;(*this)[4]=e4;(*this)[5]=e5;(*this)[6]=e6; }
505  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)
506  { assert(M==8);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2;
507  (*this)[3]=e3;(*this)[4]=e4;(*this)[5]=e5;(*this)[6]=e6;(*this)[7]=e7; }
508  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)
509  { assert(M==9);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2;
510  (*this)[3]=e3;(*this)[4]=e4;(*this)[5]=e5;(*this)[6]=e6;(*this)[7]=e7;(*this)[8]=e8; }
511 
516  template <class EE> explicit Vec(const EE* p)
517  { assert(p); for(int i=0;i<M;++i) d[i*STRIDE]=p[i]; }
518 
523  template <class EE> Vec& operator=(const EE* p)
524  { assert(p); for(int i=0;i<M;++i) d[i*STRIDE]=p[i]; return *this; }
525 
528  template <class EE, int SS> Vec& operator=(const Vec<M,EE,SS>& vv)
529  { Impl::copy(*this, vv); return *this; }
530 
533  template <class EE, int SS> Vec& operator+=(const Vec<M,EE,SS>& r)
534  { for(int i=0;i<M;++i) d[i*STRIDE] += r[i]; return *this; }
538  template <class EE, int SS> Vec& operator+=(const Vec<M,negator<EE>,SS>& r)
539  { for(int i=0;i<M;++i) d[i*STRIDE] -= -(r[i]); return *this; }
540 
543  template <class EE, int SS> Vec& operator-=(const Vec<M,EE,SS>& r)
544  { for(int i=0;i<M;++i) d[i*STRIDE] -= r[i]; return *this; }
548  template <class EE, int SS> Vec& operator-=(const Vec<M,negator<EE>,SS>& r)
549  { for(int i=0;i<M;++i) d[i*STRIDE] += -(r[i]); return *this; }
550 
551  // Conforming binary ops with 'this' on left, producing new packed result.
552  // Cases: v=v+v, v=v-v, m=v*r
553 
555  template <class EE, int SS> Vec<M,typename CNT<E>::template Result<EE>::Add>
556  conformingAdd(const Vec<M,EE,SS>& r) const {
557  Vec<M,typename CNT<E>::template Result<EE>::Add> result;
558  Impl::conformingAdd(*this, r, result);
559  return result;
560  }
562  template <class EE, int SS> Vec<M,typename CNT<E>::template Result<EE>::Sub>
564  Vec<M,typename CNT<E>::template Result<EE>::Sub> result;
565  Impl::conformingSubtract(*this, r, result);
566  return result;
567  }
568 
571  template <class EE, int SS> Mat<M,M,typename CNT<E>::template Result<EE>::Mul>
573  Mat<M,M,typename CNT<E>::template Result<EE>::Mul> result;
574  for (int j=0;j<M;++j) result(j) = scalarMultiply(r(j));
575  return result;
576  }
577 
579  template <class EE, int SS> Vec<M,typename CNT<E>::template Result<EE>::Mul>
581  Vec<M,typename CNT<E>::template Result<EE>::Mul> result;
582  Impl::elementwiseMultiply(*this, r, result);
583  return result;
584  }
586  template <class EE, int SS> Vec<M,typename CNT<E>::template Result<EE>::Dvd>
587  elementwiseDivide(const Vec<M,EE,SS>& r) const {
588  Vec<M,typename CNT<E>::template Result<EE>::Dvd> result;
589  Impl::elementwiseDivide(*this, r, result);
590  return result;
591  }
592 
596  const E& operator[](int i) const
597  { assert(0 <= i && i < M); return d[i*STRIDE]; }
599  const E& operator()(int i) const {return (*this)[i];}
600 
604  E& operator[](int i) {assert(0 <= i && i < M); return d[i*STRIDE];}
606  E& operator()(int i) {return (*this)[i];}
607 
608  ScalarNormSq normSqr() const { return scalarNormSqr(); }
609  typename CNT<ScalarNormSq>::TSqrt
610  norm() const { return CNT<ScalarNormSq>::sqrt(scalarNormSqr()); }
611 
623  TNormalize normalize() const {
624  if (CNT<E>::IsScalar) {
625  return castAwayNegatorIfAny() / (SignInterpretation*norm());
626  } else {
627  TNormalize elementwiseNormalized;
628  for (int i=0; i<M; ++i)
629  elementwiseNormalized[i] = CNT<E>::normalize((*this)[i]);
630  return elementwiseNormalized;
631  }
632  }
633 
635  TInvert invert() const {assert(false); return TInvert();} // TODO default inversion
636 
638  const Vec& operator+() const { return *this; }
642  const TNeg& operator-() const { return negate(); }
645  TNeg& operator-() { return updNegate(); }
649  const THerm& operator~() const { return transpose(); }
653  THerm& operator~() { return updTranspose(); }
654 
656  const TNeg& negate() const { return *reinterpret_cast<const TNeg*>(this); }
659  TNeg& updNegate() { return *reinterpret_cast< TNeg*>(this); }
660 
662  const THerm& transpose() const { return *reinterpret_cast<const THerm*>(this); }
665  THerm& updTranspose() { return *reinterpret_cast< THerm*>(this); }
666 
671  const TPosTrans& positionalTranspose() const
672  { return *reinterpret_cast<const TPosTrans*>(this); }
675  { return *reinterpret_cast<TPosTrans*>(this); }
676 
681  const TReal& real() const { return *reinterpret_cast<const TReal*>(this); }
684  TReal& real() { return *reinterpret_cast< TReal*>(this); }
685 
686  // Had to contort these next two routines to get them through VC++ 7.net
687 
692  const TImag& imag() const {
693  const int offs = ImagOffset;
694  const EImag* p = reinterpret_cast<const EImag*>(this);
695  return *reinterpret_cast<const TImag*>(p+offs);
696  }
699  TImag& imag() {
700  const int offs = ImagOffset;
701  EImag* p = reinterpret_cast<EImag*>(this);
702  return *reinterpret_cast<TImag*>(p+offs);
703  }
704 
708  const TWithoutNegator& castAwayNegatorIfAny() const
709  { return *reinterpret_cast<const TWithoutNegator*>(this); }
712  TWithoutNegator& updCastAwayNegatorIfAny()
713  { return *reinterpret_cast<TWithoutNegator*>(this); }
714 
715  // These are elementwise binary operators, (this op ee) by default but
716  // (ee op this) if 'FromLeft' appears in the name. The result is a packed
717  // Vec<M> but the element type may change. These are mostly used to
718  // implement global operators. We call these "scalar" operators but
719  // actually the "scalar" can be a composite type.
720 
721  //TODO: consider converting 'e' to Standard Numbers as precalculation and
722  // changing return type appropriately.
723  template <class EE> Vec<M, typename CNT<E>::template Result<EE>::Mul>
724  scalarMultiply(const EE& e) const {
725  Vec<M, typename CNT<E>::template Result<EE>::Mul> result;
726  for (int i=0; i<M; ++i) result[i] = (*this)[i] * e;
727  return result;
728  }
729  template <class EE> Vec<M, typename CNT<EE>::template Result<E>::Mul>
730  scalarMultiplyFromLeft(const EE& e) const {
731  Vec<M, typename CNT<EE>::template Result<E>::Mul> result;
732  for (int i=0; i<M; ++i) result[i] = e * (*this)[i];
733  return result;
734  }
735 
736  // TODO: should precalculate and store 1/e, while converting to Standard
737  // Numbers. Note that return type should change appropriately.
738  template <class EE> Vec<M, typename CNT<E>::template Result<EE>::Dvd>
739  scalarDivide(const EE& e) const {
740  Vec<M, typename CNT<E>::template Result<EE>::Dvd> result;
741  for (int i=0; i<M; ++i) result[i] = (*this)[i] / e;
742  return result;
743  }
744  template <class EE> Vec<M, typename CNT<EE>::template Result<E>::Dvd>
745  scalarDivideFromLeft(const EE& e) const {
746  Vec<M, typename CNT<EE>::template Result<E>::Dvd> result;
747  for (int i=0; i<M; ++i) result[i] = e / (*this)[i];
748  return result;
749  }
750 
751  template <class EE> Vec<M, typename CNT<E>::template Result<EE>::Add>
752  scalarAdd(const EE& e) const {
753  Vec<M, typename CNT<E>::template Result<EE>::Add> result;
754  for (int i=0; i<M; ++i) result[i] = (*this)[i] + e;
755  return result;
756  }
757  // Add is commutative, so no 'FromLeft'.
758 
759  template <class EE> Vec<M, typename CNT<E>::template Result<EE>::Sub>
760  scalarSubtract(const EE& e) const {
761  Vec<M, typename CNT<E>::template Result<EE>::Sub> result;
762  for (int i=0; i<M; ++i) result[i] = (*this)[i] - e;
763  return result;
764  }
765  template <class EE> Vec<M, typename CNT<EE>::template Result<E>::Sub>
766  scalarSubtractFromLeft(const EE& e) const {
767  Vec<M, typename CNT<EE>::template Result<E>::Sub> result;
768  for (int i=0; i<M; ++i) result[i] = e - (*this)[i];
769  return result;
770  }
771 
772  // Generic assignments for any element type not listed explicitly, including scalars.
773  // These are done repeatedly for each element and only work if the operation can
774  // be performed leaving the original element type.
775  template <class EE> Vec& operator =(const EE& e) {return scalarEq(e);}
776  template <class EE> Vec& operator+=(const EE& e) {return scalarPlusEq(e);}
777  template <class EE> Vec& operator-=(const EE& e) {return scalarMinusEq(e);}
778  template <class EE> Vec& operator*=(const EE& e) {return scalarTimesEq(e);}
779  template <class EE> Vec& operator/=(const EE& e) {return scalarDivideEq(e);}
780 
781  // Generalized element assignment & computed assignment methods. These will work
782  // for any assignment-compatible element, not just scalars.
783  template <class EE> Vec& scalarEq(const EE& ee)
784  { for(int i=0;i<M;++i) d[i*STRIDE] = ee; return *this; }
785  template <class EE> Vec& scalarPlusEq(const EE& ee)
786  { for(int i=0;i<M;++i) d[i*STRIDE] += ee; return *this; }
787  template <class EE> Vec& scalarMinusEq(const EE& ee)
788  { for(int i=0;i<M;++i) d[i*STRIDE] -= ee; return *this; }
789  template <class EE> Vec& scalarMinusEqFromLeft(const EE& ee)
790  { for(int i=0;i<M;++i) d[i*STRIDE] = ee - d[i*STRIDE]; return *this; }
791  template <class EE> Vec& scalarTimesEq(const EE& ee)
792  { for(int i=0;i<M;++i) d[i*STRIDE] *= ee; return *this; }
793  template <class EE> Vec& scalarTimesEqFromLeft(const EE& ee)
794  { for(int i=0;i<M;++i) d[i*STRIDE] = ee * d[i*STRIDE]; return *this; }
795  template <class EE> Vec& scalarDivideEq(const EE& ee)
796  { for(int i=0;i<M;++i) d[i*STRIDE] /= ee; return *this; }
797  template <class EE> Vec& scalarDivideEqFromLeft(const EE& ee)
798  { for(int i=0;i<M;++i) d[i*STRIDE] = ee / d[i*STRIDE]; return *this; }
799 
800  // Specialize for int to avoid warnings and ambiguities.
801  Vec& scalarEq(int ee) {return scalarEq(Precision(ee));}
802  Vec& scalarPlusEq(int ee) {return scalarPlusEq(Precision(ee));}
803  Vec& scalarMinusEq(int ee) {return scalarMinusEq(Precision(ee));}
804  Vec& scalarTimesEq(int ee) {return scalarTimesEq(Precision(ee));}
805  Vec& scalarDivideEq(int ee) {return scalarDivideEq(Precision(ee));}
806  Vec& scalarMinusEqFromLeft(int ee) {return scalarMinusEqFromLeft(Precision(ee));}
807  Vec& scalarTimesEqFromLeft(int ee) {return scalarTimesEqFromLeft(Precision(ee));}
808  Vec& scalarDivideEqFromLeft(int ee) {return scalarDivideEqFromLeft(Precision(ee));}
809 
812  void setToNaN() {
813  (*this) = CNT<ELT>::getNaN();
814  }
815 
817  void setToZero() {
818  (*this) = ELT(0);
819  }
820 
826  template <int MM>
827  const Vec<MM,ELT,STRIDE>& getSubVec(int i) const {
828  assert(0 <= i && i + MM <= M);
829  return Vec<MM,ELT,STRIDE>::getAs(&(*this)[i]);
830  }
836  template <int MM>
838  assert(0 <= i && i + MM <= M);
839  return Vec<MM,ELT,STRIDE>::updAs(&(*this)[i]);
840  }
841 
842 
846  template <int MM>
847  static const Vec& getSubVec(const Vec<MM,ELT,STRIDE>& v, int i) {
848  assert(0 <= i && i + M <= MM);
849  return getAs(&v[i]);
850  }
854  template <int MM>
855  static Vec& updSubVec(Vec<MM,ELT,STRIDE>& v, int i) {
856  assert(0 <= i && i + M <= MM);
857  return updAs(&v[i]);
858  }
859 
863  Vec<M-1,ELT,1> drop1(int p) const {
864  assert(0 <= p && p < M);
865  Vec<M-1,ELT,1> out;
866  int nxt=0;
867  for (int i=0; i<M-1; ++i, ++nxt) {
868  if (nxt==p) ++nxt; // skip the loser
869  out[i] = (*this)[nxt];
870  }
871  return out;
872  }
873 
877  template <class EE> Vec<M+1,ELT,1> append1(const EE& v) const {
878  Vec<M+1,ELT,1> out;
879  Vec<M,ELT,1>::updAs(&out[0]) = (*this);
880  out[M] = v;
881  return out;
882  }
883 
884 
890  template <class EE> Vec<M+1,ELT,1> insert1(int p, const EE& v) const {
891  assert(0 <= p && p <= M);
892  if (p==M) return append1(v);
893  Vec<M+1,ELT,1> out;
894  int nxt=0;
895  for (int i=0; i<M; ++i, ++nxt) {
896  if (i==p) out[nxt++] = v;
897  out[nxt] = (*this)[i];
898  }
899  return out;
900  }
901 
904  static const Vec& getAs(const ELT* p)
905  { return *reinterpret_cast<const Vec*>(p); }
908  static Vec& updAs(ELT* p)
909  { return *reinterpret_cast<Vec*>(p); }
910 
911 
916 
918  bool isNaN() const {
919  for (int i=0; i<M; ++i)
920  if (CNT<ELT>::isNaN((*this)[i]))
921  return true;
922  return false;
923  }
924 
927  bool isInf() const {
928  bool seenInf = false;
929  for (int i=0; i<M; ++i) {
930  const ELT& e = (*this)[i];
931  if (!CNT<ELT>::isFinite(e)) {
932  if (!CNT<ELT>::isInf(e))
933  return false; // something bad was found
934  seenInf = true;
935  }
936  }
937  return seenInf;
938  }
939 
942  bool isFinite() const {
943  for (int i=0; i<M; ++i)
944  if (!CNT<ELT>::isFinite((*this)[i]))
945  return false;
946  return true;
947  }
948 
952 
955  template <class E2, int RS2>
956  bool isNumericallyEqual(const Vec<M,E2,RS2>& v, double tol) const {
957  for (int i=0; i<M; ++i)
958  if (!CNT<ELT>::isNumericallyEqual((*this)[i], v[i], tol))
959  return false;
960  return true;
961  }
962 
966  template <class E2, int RS2>
967  bool isNumericallyEqual(const Vec<M,E2,RS2>& v) const {
968  const double tol = std::max(getDefaultTolerance(),v.getDefaultTolerance());
969  return isNumericallyEqual(v, tol);
970  }
971 
976  bool isNumericallyEqual
977  (const ELT& e,
978  double tol = getDefaultTolerance()) const
979  {
980  for (int i=0; i<M; ++i)
981  if (!CNT<ELT>::isNumericallyEqual((*this)[i], e, tol))
982  return false;
983  return true;
984  }
985 
986  // Functions to be used for Scripting in MATLAB and languages that do not support operator overloading
988  std::string toString() const {
989  std::stringstream stream;
990  stream << (*this);
991  return stream.str();
992  }
993 
995  void set(int i, const E& value)
996  { (*this)[i] = value; }
997 
999  const E& get(int i) const
1000  { return operator[](i); }
1001 
1002 private:
1003  // TODO: should be an array of scalars rather than elements to control
1004  // packing more carefully.
1005  ELT d[NActualElements]; // data
1006 };
1007 
1009 // Global operators involving two vectors. //
1010 // v+v, v-v, v==v, v!=v //
1012 
1013 // v3 = v1 + v2 where all v's have the same length M.
1014 template <int M, class E1, int S1, class E2, int S2> inline
1015 typename Vec<M,E1,S1>::template Result< Vec<M,E2,S2> >::Add
1016 operator+(const Vec<M,E1,S1>& l, const Vec<M,E2,S2>& r) {
1017  return Vec<M,E1,S1>::template Result< Vec<M,E2,S2> >
1018  ::AddOp::perform(l,r);
1019 }
1020 
1021 // v3 = v1 - v2, similar to +
1022 template <int M, class E1, int S1, class E2, int S2> inline
1023 typename Vec<M,E1,S1>::template Result< Vec<M,E2,S2> >::Sub
1024 operator-(const Vec<M,E1,S1>& l, const Vec<M,E2,S2>& r) {
1025  return Vec<M,E1,S1>::template Result< Vec<M,E2,S2> >
1026  ::SubOp::perform(l,r);
1027 }
1028 
1030 template <int M, class E1, int S1, class E2, int S2> inline bool
1032 { for (int i=0; i < M; ++i) if (l[i] != r[i]) return false;
1033  return true; }
1035 template <int M, class E1, int S1, class E2, int S2> inline bool
1036 operator!=(const Vec<M,E1,S1>& l, const Vec<M,E2,S2>& r) {return !(l==r);}
1037 
1039 template <int M, class E1, int S1, class E2> inline bool
1040 operator==(const Vec<M,E1,S1>& v, const E2& e)
1041 { for (int i=0; i < M; ++i) if (v[i] != e) return false;
1042  return true; }
1044 template <int M, class E1, int S1, class E2> inline bool
1045 operator!=(const Vec<M,E1,S1>& v, const E2& e) {return !(v==e);}
1046 
1048 template <int M, class E1, int S1, class E2, int S2> inline bool
1049 operator<(const Vec<M,E1,S1>& l, const Vec<M,E2,S2>& r)
1050 { for (int i=0; i < M; ++i) if (l[i] >= r[i]) return false;
1051  return true; }
1053 template <int M, class E1, int S1, class E2> inline bool
1054 operator<(const Vec<M,E1,S1>& v, const E2& e)
1055 { for (int i=0; i < M; ++i) if (v[i] >= e) return false;
1056  return true; }
1057 
1059 template <int M, class E1, int S1, class E2, int S2> inline bool
1061 { for (int i=0; i < M; ++i) if (l[i] <= r[i]) return false;
1062  return true; }
1064 template <int M, class E1, int S1, class E2> inline bool
1065 operator>(const Vec<M,E1,S1>& v, const E2& e)
1066 { for (int i=0; i < M; ++i) if (v[i] <= e) return false;
1067  return true; }
1068 
1071 template <int M, class E1, int S1, class E2, int S2> inline bool
1072 operator<=(const Vec<M,E1,S1>& l, const Vec<M,E2,S2>& r)
1073 { for (int i=0; i < M; ++i) if (l[i] > r[i]) return false;
1074  return true; }
1077 template <int M, class E1, int S1, class E2> inline bool
1078 operator<=(const Vec<M,E1,S1>& v, const E2& e)
1079 { for (int i=0; i < M; ++i) if (v[i] > e) return false;
1080  return true; }
1081 
1084 template <int M, class E1, int S1, class E2, int S2> inline bool
1086 { for (int i=0; i < M; ++i) if (l[i] < r[i]) return false;
1087  return true; }
1090 template <int M, class E1, int S1, class E2> inline bool
1091 operator>=(const Vec<M,E1,S1>& v, const E2& e)
1092 { for (int i=0; i < M; ++i) if (v[i] < e) return false;
1093  return true; }
1094 
1096 // Global operators involving a vector and a scalar. //
1098 
1099 // I haven't been able to figure out a nice way to templatize for the
1100 // built-in reals without introducing a lot of unwanted type matches
1101 // as well. So we'll just grind them out explicitly here.
1102 
1103 // SCALAR MULTIPLY
1104 
1105 // v = v*real, real*v
1106 template <int M, class E, int S> inline
1107 typename Vec<M,E,S>::template Result<float>::Mul
1108 operator*(const Vec<M,E,S>& l, const float& r)
1109  { return Vec<M,E,S>::template Result<float>::MulOp::perform(l,r); }
1110 template <int M, class E, int S> inline
1111 typename Vec<M,E,S>::template Result<float>::Mul
1112 operator*(const float& l, const Vec<M,E,S>& r) {return r*l;}
1113 
1114 template <int M, class E, int S> inline
1115 typename Vec<M,E,S>::template Result<double>::Mul
1116 operator*(const Vec<M,E,S>& l, const double& r)
1117  { return Vec<M,E,S>::template Result<double>::MulOp::perform(l,r); }
1118 template <int M, class E, int S> inline
1119 typename Vec<M,E,S>::template Result<double>::Mul
1120 operator*(const double& l, const Vec<M,E,S>& r) {return r*l;}
1121 
1122 // v = v*int, int*v -- just convert int to v's precision float
1123 template <int M, class E, int S> inline
1124 typename Vec<M,E,S>::template Result<typename CNT<E>::Precision>::Mul
1125 operator*(const Vec<M,E,S>& l, int r) {return l * (typename CNT<E>::Precision)r;}
1126 template <int M, class E, int S> inline
1127 typename Vec<M,E,S>::template Result<typename CNT<E>::Precision>::Mul
1128 operator*(int l, const Vec<M,E,S>& r) {return r * (typename CNT<E>::Precision)l;}
1129 
1130 // Complex, conjugate, and negator are all easy to templatize.
1131 
1132 // v = v*complex, complex*v
1133 template <int M, class E, int S, class R> inline
1134 typename Vec<M,E,S>::template Result<std::complex<R> >::Mul
1135 operator*(const Vec<M,E,S>& l, const std::complex<R>& r)
1136  { return Vec<M,E,S>::template Result<std::complex<R> >::MulOp::perform(l,r); }
1137 template <int M, class E, int S, class R> inline
1138 typename Vec<M,E,S>::template Result<std::complex<R> >::Mul
1139 operator*(const std::complex<R>& l, const Vec<M,E,S>& r) {return r*l;}
1140 
1141 // v = v*conjugate, conjugate*v (convert conjugate->complex)
1142 template <int M, class E, int S, class R> inline
1143 typename Vec<M,E,S>::template Result<std::complex<R> >::Mul
1144 operator*(const Vec<M,E,S>& l, const conjugate<R>& r) {return l*(std::complex<R>)r;}
1145 template <int M, class E, int S, class R> inline
1146 typename Vec<M,E,S>::template Result<std::complex<R> >::Mul
1147 operator*(const conjugate<R>& l, const Vec<M,E,S>& r) {return r*(std::complex<R>)l;}
1148 
1149 // v = v*negator, negator*v: convert negator to standard number
1150 template <int M, class E, int S, class R> inline
1151 typename Vec<M,E,S>::template Result<typename negator<R>::StdNumber>::Mul
1152 operator*(const Vec<M,E,S>& l, const negator<R>& r) {return l * (typename negator<R>::StdNumber)(R)r;}
1153 template <int M, class E, int S, class R> inline
1154 typename Vec<M,E,S>::template Result<typename negator<R>::StdNumber>::Mul
1155 operator*(const negator<R>& l, const Vec<M,E,S>& r) {return r * (typename negator<R>::StdNumber)(R)l;}
1156 
1157 
1158 // SCALAR DIVIDE. This is a scalar operation when the scalar is on the right,
1159 // but when it is on the left it means scalar * pseudoInverse(vec), which is
1160 // a row.
1161 
1162 // v = v/real, real/v
1163 template <int M, class E, int S> inline
1164 typename Vec<M,E,S>::template Result<float>::Dvd
1165 operator/(const Vec<M,E,S>& l, const float& r)
1166  { return Vec<M,E,S>::template Result<float>::DvdOp::perform(l,r); }
1167 template <int M, class E, int S> inline
1168 typename CNT<float>::template Result<Vec<M,E,S> >::Dvd
1169 operator/(const float& l, const Vec<M,E,S>& r)
1170  { return CNT<float>::template Result<Vec<M,E,S> >::DvdOp::perform(l,r); }
1171 
1172 template <int M, class E, int S> inline
1173 typename Vec<M,E,S>::template Result<double>::Dvd
1174 operator/(const Vec<M,E,S>& l, const double& r)
1175  { return Vec<M,E,S>::template Result<double>::DvdOp::perform(l,r); }
1176 template <int M, class E, int S> inline
1177 typename CNT<double>::template Result<Vec<M,E,S> >::Dvd
1178 operator/(const double& l, const Vec<M,E,S>& r)
1179  { return CNT<double>::template Result<Vec<M,E,S> >::DvdOp::perform(l,r); }
1180 
1181 // v = v/int, int/v -- just convert int to v's precision float
1182 template <int M, class E, int S> inline
1183 typename Vec<M,E,S>::template Result<typename CNT<E>::Precision>::Dvd
1184 operator/(const Vec<M,E,S>& l, int r) {return l / (typename CNT<E>::Precision)r;}
1185 template <int M, class E, int S> inline
1186 typename CNT<typename CNT<E>::Precision>::template Result<Vec<M,E,S> >::Dvd
1187 operator/(int l, const Vec<M,E,S>& r) {return (typename CNT<E>::Precision)l / r;}
1188 
1189 
1190 // Complex, conjugate, and negator are all easy to templatize.
1191 
1192 // v = v/complex, complex/v
1193 template <int M, class E, int S, class R> inline
1194 typename Vec<M,E,S>::template Result<std::complex<R> >::Dvd
1195 operator/(const Vec<M,E,S>& l, const std::complex<R>& r)
1196  { return Vec<M,E,S>::template Result<std::complex<R> >::DvdOp::perform(l,r); }
1197 template <int M, class E, int S, class R> inline
1198 typename CNT<std::complex<R> >::template Result<Vec<M,E,S> >::Dvd
1199 operator/(const std::complex<R>& l, const Vec<M,E,S>& r)
1200  { return CNT<std::complex<R> >::template Result<Vec<M,E,S> >::DvdOp::perform(l,r); }
1201 
1202 // v = v/conjugate, conjugate/v (convert conjugate->complex)
1203 template <int M, class E, int S, class R> inline
1204 typename Vec<M,E,S>::template Result<std::complex<R> >::Dvd
1205 operator/(const Vec<M,E,S>& l, const conjugate<R>& r) {return l/(std::complex<R>)r;}
1206 template <int M, class E, int S, class R> inline
1207 typename CNT<std::complex<R> >::template Result<Vec<M,E,S> >::Dvd
1208 operator/(const conjugate<R>& l, const Vec<M,E,S>& r) {return (std::complex<R>)l/r;}
1209 
1210 // v = v/negator, negator/v: convert negator to number
1211 template <int M, class E, int S, class R> inline
1212 typename Vec<M,E,S>::template Result<typename negator<R>::StdNumber>::Dvd
1213 operator/(const Vec<M,E,S>& l, const negator<R>& r) {return l/(typename negator<R>::StdNumber)(R)r;}
1214 template <int M, class E, int S, class R> inline
1215 typename CNT<R>::template Result<Vec<M,E,S> >::Dvd
1216 operator/(const negator<R>& l, const Vec<M,E,S>& r) {return (typename negator<R>::StdNumber)(R)l/r;}
1217 
1218 
1219 // Add and subtract are odd as scalar ops. They behave as though the
1220 // scalar stands for a vector each of whose elements is that scalar,
1221 // and then a normal vector add or subtract is done.
1222 
1223 // SCALAR ADD
1224 
1225 // v = v+real, real+v
1226 template <int M, class E, int S> inline
1227 typename Vec<M,E,S>::template Result<float>::Add
1228 operator+(const Vec<M,E,S>& l, const float& r)
1229  { return Vec<M,E,S>::template Result<float>::AddOp::perform(l,r); }
1230 template <int M, class E, int S> inline
1231 typename Vec<M,E,S>::template Result<float>::Add
1232 operator+(const float& l, const Vec<M,E,S>& r) {return r+l;}
1233 
1234 template <int M, class E, int S> inline
1235 typename Vec<M,E,S>::template Result<double>::Add
1236 operator+(const Vec<M,E,S>& l, const double& r)
1237  { return Vec<M,E,S>::template Result<double>::AddOp::perform(l,r); }
1238 template <int M, class E, int S> inline
1239 typename Vec<M,E,S>::template Result<double>::Add
1240 operator+(const double& l, const Vec<M,E,S>& r) {return r+l;}
1241 
1242 // v = v+int, int+v -- just convert int to v's precision float
1243 template <int M, class E, int S> inline
1244 typename Vec<M,E,S>::template Result<typename CNT<E>::Precision>::Add
1245 operator+(const Vec<M,E,S>& l, int r) {return l + (typename CNT<E>::Precision)r;}
1246 template <int M, class E, int S> inline
1247 typename Vec<M,E,S>::template Result<typename CNT<E>::Precision>::Add
1248 operator+(int l, const Vec<M,E,S>& r) {return r + (typename CNT<E>::Precision)l;}
1249 
1250 // Complex, conjugate, and negator are all easy to templatize.
1251 
1252 // v = v+complex, complex+v
1253 template <int M, class E, int S, class R> inline
1254 typename Vec<M,E,S>::template Result<std::complex<R> >::Add
1255 operator+(const Vec<M,E,S>& l, const std::complex<R>& r)
1256  { return Vec<M,E,S>::template Result<std::complex<R> >::AddOp::perform(l,r); }
1257 template <int M, class E, int S, class R> inline
1258 typename Vec<M,E,S>::template Result<std::complex<R> >::Add
1259 operator+(const std::complex<R>& l, const Vec<M,E,S>& r) {return r+l;}
1260 
1261 // v = v+conjugate, conjugate+v (convert conjugate->complex)
1262 template <int M, class E, int S, class R> inline
1263 typename Vec<M,E,S>::template Result<std::complex<R> >::Add
1264 operator+(const Vec<M,E,S>& l, const conjugate<R>& r) {return l+(std::complex<R>)r;}
1265 template <int M, class E, int S, class R> inline
1266 typename Vec<M,E,S>::template Result<std::complex<R> >::Add
1267 operator+(const conjugate<R>& l, const Vec<M,E,S>& r) {return r+(std::complex<R>)l;}
1268 
1269 // v = v+negator, negator+v: convert negator to standard number
1270 template <int M, class E, int S, class R> inline
1271 typename Vec<M,E,S>::template Result<typename negator<R>::StdNumber>::Add
1272 operator+(const Vec<M,E,S>& l, const negator<R>& r) {return l + (typename negator<R>::StdNumber)(R)r;}
1273 template <int M, class E, int S, class R> inline
1274 typename Vec<M,E,S>::template Result<typename negator<R>::StdNumber>::Add
1275 operator+(const negator<R>& l, const Vec<M,E,S>& r) {return r + (typename negator<R>::StdNumber)(R)l;}
1276 
1277 // SCALAR SUBTRACT -- careful, not commutative.
1278 
1279 // v = v-real, real-v
1280 template <int M, class E, int S> inline
1281 typename Vec<M,E,S>::template Result<float>::Sub
1282 operator-(const Vec<M,E,S>& l, const float& r)
1283  { return Vec<M,E,S>::template Result<float>::SubOp::perform(l,r); }
1284 template <int M, class E, int S> inline
1285 typename CNT<float>::template Result<Vec<M,E,S> >::Sub
1286 operator-(const float& l, const Vec<M,E,S>& r)
1287  { return CNT<float>::template Result<Vec<M,E,S> >::SubOp::perform(l,r); }
1288 
1289 template <int M, class E, int S> inline
1290 typename Vec<M,E,S>::template Result<double>::Sub
1291 operator-(const Vec<M,E,S>& l, const double& r)
1292  { return Vec<M,E,S>::template Result<double>::SubOp::perform(l,r); }
1293 template <int M, class E, int S> inline
1294 typename CNT<double>::template Result<Vec<M,E,S> >::Sub
1295 operator-(const double& l, const Vec<M,E,S>& r)
1296  { return CNT<double>::template Result<Vec<M,E,S> >::SubOp::perform(l,r); }
1297 
1298 // v = v-int, int-v // just convert int to v's precision float
1299 template <int M, class E, int S> inline
1300 typename Vec<M,E,S>::template Result<typename CNT<E>::Precision>::Sub
1301 operator-(const Vec<M,E,S>& l, int r) {return l - (typename CNT<E>::Precision)r;}
1302 template <int M, class E, int S> inline
1303 typename CNT<typename CNT<E>::Precision>::template Result<Vec<M,E,S> >::Sub
1304 operator-(int l, const Vec<M,E,S>& r) {return (typename CNT<E>::Precision)l - r;}
1305 
1306 
1307 // Complex, conjugate, and negator are all easy to templatize.
1308 
1309 // v = v-complex, complex-v
1310 template <int M, class E, int S, class R> inline
1311 typename Vec<M,E,S>::template Result<std::complex<R> >::Sub
1312 operator-(const Vec<M,E,S>& l, const std::complex<R>& r)
1313  { return Vec<M,E,S>::template Result<std::complex<R> >::SubOp::perform(l,r); }
1314 template <int M, class E, int S, class R> inline
1315 typename CNT<std::complex<R> >::template Result<Vec<M,E,S> >::Sub
1316 operator-(const std::complex<R>& l, const Vec<M,E,S>& r)
1317  { return CNT<std::complex<R> >::template Result<Vec<M,E,S> >::SubOp::perform(l,r); }
1318 
1319 // v = v-conjugate, conjugate-v (convert conjugate->complex)
1320 template <int M, class E, int S, class R> inline
1321 typename Vec<M,E,S>::template Result<std::complex<R> >::Sub
1322 operator-(const Vec<M,E,S>& l, const conjugate<R>& r) {return l-(std::complex<R>)r;}
1323 template <int M, class E, int S, class R> inline
1324 typename CNT<std::complex<R> >::template Result<Vec<M,E,S> >::Sub
1325 operator-(const conjugate<R>& l, const Vec<M,E,S>& r) {return (std::complex<R>)l-r;}
1326 
1327 // v = v-negator, negator-v: convert negator to standard number
1328 template <int M, class E, int S, class R> inline
1329 typename Vec<M,E,S>::template Result<typename negator<R>::StdNumber>::Sub
1330 operator-(const Vec<M,E,S>& l, const negator<R>& r) {return l-(typename negator<R>::StdNumber)(R)r;}
1331 template <int M, class E, int S, class R> inline
1332 typename CNT<R>::template Result<Vec<M,E,S> >::Sub
1333 operator-(const negator<R>& l, const Vec<M,E,S>& r) {return (typename negator<R>::StdNumber)(R)l-r;}
1334 
1335 // Vec I/O
1336 template <int M, class E, int S, class CHAR, class TRAITS> inline
1337 std::basic_ostream<CHAR,TRAITS>&
1338 operator<<(std::basic_ostream<CHAR,TRAITS>& o, const Vec<M,E,S>& v) {
1339  o << "~[" << v[0]; for(int i=1;i<M;++i) o<<','<<v[i]; o<<']'; return o;
1340 }
1341 
1344 template <int M, class E, int S, class CHAR, class TRAITS> inline
1345 std::basic_istream<CHAR,TRAITS>&
1346 operator>>(std::basic_istream<CHAR,TRAITS>& is, Vec<M,E,S>& v) {
1347  CHAR tilde;
1348  is >> tilde; if (is.fail()) return is;
1349  if (tilde != CHAR('~')) {
1350  tilde = CHAR(0);
1351  is.unget(); if (is.fail()) return is;
1352  }
1353 
1354  CHAR openBracket, closeBracket;
1355  is >> openBracket; if (is.fail()) return is;
1356  if (openBracket==CHAR('('))
1357  closeBracket = CHAR(')');
1358  else if (openBracket==CHAR('['))
1359  closeBracket = CHAR(']');
1360  else {
1361  closeBracket = CHAR(0);
1362  is.unget(); if (is.fail()) return is;
1363  }
1364 
1365  // If we saw a "~" but then we didn't see any brackets, that's an
1366  // error. Set the fail bit and return.
1367  if (tilde != CHAR(0) && closeBracket == CHAR(0)) {
1368  is.setstate( std::ios::failbit );
1369  return is;
1370  }
1371 
1372  for (int i=0; i < M; ++i) {
1373  is >> v[i];
1374  if (is.fail()) return is;
1375  if (i != M-1) {
1376  CHAR c; is >> c; if (is.fail()) return is;
1377  if (c != ',') is.unget();
1378  if (is.fail()) return is;
1379  }
1380  }
1381 
1382  // Get the closing bracket if there was an opening one. If we don't
1383  // see the expected character we'll set the fail bit in the istream.
1384  if (closeBracket != CHAR(0)) {
1385  CHAR closer; is >> closer; if (is.fail()) return is;
1386  if (closer != closeBracket) {
1387  is.unget(); if (is.fail()) return is;
1388  is.setstate( std::ios::failbit );
1389  }
1390  }
1391 
1392  return is;
1393 }
1394 
1395 } //namespace SimTK
1396 
1397 
1398 #endif //SimTK_SIMMATRIX_SMALLMATRIX_VEC_H_
Matrix_< E > operator/(const MatrixBase< E > &l, const typename CNT< E >::StdNumber &r)
Definition: BigMatrix.h:613
TImag & imag()
Recast to show only the imaginary portion of this Vec and return a writable reference.
Definition: Vec.h:699
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, using a specified tolerance.
Definition: Vec.h:956
PhiMatrixTranspose transpose(const PhiMatrix &phi)
Definition: SpatialAlgebra.h:720
CNT< E >::TSqHermT ESqHermT
Type of the expression ~E*E (default vector and matrix square; symmetric).
Definition: Vec.h:212
K::ScalarNormSq ScalarNormSq
Definition: CompositeNumericalTypes.h:166
SubOp::Type Sub
Definition: Vec.h:410
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:915
K::ULessScalar ULessScalar
Definition: CompositeNumericalTypes.h:161
TNeg & operator-()
Recast to negated type and return a writable reference; writing to this will cause the negated result...
Definition: Vec.h:645
static int size()
The number of elements in this Vec (note that stride does not affect this number.) ...
Definition: Vec.h:318
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:508
Vec< M, P > Type
Definition: Vec.h:419
K::TReal TReal
Definition: CompositeNumericalTypes.h:141
bool isNaN() const
Return true if any element of this Vec contains a NaN anywhere.
Definition: Vec.h:918
CNT< E >::TSqrt ESqrt
Type required to hold the result of sqrt(E).
Definition: Vec.h:216
This is a small, fixed-size symmetric or Hermitian matrix designed for no-overhead inline computation...
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:621
TAbs abs() const
Elementwise absolute value; that is, the return value has the same dimension as this Vec but with eac...
Definition: Vec.h:347
SymMat< M, ESqTHerm > TSqTHerm
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:304
Vec & scalarEq(const EE &ee)
Definition: Vec.h:783
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:202
MulOp::Type Mul
Definition: Vec.h:390
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:198
Vec & scalarTimesEq(const EE &ee)
Definition: Vec.h:791
Vec & scalarTimesEqFromLeft(int ee)
Definition: Vec.h:807
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
NTraits< N >::StdNumber StdNumber
Definition: negator.h:107
SimTK::conjugate<R> should be instantiated only for float, double.
Definition: String.h:45
K::TSqrt TSqrt
Definition: CompositeNumericalTypes.h:154
TWithoutNegator & updCastAwayNegatorIfAny()
Recast to remove negators from this Vec&#39;s type if present and return a writable reference.
Definition: Vec.h:712
Vec(const E &e)
Construction from a single value of this Vec&#39;s element type assigns that value to each element...
Definition: Vec.h:470
static TSqrt sqrt(const K &t)
Definition: CompositeNumericalTypes.h:239
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:908
Vec< M, ESqrt, 1 > TSqrt
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:297
Vec & operator=(const EE *p)
Assignment to a pointer to elements of any type EE assumes we&#39;re pointing at a C++ array of EE&#39;s of t...
Definition: Vec.h:523
Definition: Vec.h:377
TNeg & updNegate()
Non-operator version of unary negation; recasts and returns a writable reference. ...
Definition: Vec.h:659
K::Scalar Scalar
Definition: CompositeNumericalTypes.h:160
ESqHermT TSqHermT
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:303
const THerm & transpose() const
Non-operator version of Hermitian transpose; just a recast.
Definition: Vec.h:662
Vec & operator+=(const EE &e)
Definition: Vec.h:776
CNT< E >::TNormalize ENormalize
Packed type that can hold the value returned from normalize(E).
Definition: Vec.h:226
K::TNormalize TNormalize
Definition: CompositeNumericalTypes.h:158
Matrix_< typename CNT< E1 >::template Result< E2 >::Sub > operator-(const MatrixBase< E1 > &l, const MatrixBase< E2 > &r)
Definition: BigMatrix.h:584
E TElement
Element type of this Vec.
Definition: Vec.h:289
const TWithoutNegator & castAwayNegatorIfAny() const
Recast to remove negators from this Vec&#39;s type if present; this is handy for simplifying operations w...
Definition: Vec.h:708
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:502
static int nrow()
The number of rows in a Vec is the number of elements.
Definition: Vec.h:320
E & operator[](int i)
Select an element of this Vec and return a writable reference to it.
Definition: Vec.h:604
Vec< M, typename CNT< E >::template Result< EE >::Dvd > scalarDivide(const EE &e) const
Definition: Vec.h:739
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:505
K::TImag TImag
Definition: CompositeNumericalTypes.h:142
CNT< E >::StdNumber EStdNumber
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:231
Vec(const E &e0, const E &e1)
Construct a Vec<2,E> from two elements of type E, etc.
Definition: Vec.h:490
Vec< M, typename CNT< E >::template Result< P >::Mul, 1 > Mul
Definition: Vec.h:378
EStandard sum() const
Sum just adds up all the elements into a single return element that is the same type as this Vec&#39;s el...
Definition: Vec.h:366
Vec & operator-=(const EE &e)
Definition: Vec.h:777
EStdNumber StdNumber
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:311
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:404
std::basic_istream< CHAR, TRAITS > & operator>>(std::basic_istream< CHAR, TRAITS > &is, conjugate< R > &c)
Definition: conjugate.h:505
Vec(const EE *p)
Construction from a pointer to elements of any type EE assumes we&#39;re pointing at a C++ array of EE&#39;s ...
Definition: Vec.h:516
Vec< M, typename CNT< E >::template Result< EE >::Mul > scalarMultiply(const EE &e) const
Definition: Vec.h:724
Vec< M, EAbs, 1 > TAbs
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:298
negator<N>, where N is a number type (real, complex, conjugate), is represented in memory identically...
Definition: String.h:44
Definition: CompositeNumericalTypes.h:120
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:692
static double getDefaultTolerance()
Definition: CompositeNumericalTypes.h:269
CNT< E >::THerm EHerm
Type of the Hermitian transpose of an element of this Vec.
Definition: Vec.h:207
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:623
TInvert invert() const
This method is not supported for Vec objects.
Definition: Vec.h:635
bool isInf() const
Return true if any element of this Vec contains a +Infinity or -Infinity somewhere but no element con...
Definition: Vec.h:927
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:409
TPosTrans & updPositionalTranspose()
Positional transpose returning a writable reference.
Definition: Vec.h:674
Vec(const Vec &src)
Copy constructor copies the logically-included elements from the source Vec; gaps due to stride are n...
Definition: Vec.h:438
bool operator==(const PhiMatrix &p1, const PhiMatrix &p2)
Definition: SpatialAlgebra.h:791
ScalarNormSq scalarNormSqr() const
Scalar norm square is sum( conjugate squares of all underlying scalars ), where conjugate square of s...
Definition: Vec.h:327
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:221
static TStandard standardize(const K &t)
Definition: CompositeNumericalTypes.h:241
Vec(const E &e0, const E &e1, const E &e2, const E &e3)
Definition: Vec.h:494
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:275
CNT< E >::Scalar EScalar
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:228
EPrecision Precision
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:312
CNT< E >::TPosTrans EPosTrans
Type of a positional transpose of an element of this Vec.
Definition: Vec.h:209
CNT< E >::TSqTHerm ESqTHerm
Type of the expression E*~E ("row square"; symmetric).
Definition: Vec.h:214
Vec< M, typename CNT< E >::template Result< P >::Add, 1 > Add
Definition: Vec.h:380
Vec< M, EStandard, 1 > TStandard
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:299
CNT< ScalarNormSq >::TSqrt norm() const
Definition: Vec.h:610
const E & operator()(int i) const
Same as const operator[] above.
Definition: Vec.h:599
const THerm & operator~() const
The Hermitian transpose operator recasts this Vec to a type that specifies the opposite storage order...
Definition: Vec.h:649
Vec & scalarMinusEqFromLeft(int ee)
Definition: Vec.h:806
const TNeg & negate() const
Non-operator version of unary negation; just a recast.
Definition: Vec.h:656
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:572
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:337
Vec & scalarPlusEq(const EE &ee)
Definition: Vec.h:785
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:538
Vec< M, E, STRIDE > T
The type of this Vec.
Definition: Vec.h:265
CNT< E >::ScalarNormSq EScalarNormSq
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:233
bool isNumericallyEqual(const Vec< M, E2, RS2 > &v) const
Test whether this vector is numerically equal to some other vector with the same shape, using a default tolerance which is the looser of the default tolerances of the two objects being compared.
Definition: Vec.h:967
ELEM sum(const VectorBase< ELEM > &v)
Definition: VectorMath.h:147
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:827
K::TSqTHerm TSqTHerm
Definition: CompositeNumericalTypes.h:147
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:458
This is a fixed-length column vector designed for no-overhead inline computation. ...
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:618
Row< M, EInvert, 1 > TInvert
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:300
Vec< M, typename CNT< E >::template Result< EE >::Mul > elementwiseMultiply(const Vec< M, EE, SS > &r) const
Elementwise multiply (Matlab " .* " operator).
Definition: Vec.h:580
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:357
Vec(const Vec< M, EE, SS > &src)
Construct a Vec from a Vec of the same length, with any stride.
Definition: Vec.h:464
ScalarNormSq normSqr() const
Definition: Vec.h:608
static double getDefaultTolerance()
For approximate comparisons, the default tolerance to use for a vector is the same as its elements&#39; d...
Definition: Vec.h:951
K::Precision Precision
Definition: CompositeNumericalTypes.h:164
Vec & scalarEq(int ee)
Definition: Vec.h:801
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:284
ENumber Number
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:310
void setToNaN()
Set every scalar in this Vec to NaN; this is the default initial value in Debug builds, but not in Release.
Definition: Vec.h:812
Matrix_< E > operator*(const MatrixBase< E > &l, const typename CNT< E >::StdNumber &r)
Definition: BigMatrix.h:605
Vec< M, typename CNT< E >::template Result< EE >::Dvd > elementwiseDivide(const Vec< M, EE, SS > &r) const
Elementwise divide (Matlab " ./ " operator).
Definition: Vec.h:587
void setToZero()
Set every scalar in this Vec to zero.
Definition: Vec.h:817
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
K::TInvert TInvert
Definition: CompositeNumericalTypes.h:157
THerm & operator~()
Recast to Hermitian transposed type and return a writable reference; the effect is that writing to el...
Definition: Vec.h:653
Vec & operator=(const Vec &src)
Copy assignment operator copies the logically-included elements from the source Vec; gaps due to stri...
Definition: Vec.h:445
Vec(const E &e0, const E &e1, const E &e2)
Definition: Vec.h:492
Vec< M, typename CNT< EE >::template Result< E >::Mul > scalarMultiplyFromLeft(const EE &e) const
Definition: Vec.h:730
MulOpNonConforming::Type MulNon
Definition: Vec.h:395
ELEM max(const VectorBase< ELEM > &v)
Definition: VectorMath.h:251
Vec & scalarMinusEq(int ee)
Definition: Vec.h:803
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:563
Shape-preserving element substitution (always packed).
Definition: Vec.h:418
const TPosTrans & positionalTranspose() const
Positional transpose turns this Vec into a Row but does not transpose the individual elements...
Definition: Vec.h:671
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:394
const Vec & operator+() const
Unary plus does nothing.
Definition: Vec.h:638
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:890
Vec & operator/=(const EE &e)
Definition: Vec.h:779
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:847
CNT< E >::TWithoutNegator EWithoutNegator
Element type, stripped of negator<> if it has one.
Definition: Vec.h:195
Definition: Vec.h:386
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:205
Vec(const ENeg &ne)
Construction from a single value of this Vec&#39;s negated element type assigns that value to each elemen...
Definition: Vec.h:476
K::TPosTrans TPosTrans
Definition: CompositeNumericalTypes.h:145
Vec & operator*=(const EE &e)
Definition: Vec.h:778
Vec< M, typename CNT< E >::template Result< EE >::Add > scalarAdd(const EE &e) const
Definition: Vec.h:752
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:642
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
float norm(const conjugate< float > &c)
Definition: conjugate.h:486
std::string toString() const
Print Vec into a string and return it.
Definition: Vec.h:988
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:279
TReal & real()
Recast to show only the real portion of this Vec and return a writable reference. ...
Definition: Vec.h:684
CNT< E >::TAbs EAbs
Type required to hold the result of abs(E).
Definition: Vec.h:218
K::StdNumber StdNumber
Definition: CompositeNumericalTypes.h:163
RowVectorBase< typename CNT< ELEM >::TAbs > abs(const RowVectorBase< ELEM > &v)
Definition: VectorMath.h:120
bool isFinite() const
Return true if no element of this Vec contains an Infinity or a NaN anywhere.
Definition: Vec.h:942
Vec & scalarTimesEqFromLeft(const EE &ee)
Definition: Vec.h:793
E TRow
Type of a row of this CNT object (for a Vec, just its element type).
Definition: Vec.h:291
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:863
Specialized information about Composite Numerical Types which allows us to define appropriate templat...
Definition: CompositeNumericalTypes.h:136
Vec & scalarPlusEq(int ee)
Definition: Vec.h:802
THerm & updTranspose()
Non-operator version of Hermitian transpose; recasts and returns a writable reference.
Definition: Vec.h:665
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:399
Vec & scalarDivideEq(int ee)
Definition: Vec.h:805
CNT< E >::Precision EPrecision
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:232
This is a fixed-length row vector designed for no-overhead inline computation.
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:619
Vec & scalarMinusEqFromLeft(const EE &ee)
Definition: Vec.h:789
const E & operator[](int i) const
Select an element of this Vec and return a const reference to it.
Definition: Vec.h:596
const Real E
e = Real(exp(1))
Mandatory first inclusion for any Simbody source or header file.
Vec< M, ENormalize, 1 > TNormalize
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:301
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:877
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:556
E & operator()(int i)
Same as non-const operator[] above.
Definition: Vec.h:606
K::TNeg TNeg
Definition: CompositeNumericalTypes.h:139
K::TStandard TStandard
Definition: CompositeNumericalTypes.h:156
void copy(Row< 1, E1, S1 > &r1, const Row< 1, E2, S2 > &r2)
Definition: Row.h:105
Vec< M, typename CNT< EE >::template Result< E >::Dvd > scalarDivideFromLeft(const EE &e) const
Definition: Vec.h:745
K::TWithoutNegator TWithoutNegator
Definition: CompositeNumericalTypes.h:140
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:528
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
Vec< MM, ELT, STRIDE > & updSubVec(int i)
Extract a writable reference to a sub-Vec with size known at compile time.
Definition: Vec.h:837
Vec< M, typename CNT< E >::template Result< P >::Sub, 1 > Sub
Definition: Vec.h:381
Vec< M, typename CNT< E >::template Result< EE >::Sub > scalarSubtract(const EE &e) const
Definition: Vec.h:760
CNT< E >::TInvert EInvert
Packed type that can hold the value returned from invert(E), the inverse type of an element...
Definition: Vec.h:224
Matrix_< typename CNT< E1 >::template Result< E2 >::Add > operator+(const MatrixBase< E1 > &l, const MatrixBase< E2 > &r)
Definition: BigMatrix.h:568
Vec< M, EComplex, STRIDE > TComplex
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:280
bool operator!=(const L &left, const R &right)
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:641
This class represents a small matrix whose size is known at compile time, containing elements of any ...
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:620
Vec & scalarDivideEqFromLeft(int ee)
Definition: Vec.h:808
K::TComplex TComplex
Definition: CompositeNumericalTypes.h:143
bool operator>(const L &left, const R &right)
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:647
Vec & scalarTimesEq(int ee)
Definition: Vec.h:804
K::Number Number
Definition: CompositeNumericalTypes.h:162
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:533
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:287
bool operator>=(const L &left, const R &right)
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:659
Vec & scalarDivideEq(const EE &ee)
Definition: Vec.h:795
static K getNaN()
Definition: CompositeNumericalTypes.h:246
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:548
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:855
Vec(const E &e0, const E &e1, const E &e2, const E &e3, const E &e4)
Definition: Vec.h:496
Vec< M, ENeg, STRIDE > TNeg
Type this Vec would have if its elements were interpreted as negated.
Definition: Vec.h:268
CNT< E >::Number ENumber
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:230
ELT E
Element type of this Vec.
Definition: Vec.h:191
EScalarNormSq ScalarNormSq
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:313
K::TSqHermT TSqHermT
Definition: CompositeNumericalTypes.h:146
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:681
Vec(const E &e0, const E &e1, const E &e2, const E &e3, const E &e4, const E &e5)
Definition: Vec.h:499
CNT< E >::ULessScalar EULessScalar
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:229
AddOp::Type Add
Definition: Vec.h:405
Vec TCol
Type of a column of this CNT object (for a Vec, the whole thing).
Definition: Vec.h:293
EULessScalar ULessScalar
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:309
K::THerm THerm
Definition: CompositeNumericalTypes.h:144
Vec()
Default construction initializes Vec&#39;s elements to NaN when debugging but leaves them uninitialized g...
Definition: Vec.h:425
Vec & scalarMinusEq(const EE &ee)
Definition: Vec.h:787
static int ncol()
The number of columns in a Vec is always 1.
Definition: Vec.h:322
EScalar Scalar
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:308
Definition: negator.h:64
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:452
Vec & scalarDivideEqFromLeft(const EE &ee)
Definition: Vec.h:797
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:485
Vec< M, typename CNT< EE >::template Result< E >::Sub > scalarSubtractFromLeft(const EE &e) const
Definition: Vec.h:766
CNT< E >::TNeg ENeg
Negated version of this Vec&#39;s element type; ENeg==negator< E >.
Definition: Vec.h:193
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
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:543
DvdOp::Type Dvd
Definition: Vec.h:400
Vec< M, EWithoutNegator, STRIDE > TWithoutNegator
Type of this Vec with negator removed from its element type, if the element is negated.
Definition: Vec.h:271
Vec< M, typename CNT< E >::template Result< P >::Dvd, 1 > Dvd
Definition: Vec.h:379
static const Vec & getAs(const ELT *p)
Recast an ordinary C++ array E[] to a const Vec<M,E,S>; assumes compatible length, stride, and packing.
Definition: Vec.h:904
K::TAbs TAbs
Definition: CompositeNumericalTypes.h:155
bool isNumericallyEqual(const float &a, const float &b, double tol=RTraits< float >::getDefaultTolerance())
Compare two floats for approximate equality.
Definition: NTraits.h:293
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:389