Simbody  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 }
130 template <int M, class ELT, int STRIDE>
131 class Vec {
132 public:
138  typedef ELT E;
140  typedef typename CNT<E>::TNeg ENeg;
145  typedef typename CNT<E>::TReal EReal;
149  typedef typename CNT<E>::TImag EImag;
152  typedef typename CNT<E>::TComplex EComplex;
154  typedef typename CNT<E>::THerm EHerm;
156  typedef typename CNT<E>::TPosTrans EPosTrans;
159  typedef typename CNT<E>::TSqHermT ESqHermT;
161  typedef typename CNT<E>::TSqTHerm ESqTHerm;
163  typedef typename CNT<E>::TSqrt ESqrt;
165  typedef typename CNT<E>::TAbs EAbs;
168  typedef typename CNT<E>::TStandard EStandard;
171  typedef typename CNT<E>::TInvert EInvert;
173  typedef typename CNT<E>::TNormalize ENormalize;
174 
175  typedef typename CNT<E>::Scalar EScalar;
177  typedef typename CNT<E>::Number ENumber;
178  typedef typename CNT<E>::StdNumber EStdNumber;
179  typedef typename CNT<E>::Precision EPrecision;
181 
184  enum {
185  NRows = M,
186  NCols = 1,
188  NActualElements = M * STRIDE, // includes trailing gap
190  RowSpacing = STRIDE,
193  RealStrideFactor = 1, // composite types don't change size when
194  // cast from complex to real or imaginary
196  ? CNT<E>::ArgDepth + 1
198  IsScalar = 0,
200  IsNumber = 0,
204  };
205 
206  // These are reinterpretations of the current data, so have the
207  // same packing (stride).
208 
234  typedef E TElement;
236  typedef E TRow;
238  typedef Vec TCol;
239 
240  // These are the results of calculations, so are returned in new, packed
241  // memory. Be sure to refer to element types here which are also packed.
242  typedef Vec<M,ESqrt,1> TSqrt; // Note stride
243  typedef Vec<M,EAbs,1> TAbs; // Note stride
247 
248  typedef ESqHermT TSqHermT; // result of self dot product
249  typedef SymMat<M,ESqTHerm> TSqTHerm; // result of self outer product
250 
251  // These recurse right down to the underlying scalar type no matter how
252  // deep the elements are.
253  typedef EScalar Scalar;
255  typedef ENumber Number;
263  static int size() { return M; }
265  static int nrow() { return M; }
267  static int ncol() { return 1; }
268 
269 
272  ScalarNormSq scalarNormSqr() const {
273  ScalarNormSq sum(0);
274  for(int i=0;i<M;++i) sum += CNT<E>::scalarNormSqr(d[i*STRIDE]);
275  return sum;
276  }
277 
282  TSqrt sqrt() const {
283  TSqrt vsqrt;
284  for(int i=0;i<M;++i) vsqrt[i] = CNT<E>::sqrt(d[i*STRIDE]);
285  return vsqrt;
286  }
287 
292  TAbs abs() const {
293  TAbs vabs;
294  for(int i=0;i<M;++i) vabs[i] = CNT<E>::abs(d[i*STRIDE]);
295  return vabs;
296  }
297 
302  TStandard standardize() const {
303  TStandard vstd;
304  for(int i=0;i<M;++i) vstd[i] = CNT<E>::standardize(d[i*STRIDE]);
305  return vstd;
306  }
307 
311  EStandard sum() const {
312  E sum(0);
313  for (int i=0;i<M;++i) sum += d[i*STRIDE];
314  return CNT<E>::standardize(sum);
315  }
316 
317 
318  // This gives the resulting vector type when (v[i] op P) is applied to
319  // each element of v. It is a vector of length M, stride 1, and element
320  // types which are the regular composite result of E op P. Typically P is
321  // a scalar type but it doesn't have to be.
322  template <class P> struct EltResult {
327  };
328 
329  // This is the composite result for v op P where P is some kind of
330  // appropriately shaped non-scalar type.
331  template <class P> struct Result {
332  typedef MulCNTs<M,1,ArgDepth,Vec,ColSpacing,RowSpacing,
335  typedef typename MulOp::Type Mul;
336 
337  typedef MulCNTsNonConforming<M,1,ArgDepth,Vec,ColSpacing,RowSpacing,
340  typedef typename MulOpNonConforming::Type MulNon;
341 
342  typedef DvdCNTs<M,1,ArgDepth,Vec,ColSpacing,RowSpacing,
345  typedef typename DvdOp::Type Dvd;
346 
347  typedef AddCNTs<M,1,ArgDepth,Vec,ColSpacing,RowSpacing,
350  typedef typename AddOp::Type Add;
351 
352  typedef SubCNTs<M,1,ArgDepth,Vec,ColSpacing,RowSpacing,
355  typedef typename SubOp::Type Sub;
356  };
357 
363  template <class P> struct Substitute {
364  typedef Vec<M,P> Type;
365  };
366 
370  Vec(){
371  #ifndef NDEBUG
372  setToNaN();
373  #endif
374  }
375 
376  // It's important not to use the default copy constructor or copy
377  // assignment because the compiler doesn't understand that we may
378  // have noncontiguous storage and will try to copy the whole array.
379 
383  Vec(const Vec& src) {
384  Impl::copy(*this, src);
385  }
390  Vec& operator=(const Vec& src) {
391  Impl::copy(*this, src);
392  return *this;
393  }
394 
397  template <int SS> Vec(const Vec<M,E,SS>& src) {
398  Impl::copy(*this, src);
399  }
400 
403  template <int SS> Vec(const Vec<M,ENeg,SS>& src) {
404  Impl::copy(*this, src);
405  }
406 
409  template <class EE, int SS> explicit Vec(const Vec<M,EE,SS>& src) {
410  Impl::copy(*this, src);
411  }
412 
415  explicit Vec(const E& e) {for (int i=0;i<M;++i) d[i*STRIDE]=e;}
416 
421  explicit Vec(const ENeg& ne) {
422  const E e = ne; // requires floating point negation
423  for (int i=0;i<M;++i) d[i*STRIDE]=e;
424  }
425 
430  explicit Vec(int i) {new (this) Vec(E(Precision(i)));}
431 
432  // A bevy of constructors for Vecs up to length 9.
433 
435  Vec(const E& e0,const E& e1)
436  { assert(M==2);(*this)[0]=e0;(*this)[1]=e1; }
437  Vec(const E& e0,const E& e1,const E& e2)
438  { assert(M==3);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2; }
439  Vec(const E& e0,const E& e1,const E& e2,const E& e3)
440  { assert(M==4);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2;(*this)[3]=e3; }
441  Vec(const E& e0,const E& e1,const E& e2,const E& e3,const E& e4)
442  { assert(M==5);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2;
443  (*this)[3]=e3;(*this)[4]=e4; }
444  Vec(const E& e0,const E& e1,const E& e2,const E& e3,const E& e4,const E& e5)
445  { assert(M==6);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2;
446  (*this)[3]=e3;(*this)[4]=e4;(*this)[5]=e5; }
447  Vec(const E& e0,const E& e1,const E& e2,const E& e3,const E& e4,const E& e5, const E& e6)
448  { assert(M==7);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2;
449  (*this)[3]=e3;(*this)[4]=e4;(*this)[5]=e5;(*this)[6]=e6; }
450  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)
451  { assert(M==8);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2;
452  (*this)[3]=e3;(*this)[4]=e4;(*this)[5]=e5;(*this)[6]=e6;(*this)[7]=e7; }
453  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)
454  { assert(M==9);(*this)[0]=e0;(*this)[1]=e1;(*this)[2]=e2;
455  (*this)[3]=e3;(*this)[4]=e4;(*this)[5]=e5;(*this)[6]=e6;(*this)[7]=e7;(*this)[8]=e8; }
456 
461  template <class EE> explicit Vec(const EE* p)
462  { assert(p); for(int i=0;i<M;++i) d[i*STRIDE]=p[i]; }
463 
468  template <class EE> Vec& operator=(const EE* p)
469  { assert(p); for(int i=0;i<M;++i) d[i*STRIDE]=p[i]; return *this; }
470 
473  template <class EE, int SS> Vec& operator=(const Vec<M,EE,SS>& vv)
474  { Impl::copy(*this, vv); return *this; }
475 
478  template <class EE, int SS> Vec& operator+=(const Vec<M,EE,SS>& r)
479  { for(int i=0;i<M;++i) d[i*STRIDE] += r[i]; return *this; }
483  template <class EE, int SS> Vec& operator+=(const Vec<M,negator<EE>,SS>& r)
484  { for(int i=0;i<M;++i) d[i*STRIDE] -= -(r[i]); return *this; }
485 
488  template <class EE, int SS> Vec& operator-=(const Vec<M,EE,SS>& r)
489  { for(int i=0;i<M;++i) d[i*STRIDE] -= r[i]; return *this; }
493  template <class EE, int SS> Vec& operator-=(const Vec<M,negator<EE>,SS>& r)
494  { for(int i=0;i<M;++i) d[i*STRIDE] += -(r[i]); return *this; }
495 
496  // Conforming binary ops with 'this' on left, producing new packed result.
497  // Cases: v=v+v, v=v-v, m=v*r
498 
500  template <class EE, int SS> Vec<M,typename CNT<E>::template Result<EE>::Add>
501  conformingAdd(const Vec<M,EE,SS>& r) const {
502  Vec<M,typename CNT<E>::template Result<EE>::Add> result;
503  Impl::conformingAdd(*this, r, result);
504  return result;
505  }
507  template <class EE, int SS> Vec<M,typename CNT<E>::template Result<EE>::Sub>
509  Vec<M,typename CNT<E>::template Result<EE>::Sub> result;
510  Impl::conformingSubtract(*this, r, result);
511  return result;
512  }
513 
516  template <class EE, int SS> Mat<M,M,typename CNT<E>::template Result<EE>::Mul>
518  Mat<M,M,typename CNT<E>::template Result<EE>::Mul> result;
519  for (int j=0;j<M;++j) result(j) = scalarMultiply(r(j));
520  return result;
521  }
522 
524  template <class EE, int SS> Vec<M,typename CNT<E>::template Result<EE>::Mul>
526  Vec<M,typename CNT<E>::template Result<EE>::Mul> result;
527  Impl::elementwiseMultiply(*this, r, result);
528  return result;
529  }
531  template <class EE, int SS> Vec<M,typename CNT<E>::template Result<EE>::Dvd>
532  elementwiseDivide(const Vec<M,EE,SS>& r) const {
533  Vec<M,typename CNT<E>::template Result<EE>::Dvd> result;
534  Impl::elementwiseDivide(*this, r, result);
535  return result;
536  }
537 
541  const E& operator[](int i) const
542  { assert(0 <= i && i < M); return d[i*STRIDE]; }
544  const E& operator()(int i) const {return (*this)[i];}
545 
549  E& operator[](int i) {assert(0 <= i && i < M); return d[i*STRIDE];}
551  E& operator()(int i) {return (*this)[i];}
552 
553  ScalarNormSq normSqr() const { return scalarNormSqr(); }
554  typename CNT<ScalarNormSq>::TSqrt
556 
568  TNormalize normalize() const {
569  if (CNT<E>::IsScalar) {
571  } else {
572  TNormalize elementwiseNormalized;
573  for (int i=0; i<M; ++i)
574  elementwiseNormalized[i] = CNT<E>::normalize((*this)[i]);
575  return elementwiseNormalized;
576  }
577  }
578 
580  TInvert invert() const {assert(false); return TInvert();} // TODO default inversion
581 
583  const Vec& operator+() const { return *this; }
587  const TNeg& operator-() const { return negate(); }
590  TNeg& operator-() { return updNegate(); }
594  const THerm& operator~() const { return transpose(); }
598  THerm& operator~() { return updTranspose(); }
599 
601  const TNeg& negate() const { return *reinterpret_cast<const TNeg*>(this); }
604  TNeg& updNegate() { return *reinterpret_cast< TNeg*>(this); }
605 
607  const THerm& transpose() const { return *reinterpret_cast<const THerm*>(this); }
610  THerm& updTranspose() { return *reinterpret_cast< THerm*>(this); }
611 
616  const TPosTrans& positionalTranspose() const
617  { return *reinterpret_cast<const TPosTrans*>(this); }
620  { return *reinterpret_cast<TPosTrans*>(this); }
621 
626  const TReal& real() const { return *reinterpret_cast<const TReal*>(this); }
629  TReal& real() { return *reinterpret_cast< TReal*>(this); }
630 
631  // Had to contort these next two routines to get them through VC++ 7.net
632 
637  const TImag& imag() const {
638  const int offs = ImagOffset;
639  const EImag* p = reinterpret_cast<const EImag*>(this);
640  return *reinterpret_cast<const TImag*>(p+offs);
641  }
644  TImag& imag() {
645  const int offs = ImagOffset;
646  EImag* p = reinterpret_cast<EImag*>(this);
647  return *reinterpret_cast<TImag*>(p+offs);
648  }
649 
653  const TWithoutNegator& castAwayNegatorIfAny() const
654  { return *reinterpret_cast<const TWithoutNegator*>(this); }
657  TWithoutNegator& updCastAwayNegatorIfAny()
658  { return *reinterpret_cast<TWithoutNegator*>(this); }
659 
660  // These are elementwise binary operators, (this op ee) by default but
661  // (ee op this) if 'FromLeft' appears in the name. The result is a packed
662  // Vec<M> but the element type may change. These are mostly used to
663  // implement global operators. We call these "scalar" operators but
664  // actually the "scalar" can be a composite type.
665 
666  //TODO: consider converting 'e' to Standard Numbers as precalculation and
667  // changing return type appropriately.
668  template <class EE> Vec<M, typename CNT<E>::template Result<EE>::Mul>
669  scalarMultiply(const EE& e) const {
670  Vec<M, typename CNT<E>::template Result<EE>::Mul> result;
671  for (int i=0; i<M; ++i) result[i] = (*this)[i] * e;
672  return result;
673  }
674  template <class EE> Vec<M, typename CNT<EE>::template Result<E>::Mul>
675  scalarMultiplyFromLeft(const EE& e) const {
676  Vec<M, typename CNT<EE>::template Result<E>::Mul> result;
677  for (int i=0; i<M; ++i) result[i] = e * (*this)[i];
678  return result;
679  }
680 
681  // TODO: should precalculate and store 1/e, while converting to Standard
682  // Numbers. Note that return type should change appropriately.
683  template <class EE> Vec<M, typename CNT<E>::template Result<EE>::Dvd>
684  scalarDivide(const EE& e) const {
685  Vec<M, typename CNT<E>::template Result<EE>::Dvd> result;
686  for (int i=0; i<M; ++i) result[i] = (*this)[i] / e;
687  return result;
688  }
689  template <class EE> Vec<M, typename CNT<EE>::template Result<E>::Dvd>
690  scalarDivideFromLeft(const EE& e) const {
691  Vec<M, typename CNT<EE>::template Result<E>::Dvd> result;
692  for (int i=0; i<M; ++i) result[i] = e / (*this)[i];
693  return result;
694  }
695 
696  template <class EE> Vec<M, typename CNT<E>::template Result<EE>::Add>
697  scalarAdd(const EE& e) const {
698  Vec<M, typename CNT<E>::template Result<EE>::Add> result;
699  for (int i=0; i<M; ++i) result[i] = (*this)[i] + e;
700  return result;
701  }
702  // Add is commutative, so no 'FromLeft'.
703 
704  template <class EE> Vec<M, typename CNT<E>::template Result<EE>::Sub>
705  scalarSubtract(const EE& e) const {
706  Vec<M, typename CNT<E>::template Result<EE>::Sub> result;
707  for (int i=0; i<M; ++i) result[i] = (*this)[i] - e;
708  return result;
709  }
710  template <class EE> Vec<M, typename CNT<EE>::template Result<E>::Sub>
711  scalarSubtractFromLeft(const EE& e) const {
712  Vec<M, typename CNT<EE>::template Result<E>::Sub> result;
713  for (int i=0; i<M; ++i) result[i] = e - (*this)[i];
714  return result;
715  }
716 
717  // Generic assignments for any element type not listed explicitly, including scalars.
718  // These are done repeatedly for each element and only work if the operation can
719  // be performed leaving the original element type.
720  template <class EE> Vec& operator =(const EE& e) {return scalarEq(e);}
721  template <class EE> Vec& operator+=(const EE& e) {return scalarPlusEq(e);}
722  template <class EE> Vec& operator-=(const EE& e) {return scalarMinusEq(e);}
723  template <class EE> Vec& operator*=(const EE& e) {return scalarTimesEq(e);}
724  template <class EE> Vec& operator/=(const EE& e) {return scalarDivideEq(e);}
725 
726  // Generalized element assignment & computed assignment methods. These will work
727  // for any assignment-compatible element, not just scalars.
728  template <class EE> Vec& scalarEq(const EE& ee)
729  { for(int i=0;i<M;++i) d[i*STRIDE] = ee; return *this; }
730  template <class EE> Vec& scalarPlusEq(const EE& ee)
731  { for(int i=0;i<M;++i) d[i*STRIDE] += ee; return *this; }
732  template <class EE> Vec& scalarMinusEq(const EE& ee)
733  { for(int i=0;i<M;++i) d[i*STRIDE] -= ee; return *this; }
734  template <class EE> Vec& scalarMinusEqFromLeft(const EE& ee)
735  { for(int i=0;i<M;++i) d[i*STRIDE] = ee - d[i*STRIDE]; return *this; }
736  template <class EE> Vec& scalarTimesEq(const EE& ee)
737  { for(int i=0;i<M;++i) d[i*STRIDE] *= ee; return *this; }
738  template <class EE> Vec& scalarTimesEqFromLeft(const EE& ee)
739  { for(int i=0;i<M;++i) d[i*STRIDE] = ee * d[i*STRIDE]; return *this; }
740  template <class EE> Vec& scalarDivideEq(const EE& ee)
741  { for(int i=0;i<M;++i) d[i*STRIDE] /= ee; return *this; }
742  template <class EE> Vec& scalarDivideEqFromLeft(const EE& ee)
743  { for(int i=0;i<M;++i) d[i*STRIDE] = ee / d[i*STRIDE]; return *this; }
744 
745  // Specialize for int to avoid warnings and ambiguities.
746  Vec& scalarEq(int ee) {return scalarEq(Precision(ee));}
747  Vec& scalarPlusEq(int ee) {return scalarPlusEq(Precision(ee));}
748  Vec& scalarMinusEq(int ee) {return scalarMinusEq(Precision(ee));}
749  Vec& scalarTimesEq(int ee) {return scalarTimesEq(Precision(ee));}
750  Vec& scalarDivideEq(int ee) {return scalarDivideEq(Precision(ee));}
754 
757  void setToNaN() {
758  (*this) = CNT<ELT>::getNaN();
759  }
760 
762  void setToZero() {
763  (*this) = ELT(0);
764  }
765 
771  template <int MM>
772  const Vec<MM,ELT,STRIDE>& getSubVec(int i) const {
773  assert(0 <= i && i + MM <= M);
774  return Vec<MM,ELT,STRIDE>::getAs(&(*this)[i]);
775  }
781  template <int MM>
783  assert(0 <= i && i + MM <= M);
784  return Vec<MM,ELT,STRIDE>::updAs(&(*this)[i]);
785  }
786 
787 
791  template <int MM>
792  static const Vec& getSubVec(const Vec<MM,ELT,STRIDE>& v, int i) {
793  assert(0 <= i && i + M <= MM);
794  return getAs(&v[i]);
795  }
799  template <int MM>
800  static Vec& updSubVec(Vec<MM,ELT,STRIDE>& v, int i) {
801  assert(0 <= i && i + M <= MM);
802  return updAs(&v[i]);
803  }
804 
808  Vec<M-1,ELT,1> drop1(int p) const {
809  assert(0 <= p && p < M);
810  Vec<M-1,ELT,1> out;
811  int nxt=0;
812  for (int i=0; i<M-1; ++i, ++nxt) {
813  if (nxt==p) ++nxt; // skip the loser
814  out[i] = (*this)[nxt];
815  }
816  return out;
817  }
818 
822  template <class EE> Vec<M+1,ELT,1> append1(const EE& v) const {
823  Vec<M+1,ELT,1> out;
824  Vec<M,ELT,1>::updAs(&out[0]) = (*this);
825  out[M] = v;
826  return out;
827  }
828 
829 
835  template <class EE> Vec<M+1,ELT,1> insert1(int p, const EE& v) const {
836  assert(0 <= p && p <= M);
837  if (p==M) return append1(v);
838  Vec<M+1,ELT,1> out;
839  int nxt=0;
840  for (int i=0; i<M; ++i, ++nxt) {
841  if (i==p) out[nxt++] = v;
842  out[nxt] = (*this)[i];
843  }
844  return out;
845  }
846 
849  static const Vec& getAs(const ELT* p)
850  { return *reinterpret_cast<const Vec*>(p); }
853  static Vec& updAs(ELT* p)
854  { return *reinterpret_cast<Vec*>(p); }
855 
856 
861 
863  bool isNaN() const {
864  for (int i=0; i<M; ++i)
865  if (CNT<ELT>::isNaN((*this)[i]))
866  return true;
867  return false;
868  }
869 
872  bool isInf() const {
873  bool seenInf = false;
874  for (int i=0; i<M; ++i) {
875  const ELT& e = (*this)[i];
876  if (!CNT<ELT>::isFinite(e)) {
877  if (!CNT<ELT>::isInf(e))
878  return false; // something bad was found
879  seenInf = true;
880  }
881  }
882  return seenInf;
883  }
884 
887  bool isFinite() const {
888  for (int i=0; i<M; ++i)
889  if (!CNT<ELT>::isFinite((*this)[i]))
890  return false;
891  return true;
892  }
893 
897 
900  template <class E2, int RS2>
901  bool isNumericallyEqual(const Vec<M,E2,RS2>& v, double tol) const {
902  for (int i=0; i<M; ++i)
903  if (!CNT<ELT>::isNumericallyEqual((*this)[i], v[i], tol))
904  return false;
905  return true;
906  }
907 
911  template <class E2, int RS2>
912  bool isNumericallyEqual(const Vec<M,E2,RS2>& v) const {
913  const double tol = std::max(getDefaultTolerance(),v.getDefaultTolerance());
914  return isNumericallyEqual(v, tol);
915  }
916 
921  bool isNumericallyEqual
922  (const ELT& e,
923  double tol = getDefaultTolerance()) const
924  {
925  for (int i=0; i<M; ++i)
926  if (!CNT<ELT>::isNumericallyEqual((*this)[i], e, tol))
927  return false;
928  return true;
929  }
930 
931  // Functions to be used for Scripting in MATLAB and languages that do not support operator overloading
933  std::string toString() const {
934  std::stringstream stream;
935  stream << (*this);
936  return stream.str();
937  }
938 
940  void set(int i, const E& value)
941  { (*this)[i] = value; }
942 
944  const E& get(int i) const
945  { return operator[](i); }
946 
947 private:
948  // TODO: should be an array of scalars rather than elements to control
949  // packing more carefully.
950  ELT d[NActualElements]; // data
951 };
952 
954 // Global operators involving two vectors. //
955 // v+v, v-v, v==v, v!=v //
957 
958 // v3 = v1 + v2 where all v's have the same length M.
959 template <int M, class E1, int S1, class E2, int S2> inline
960 typename Vec<M,E1,S1>::template Result< Vec<M,E2,S2> >::Add
961 operator+(const Vec<M,E1,S1>& l, const Vec<M,E2,S2>& r) {
962  return Vec<M,E1,S1>::template Result< Vec<M,E2,S2> >
963  ::AddOp::perform(l,r);
964 }
965 
966 // v3 = v1 - v2, similar to +
967 template <int M, class E1, int S1, class E2, int S2> inline
968 typename Vec<M,E1,S1>::template Result< Vec<M,E2,S2> >::Sub
969 operator-(const Vec<M,E1,S1>& l, const Vec<M,E2,S2>& r) {
970  return Vec<M,E1,S1>::template Result< Vec<M,E2,S2> >
971  ::SubOp::perform(l,r);
972 }
973 
975 template <int M, class E1, int S1, class E2, int S2> inline bool
977 { for (int i=0; i < M; ++i) if (l[i] != r[i]) return false;
978  return true; }
980 template <int M, class E1, int S1, class E2, int S2> inline bool
981 operator!=(const Vec<M,E1,S1>& l, const Vec<M,E2,S2>& r) {return !(l==r);}
982 
984 template <int M, class E1, int S1, class E2> inline bool
985 operator==(const Vec<M,E1,S1>& v, const E2& e)
986 { for (int i=0; i < M; ++i) if (v[i] != e) return false;
987  return true; }
989 template <int M, class E1, int S1, class E2> inline bool
990 operator!=(const Vec<M,E1,S1>& v, const E2& e) {return !(v==e);}
991 
993 template <int M, class E1, int S1, class E2, int S2> inline bool
994 operator<(const Vec<M,E1,S1>& l, const Vec<M,E2,S2>& r)
995 { for (int i=0; i < M; ++i) if (l[i] >= r[i]) return false;
996  return true; }
998 template <int M, class E1, int S1, class E2> inline bool
999 operator<(const Vec<M,E1,S1>& v, const E2& e)
1000 { for (int i=0; i < M; ++i) if (v[i] >= e) return false;
1001  return true; }
1002 
1004 template <int M, class E1, int S1, class E2, int S2> inline bool
1006 { for (int i=0; i < M; ++i) if (l[i] <= r[i]) return false;
1007  return true; }
1009 template <int M, class E1, int S1, class E2> inline bool
1010 operator>(const Vec<M,E1,S1>& v, const E2& e)
1011 { for (int i=0; i < M; ++i) if (v[i] <= e) return false;
1012  return true; }
1013 
1016 template <int M, class E1, int S1, class E2, int S2> inline bool
1017 operator<=(const Vec<M,E1,S1>& l, const Vec<M,E2,S2>& r)
1018 { for (int i=0; i < M; ++i) if (l[i] > r[i]) return false;
1019  return true; }
1022 template <int M, class E1, int S1, class E2> inline bool
1023 operator<=(const Vec<M,E1,S1>& v, const E2& e)
1024 { for (int i=0; i < M; ++i) if (v[i] > e) return false;
1025  return true; }
1026 
1029 template <int M, class E1, int S1, class E2, int S2> inline bool
1031 { for (int i=0; i < M; ++i) if (l[i] < r[i]) return false;
1032  return true; }
1035 template <int M, class E1, int S1, class E2> inline bool
1036 operator>=(const Vec<M,E1,S1>& v, const E2& e)
1037 { for (int i=0; i < M; ++i) if (v[i] < e) return false;
1038  return true; }
1039 
1041 // Global operators involving a vector and a scalar. //
1043 
1044 // I haven't been able to figure out a nice way to templatize for the
1045 // built-in reals without introducing a lot of unwanted type matches
1046 // as well. So we'll just grind them out explicitly here.
1047 
1048 // SCALAR MULTIPLY
1049 
1050 // v = v*real, real*v
1051 template <int M, class E, int S> inline
1052 typename Vec<M,E,S>::template Result<float>::Mul
1053 operator*(const Vec<M,E,S>& l, const float& r)
1054  { return Vec<M,E,S>::template Result<float>::MulOp::perform(l,r); }
1055 template <int M, class E, int S> inline
1056 typename Vec<M,E,S>::template Result<float>::Mul
1057 operator*(const float& l, const Vec<M,E,S>& r) {return r*l;}
1058 
1059 template <int M, class E, int S> inline
1060 typename Vec<M,E,S>::template Result<double>::Mul
1061 operator*(const Vec<M,E,S>& l, const double& r)
1062  { return Vec<M,E,S>::template Result<double>::MulOp::perform(l,r); }
1063 template <int M, class E, int S> inline
1064 typename Vec<M,E,S>::template Result<double>::Mul
1065 operator*(const double& l, const Vec<M,E,S>& r) {return r*l;}
1066 
1067 template <int M, class E, int S> inline
1068 typename Vec<M,E,S>::template Result<long double>::Mul
1069 operator*(const Vec<M,E,S>& l, const long double& r)
1070  { return Vec<M,E,S>::template Result<long double>::MulOp::perform(l,r); }
1071 template <int M, class E, int S> inline
1072 typename Vec<M,E,S>::template Result<long double>::Mul
1073 operator*(const long double& l, const Vec<M,E,S>& r) {return r*l;}
1074 
1075 // v = v*int, int*v -- just convert int to v's precision float
1076 template <int M, class E, int S> inline
1077 typename Vec<M,E,S>::template Result<typename CNT<E>::Precision>::Mul
1078 operator*(const Vec<M,E,S>& l, int r) {return l * (typename CNT<E>::Precision)r;}
1079 template <int M, class E, int S> inline
1080 typename Vec<M,E,S>::template Result<typename CNT<E>::Precision>::Mul
1081 operator*(int l, const Vec<M,E,S>& r) {return r * (typename CNT<E>::Precision)l;}
1082 
1083 // Complex, conjugate, and negator are all easy to templatize.
1084 
1085 // v = v*complex, complex*v
1086 template <int M, class E, int S, class R> inline
1087 typename Vec<M,E,S>::template Result<std::complex<R> >::Mul
1088 operator*(const Vec<M,E,S>& l, const std::complex<R>& r)
1089  { return Vec<M,E,S>::template Result<std::complex<R> >::MulOp::perform(l,r); }
1090 template <int M, class E, int S, class R> inline
1091 typename Vec<M,E,S>::template Result<std::complex<R> >::Mul
1092 operator*(const std::complex<R>& l, const Vec<M,E,S>& r) {return r*l;}
1093 
1094 // v = v*conjugate, conjugate*v (convert conjugate->complex)
1095 template <int M, class E, int S, class R> inline
1096 typename Vec<M,E,S>::template Result<std::complex<R> >::Mul
1097 operator*(const Vec<M,E,S>& l, const conjugate<R>& r) {return l*(std::complex<R>)r;}
1098 template <int M, class E, int S, class R> inline
1099 typename Vec<M,E,S>::template Result<std::complex<R> >::Mul
1100 operator*(const conjugate<R>& l, const Vec<M,E,S>& r) {return r*(std::complex<R>)l;}
1101 
1102 // v = v*negator, negator*v: convert negator to standard number
1103 template <int M, class E, int S, class R> inline
1104 typename Vec<M,E,S>::template Result<typename negator<R>::StdNumber>::Mul
1105 operator*(const Vec<M,E,S>& l, const negator<R>& r) {return l * (typename negator<R>::StdNumber)(R)r;}
1106 template <int M, class E, int S, class R> inline
1107 typename Vec<M,E,S>::template Result<typename negator<R>::StdNumber>::Mul
1108 operator*(const negator<R>& l, const Vec<M,E,S>& r) {return r * (typename negator<R>::StdNumber)(R)l;}
1109 
1110 
1111 // SCALAR DIVIDE. This is a scalar operation when the scalar is on the right,
1112 // but when it is on the left it means scalar * pseudoInverse(vec), which is
1113 // a row.
1114 
1115 // v = v/real, real/v
1116 template <int M, class E, int S> inline
1117 typename Vec<M,E,S>::template Result<float>::Dvd
1118 operator/(const Vec<M,E,S>& l, const float& r)
1119  { return Vec<M,E,S>::template Result<float>::DvdOp::perform(l,r); }
1120 template <int M, class E, int S> inline
1121 typename CNT<float>::template Result<Vec<M,E,S> >::Dvd
1122 operator/(const float& l, const Vec<M,E,S>& r)
1123  { return CNT<float>::template Result<Vec<M,E,S> >::DvdOp::perform(l,r); }
1124 
1125 template <int M, class E, int S> inline
1126 typename Vec<M,E,S>::template Result<double>::Dvd
1127 operator/(const Vec<M,E,S>& l, const double& r)
1128  { return Vec<M,E,S>::template Result<double>::DvdOp::perform(l,r); }
1129 template <int M, class E, int S> inline
1130 typename CNT<double>::template Result<Vec<M,E,S> >::Dvd
1131 operator/(const double& l, const Vec<M,E,S>& r)
1132  { return CNT<double>::template Result<Vec<M,E,S> >::DvdOp::perform(l,r); }
1133 
1134 template <int M, class E, int S> inline
1135 typename Vec<M,E,S>::template Result<long double>::Dvd
1136 operator/(const Vec<M,E,S>& l, const long double& r)
1137  { return Vec<M,E,S>::template Result<long double>::DvdOp::perform(l,r); }
1138 template <int M, class E, int S> inline
1139 typename CNT<long double>::template Result<Vec<M,E,S> >::Dvd
1140 operator/(const long double& l, const Vec<M,E,S>& r)
1141  { return CNT<long double>::template Result<Vec<M,E,S> >::DvdOp::perform(l,r); }
1142 
1143 // v = v/int, int/v -- just convert int to v's precision float
1144 template <int M, class E, int S> inline
1145 typename Vec<M,E,S>::template Result<typename CNT<E>::Precision>::Dvd
1146 operator/(const Vec<M,E,S>& l, int r) {return l / (typename CNT<E>::Precision)r;}
1147 template <int M, class E, int S> inline
1148 typename CNT<typename CNT<E>::Precision>::template Result<Vec<M,E,S> >::Dvd
1149 operator/(int l, const Vec<M,E,S>& r) {return (typename CNT<E>::Precision)l / r;}
1150 
1151 
1152 // Complex, conjugate, and negator are all easy to templatize.
1153 
1154 // v = v/complex, complex/v
1155 template <int M, class E, int S, class R> inline
1156 typename Vec<M,E,S>::template Result<std::complex<R> >::Dvd
1157 operator/(const Vec<M,E,S>& l, const std::complex<R>& r)
1158  { return Vec<M,E,S>::template Result<std::complex<R> >::DvdOp::perform(l,r); }
1159 template <int M, class E, int S, class R> inline
1160 typename CNT<std::complex<R> >::template Result<Vec<M,E,S> >::Dvd
1161 operator/(const std::complex<R>& l, const Vec<M,E,S>& r)
1162  { return CNT<std::complex<R> >::template Result<Vec<M,E,S> >::DvdOp::perform(l,r); }
1163 
1164 // v = v/conjugate, conjugate/v (convert conjugate->complex)
1165 template <int M, class E, int S, class R> inline
1166 typename Vec<M,E,S>::template Result<std::complex<R> >::Dvd
1167 operator/(const Vec<M,E,S>& l, const conjugate<R>& r) {return l/(std::complex<R>)r;}
1168 template <int M, class E, int S, class R> inline
1169 typename CNT<std::complex<R> >::template Result<Vec<M,E,S> >::Dvd
1170 operator/(const conjugate<R>& l, const Vec<M,E,S>& r) {return (std::complex<R>)l/r;}
1171 
1172 // v = v/negator, negator/v: convert negator to number
1173 template <int M, class E, int S, class R> inline
1174 typename Vec<M,E,S>::template Result<typename negator<R>::StdNumber>::Dvd
1175 operator/(const Vec<M,E,S>& l, const negator<R>& r) {return l/(typename negator<R>::StdNumber)(R)r;}
1176 template <int M, class E, int S, class R> inline
1177 typename CNT<R>::template Result<Vec<M,E,S> >::Dvd
1178 operator/(const negator<R>& l, const Vec<M,E,S>& r) {return (typename negator<R>::StdNumber)(R)l/r;}
1179 
1180 
1181 // Add and subtract are odd as scalar ops. They behave as though the
1182 // scalar stands for a vector each of whose elements is that scalar,
1183 // and then a normal vector add or subtract is done.
1184 
1185 // SCALAR ADD
1186 
1187 // v = v+real, real+v
1188 template <int M, class E, int S> inline
1189 typename Vec<M,E,S>::template Result<float>::Add
1190 operator+(const Vec<M,E,S>& l, const float& r)
1191  { return Vec<M,E,S>::template Result<float>::AddOp::perform(l,r); }
1192 template <int M, class E, int S> inline
1193 typename Vec<M,E,S>::template Result<float>::Add
1194 operator+(const float& l, const Vec<M,E,S>& r) {return r+l;}
1195 
1196 template <int M, class E, int S> inline
1197 typename Vec<M,E,S>::template Result<double>::Add
1198 operator+(const Vec<M,E,S>& l, const double& r)
1199  { return Vec<M,E,S>::template Result<double>::AddOp::perform(l,r); }
1200 template <int M, class E, int S> inline
1201 typename Vec<M,E,S>::template Result<double>::Add
1202 operator+(const double& l, const Vec<M,E,S>& r) {return r+l;}
1203 
1204 template <int M, class E, int S> inline
1205 typename Vec<M,E,S>::template Result<long double>::Add
1206 operator+(const Vec<M,E,S>& l, const long double& r)
1207  { return Vec<M,E,S>::template Result<long double>::AddOp::perform(l,r); }
1208 template <int M, class E, int S> inline
1209 typename Vec<M,E,S>::template Result<long double>::Add
1210 operator+(const long double& l, const Vec<M,E,S>& r) {return r+l;}
1211 
1212 // v = v+int, int+v -- just convert int to v's precision float
1213 template <int M, class E, int S> inline
1214 typename Vec<M,E,S>::template Result<typename CNT<E>::Precision>::Add
1215 operator+(const Vec<M,E,S>& l, int r) {return l + (typename CNT<E>::Precision)r;}
1216 template <int M, class E, int S> inline
1217 typename Vec<M,E,S>::template Result<typename CNT<E>::Precision>::Add
1218 operator+(int l, const Vec<M,E,S>& r) {return r + (typename CNT<E>::Precision)l;}
1219 
1220 // Complex, conjugate, and negator are all easy to templatize.
1221 
1222 // v = v+complex, complex+v
1223 template <int M, class E, int S, class R> inline
1224 typename Vec<M,E,S>::template Result<std::complex<R> >::Add
1225 operator+(const Vec<M,E,S>& l, const std::complex<R>& r)
1226  { return Vec<M,E,S>::template Result<std::complex<R> >::AddOp::perform(l,r); }
1227 template <int M, class E, int S, class R> inline
1228 typename Vec<M,E,S>::template Result<std::complex<R> >::Add
1229 operator+(const std::complex<R>& l, const Vec<M,E,S>& r) {return r+l;}
1230 
1231 // v = v+conjugate, conjugate+v (convert conjugate->complex)
1232 template <int M, class E, int S, class R> inline
1233 typename Vec<M,E,S>::template Result<std::complex<R> >::Add
1234 operator+(const Vec<M,E,S>& l, const conjugate<R>& r) {return l+(std::complex<R>)r;}
1235 template <int M, class E, int S, class R> inline
1236 typename Vec<M,E,S>::template Result<std::complex<R> >::Add
1237 operator+(const conjugate<R>& l, const Vec<M,E,S>& r) {return r+(std::complex<R>)l;}
1238 
1239 // v = v+negator, negator+v: convert negator to standard number
1240 template <int M, class E, int S, class R> inline
1241 typename Vec<M,E,S>::template Result<typename negator<R>::StdNumber>::Add
1242 operator+(const Vec<M,E,S>& l, const negator<R>& r) {return l + (typename negator<R>::StdNumber)(R)r;}
1243 template <int M, class E, int S, class R> inline
1244 typename Vec<M,E,S>::template Result<typename negator<R>::StdNumber>::Add
1245 operator+(const negator<R>& l, const Vec<M,E,S>& r) {return r + (typename negator<R>::StdNumber)(R)l;}
1246 
1247 // SCALAR SUBTRACT -- careful, not commutative.
1248 
1249 // v = v-real, real-v
1250 template <int M, class E, int S> inline
1251 typename Vec<M,E,S>::template Result<float>::Sub
1252 operator-(const Vec<M,E,S>& l, const float& r)
1253  { return Vec<M,E,S>::template Result<float>::SubOp::perform(l,r); }
1254 template <int M, class E, int S> inline
1255 typename CNT<float>::template Result<Vec<M,E,S> >::Sub
1256 operator-(const float& l, const Vec<M,E,S>& r)
1257  { return CNT<float>::template Result<Vec<M,E,S> >::SubOp::perform(l,r); }
1258 
1259 template <int M, class E, int S> inline
1260 typename Vec<M,E,S>::template Result<double>::Sub
1261 operator-(const Vec<M,E,S>& l, const double& r)
1262  { return Vec<M,E,S>::template Result<double>::SubOp::perform(l,r); }
1263 template <int M, class E, int S> inline
1264 typename CNT<double>::template Result<Vec<M,E,S> >::Sub
1265 operator-(const double& l, const Vec<M,E,S>& r)
1266  { return CNT<double>::template Result<Vec<M,E,S> >::SubOp::perform(l,r); }
1267 
1268 template <int M, class E, int S> inline
1269 typename Vec<M,E,S>::template Result<long double>::Sub
1270 operator-(const Vec<M,E,S>& l, const long double& r)
1271  { return Vec<M,E,S>::template Result<long double>::SubOp::perform(l,r); }
1272 template <int M, class E, int S> inline
1273 typename CNT<long double>::template Result<Vec<M,E,S> >::Sub
1274 operator-(const long double& l, const Vec<M,E,S>& r)
1275  { return CNT<long double>::template Result<Vec<M,E,S> >::SubOp::perform(l,r); }
1276 
1277 // v = v-int, int-v // just convert int to v's precision float
1278 template <int M, class E, int S> inline
1279 typename Vec<M,E,S>::template Result<typename CNT<E>::Precision>::Sub
1280 operator-(const Vec<M,E,S>& l, int r) {return l - (typename CNT<E>::Precision)r;}
1281 template <int M, class E, int S> inline
1282 typename CNT<typename CNT<E>::Precision>::template Result<Vec<M,E,S> >::Sub
1283 operator-(int l, const Vec<M,E,S>& r) {return (typename CNT<E>::Precision)l - r;}
1284 
1285 
1286 // Complex, conjugate, and negator are all easy to templatize.
1287 
1288 // v = v-complex, complex-v
1289 template <int M, class E, int S, class R> inline
1290 typename Vec<M,E,S>::template Result<std::complex<R> >::Sub
1291 operator-(const Vec<M,E,S>& l, const std::complex<R>& r)
1292  { return Vec<M,E,S>::template Result<std::complex<R> >::SubOp::perform(l,r); }
1293 template <int M, class E, int S, class R> inline
1294 typename CNT<std::complex<R> >::template Result<Vec<M,E,S> >::Sub
1295 operator-(const std::complex<R>& l, const Vec<M,E,S>& r)
1296  { return CNT<std::complex<R> >::template Result<Vec<M,E,S> >::SubOp::perform(l,r); }
1297 
1298 // v = v-conjugate, conjugate-v (convert conjugate->complex)
1299 template <int M, class E, int S, class R> inline
1300 typename Vec<M,E,S>::template Result<std::complex<R> >::Sub
1301 operator-(const Vec<M,E,S>& l, const conjugate<R>& r) {return l-(std::complex<R>)r;}
1302 template <int M, class E, int S, class R> inline
1303 typename CNT<std::complex<R> >::template Result<Vec<M,E,S> >::Sub
1304 operator-(const conjugate<R>& l, const Vec<M,E,S>& r) {return (std::complex<R>)l-r;}
1305 
1306 // v = v-negator, negator-v: convert negator to standard number
1307 template <int M, class E, int S, class R> inline
1308 typename Vec<M,E,S>::template Result<typename negator<R>::StdNumber>::Sub
1309 operator-(const Vec<M,E,S>& l, const negator<R>& r) {return l-(typename negator<R>::StdNumber)(R)r;}
1310 template <int M, class E, int S, class R> inline
1311 typename CNT<R>::template Result<Vec<M,E,S> >::Sub
1312 operator-(const negator<R>& l, const Vec<M,E,S>& r) {return (typename negator<R>::StdNumber)(R)l-r;}
1313 
1314 // Vec I/O
1315 template <int M, class E, int S, class CHAR, class TRAITS> inline
1316 std::basic_ostream<CHAR,TRAITS>&
1317 operator<<(std::basic_ostream<CHAR,TRAITS>& o, const Vec<M,E,S>& v) {
1318  o << "~[" << v[0]; for(int i=1;i<M;++i) o<<','<<v[i]; o<<']'; return o;
1319 }
1320 
1323 template <int M, class E, int S, class CHAR, class TRAITS> inline
1324 std::basic_istream<CHAR,TRAITS>&
1325 operator>>(std::basic_istream<CHAR,TRAITS>& is, Vec<M,E,S>& v) {
1326  CHAR tilde;
1327  is >> tilde; if (is.fail()) return is;
1328  if (tilde != CHAR('~')) {
1329  tilde = CHAR(0);
1330  is.unget(); if (is.fail()) return is;
1331  }
1332 
1333  CHAR openBracket, closeBracket;
1334  is >> openBracket; if (is.fail()) return is;
1335  if (openBracket==CHAR('('))
1336  closeBracket = CHAR(')');
1337  else if (openBracket==CHAR('['))
1338  closeBracket = CHAR(']');
1339  else {
1340  closeBracket = CHAR(0);
1341  is.unget(); if (is.fail()) return is;
1342  }
1343 
1344  // If we saw a "~" but then we didn't see any brackets, that's an
1345  // error. Set the fail bit and return.
1346  if (tilde != CHAR(0) && closeBracket == CHAR(0)) {
1347  is.setstate( std::ios::failbit );
1348  return is;
1349  }
1350 
1351  for (int i=0; i < M; ++i) {
1352  is >> v[i];
1353  if (is.fail()) return is;
1354  if (i != M-1) {
1355  CHAR c; is >> c; if (is.fail()) return is;
1356  if (c != ',') is.unget();
1357  if (is.fail()) return is;
1358  }
1359  }
1360 
1361  // Get the closing bracket if there was an opening one. If we don't
1362  // see the expected character we'll set the fail bit in the istream.
1363  if (closeBracket != CHAR(0)) {
1364  CHAR closer; is >> closer; if (is.fail()) return is;
1365  if (closer != closeBracket) {
1366  is.unget(); if (is.fail()) return is;
1367  is.setstate( std::ios::failbit );
1368  }
1369  }
1370 
1371  return is;
1372 }
1373 
1374 } //namespace SimTK
1375 
1376 
1377 #endif //SimTK_SIMMATRIX_SMALLMATRIX_VEC_H_
Matrix_< E > operator/(const MatrixBase< E > &l, const typename CNT< E >::StdNumber &r)
Definition: BigMatrix.h:2693
TImag & imag()
Recast to show only the imaginary portion of this Vec and return a writable reference.
Definition: Vec.h:644
std::string toString() const
Print Vec into a string and return it.
Definition: Vec.h:933
bool isFinite() const
Return true if no element of this Vec contains an Infinity or a NaN anywhere.
Definition: Vec.h:887
TAbs abs() const
Elementwise absolute value; that is, the return value has the same dimension as this Vec but with eac...
Definition: Vec.h:292
CNT< E >::TSqHermT ESqHermT
Type of the expression ~E*E (default vector and matrix square; symmetric).
Definition: Vec.h:159
K::ScalarNormSq ScalarNormSq
Definition: CompositeNumericalTypes.h:166
SubOp::Type Sub
Definition: Vec.h:355
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:860
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:590
static int size()
The number of elements in this Vec (note that stride does not affect this number.) ...
Definition: Vec.h:263
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:453
Vec< M, P > Type
Definition: Vec.h:364
K::TReal TReal
Definition: CompositeNumericalTypes.h:141
CNT< E >::TSqrt ESqrt
Type required to hold the result of sqrt(E).
Definition: Vec.h:163
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:637
ScalarNormSq scalarNormSqr() const
Scalar norm square is sum( conjugate squares of all underlying scalars ), where conjugate square of s...
Definition: Vec.h:272
Vec< M, typename CNT< E >::template Result< EE >::Dvd > elementwiseDivide(const Vec< M, EE, SS > &r) const
Elementwise divide (Matlab .
Definition: Vec.h:532
RS is total spacing between rows in memory (default 1)
Definition: SymMat.h:71
const E & operator[](int i) const
Select an element of this Vec and return a const reference to it.
Definition: Vec.h:541
SymMat< M, ESqTHerm > TSqTHerm
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:249
Vec< M, typename CNT< EE >::template Result< E >::Sub > scalarSubtractFromLeft(const EE &e) const
Definition: Vec.h:711
Vec & scalarEq(const EE &ee)
Definition: Vec.h:728
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:149
MulOp::Type Mul
Definition: Vec.h:335
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:145
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:282
Vec & scalarTimesEq(const EE &ee)
Definition: Vec.h:736
Vec & scalarTimesEqFromLeft(int ee)
Definition: Vec.h:752
bool isNaN() const
Return true if any element of this Vec contains a NaN anywhere.
Definition: Vec.h:863
SimTK::conjugate<R> should be instantiated only for float, double, long double.
Definition: String.h:45
K::TSqrt TSqrt
Definition: CompositeNumericalTypes.h:154
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:808
TWithoutNegator & updCastAwayNegatorIfAny()
Recast to remove negators from this Vec's type if present and return a writable reference.
Definition: Vec.h:657
Vec(const E &e)
Construction from a single value of this Vec's element type assigns that value to each element...
Definition: Vec.h:415
TInvert invert() const
This method is not supported for Vec objects.
Definition: Vec.h:580
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:853
Vec< M, ESqrt, 1 > TSqrt
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:242
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:468
Definition: Vec.h:322
TNeg & updNegate()
Non-operator version of unary negation; recasts and returns a writable reference. ...
Definition: Vec.h:604
K::Scalar Scalar
Definition: CompositeNumericalTypes.h:160
ESqHermT TSqHermT
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:248
Vec & operator+=(const EE &e)
Definition: Vec.h:721
CNT< E >::TNormalize ENormalize
Packed type that can hold the value returned from normalize(E).
Definition: Vec.h:173
K::TNormalize TNormalize
Definition: CompositeNumericalTypes.h:158
Vec< M, typename CNT< EE >::template Result< E >::Mul > scalarMultiplyFromLeft(const EE &e) const
Definition: Vec.h:675
E TElement
Element type of this Vec.
Definition: Vec.h:234
Vec< M, typename CNT< E >::template Result< EE >::Mul > elementwiseMultiply(const Vec< M, EE, SS > &r) const
Elementwise multiply (Matlab .
Definition: Vec.h:525
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:447
static int nrow()
The number of rows in a Vec is the number of elements.
Definition: Vec.h:265
E & operator[](int i)
Select an element of this Vec and return a writable reference to it.
Definition: Vec.h:549
Definition: Vec.h:189
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:450
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:178
Vec(const E &e0, const E &e1)
Construct a Vec<2,E> from two elements of type E, etc.
Definition: Vec.h:435
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:302
void set(int i, const E &value)
Variant of operator[] that's scripting friendly to set ith entry.
Definition: Vec.h:940
Vec< M, typename CNT< E >::template Result< P >::Mul, 1 > Mul
Definition: Vec.h:323
Vec & operator-=(const EE &e)
Definition: Vec.h:722
EStdNumber StdNumber
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:256
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:349
std::basic_istream< CHAR, TRAITS > & operator>>(std::basic_istream< CHAR, TRAITS > &is, conjugate< R > &c)
Definition: conjugate.h:800
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:461
Vec< M, EAbs, 1 > TAbs
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:243
negator<N>, where N is a number type (real, complex, conjugate), is represented in memory identically...
Definition: String.h:44
Definition: CompositeNumericalTypes.h:120
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:154
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:835
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:587
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:354
TPosTrans & updPositionalTranspose()
Positional transpose returning a writable reference.
Definition: Vec.h:619
Vec(const Vec &src)
Copy constructor copies the logically-included elements from the source Vec; gaps due to stride are n...
Definition: Vec.h:383
Definition: Vec.h:186
bool operator==(const PhiMatrix &p1, const PhiMatrix &p2)
Definition: SpatialAlgebra.h:774
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:168
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:439
Definition: Vec.h:190
Definition: Vec.h:192
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:220
CNT< E >::Scalar EScalar
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:175
EPrecision Precision
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:257
CNT< E >::TPosTrans EPosTrans
Type of a positional transpose of an element of this Vec.
Definition: Vec.h:156
CNT< E >::TSqTHerm ESqTHerm
Type of the expression E*~E ("row square"; symmetric).
Definition: Vec.h:161
Vec< M, typename CNT< E >::template Result< P >::Add, 1 > Add
Definition: Vec.h:325
Vec< M, EStandard, 1 > TStandard
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:244
Vec & scalarMinusEqFromLeft(int ee)
Definition: Vec.h:751
Vec & scalarPlusEq(const EE &ee)
Definition: Vec.h:730
const E & operator()(int i) const
Same as const operator[] above.
Definition: Vec.h:544
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:483
Vec< M, E, STRIDE > T
The type of this Vec.
Definition: Vec.h:210
CNT< E >::ScalarNormSq EScalarNormSq
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:180
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:517
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:403
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:311
Definition: Vec.h:199
Definition: Vec.h:193
This is a fixed length column vector designed for no-overhead inline computation. ...
Definition: Vec.h:131
Definition: Vec.h:202
const Vec & operator+() const
Unary plus does nothing.
Definition: Vec.h:583
Row< M, EInvert, 1 > TInvert
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:245
const TNeg & negate() const
Non-operator version of unary negation; just a recast.
Definition: Vec.h:601
Vec(const Vec< M, EE, SS > &src)
Construct a Vec from a Vec of the same length, with any stride.
Definition: Vec.h:409
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:626
const THerm & operator~() const
The Hermitian transpose operator recasts this Vec to a type that specifies the opposite storage order...
Definition: Vec.h:594
Vec< M, typename CNT< E >::template Result< EE >::Mul > scalarMultiply(const EE &e) const
Definition: Vec.h:669
static double getDefaultTolerance()
For approximate comparisions, the default tolerance to use for a vector is the same as its elements' ...
Definition: Vec.h:896
K::Precision Precision
Definition: CompositeNumericalTypes.h:164
Vec & scalarEq(int ee)
Definition: Vec.h:746
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:229
ENumber Number
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:255
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:757
Matrix_< E > operator*(const MatrixBase< E > &l, const typename CNT< E >::StdNumber &r)
Definition: BigMatrix.h:2685
Definition: Vec.h:188
Vec< M, typename CNT< E >::template Result< EE >::Add > scalarAdd(const EE &e) const
Definition: Vec.h:697
Definition: Vec.h:187
void setToZero()
Set every scalar in this Vec to zero.
Definition: Vec.h:762
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:598
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:901
Vec & operator=(const Vec &src)
Copy assignment operator copies the logically-included elements from the source Vec; gaps due to stri...
Definition: Vec.h:390
Vec(const E &e0, const E &e1, const E &e2)
Definition: Vec.h:437
MulOpNonConforming::Type MulNon
Definition: Vec.h:340
ELEM max(const VectorBase< ELEM > &v)
Definition: VectorMath.h:251
Definition: Vec.h:195
NTraits< N >::StdNumber StdNumber
Definition: negator.h:107
Vec & scalarMinusEq(int ee)
Definition: Vec.h:748
Shape-preserving element substitution (always packed).
Definition: Vec.h:363
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:501
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:339
Definition: Vec.h:191
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:568
Vec & operator/=(const EE &e)
Definition: Vec.h:724
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:792
bool operator>=(const Row< N, E1, S1 > &l, const Row< N, E2, S2 > &r)
bool = v1[i] >= v2[i], for all elements i This is not the same as !(v1<v2).
Definition: Row.h:844
CNT< E >::TWithoutNegator EWithoutNegator
Element type, stripped of negator<> if it has one.
Definition: Vec.h:142
Definition: Vec.h:331
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:152
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:421
Definition: Vec.h:185
K::TPosTrans TPosTrans
Definition: CompositeNumericalTypes.h:145
Vec & operator*=(const EE &e)
Definition: Vec.h:723
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
Definition: Vec.h:203
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:224
TReal & real()
Recast to show only the real portion of this Vec and return a writable reference. ...
Definition: Vec.h:629
const TPosTrans & positionalTranspose() const
Positional transpose turns this Vec into a Row but does not transpose the individual elements...
Definition: Vec.h:616
CNT< E >::TAbs EAbs
Type required to hold the result of abs(E).
Definition: Vec.h:165
K::StdNumber StdNumber
Definition: CompositeNumericalTypes.h:163
RowVectorBase< typename CNT< ELEM >::TAbs > abs(const RowVectorBase< ELEM > &v)
Definition: VectorMath.h:120
Vec & scalarTimesEqFromLeft(const EE &ee)
Definition: Vec.h:738
bool operator!=(const conjugate< R > &a, const float &b)
Definition: conjugate.h:859
E TRow
Type of a row of this CNT object (for a Vec, just its element type).
Definition: Vec.h:236
Specialized information about Composite Numerical Types which allows us to define appropriate templat...
Definition: CompositeNumericalTypes.h:136
Vec & scalarPlusEq(int ee)
Definition: Vec.h:747
THerm & updTranspose()
Non-operator version of Hermitian transpose; recasts and returns a writable reference.
Definition: Vec.h:610
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:344
Vec & scalarDivideEq(int ee)
Definition: Vec.h:750
CNT< E >::Precision EPrecision
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:179
Generic Row.
Definition: Row.h:118
Vec & scalarMinusEqFromLeft(const EE &ee)
Definition: Vec.h:734
Definition: Vec.h:200
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:246
E & operator()(int i)
Same as non-const operator[] above.
Definition: Vec.h:551
Vec< M, typename CNT< E >::template Result< EE >::Sub > scalarSubtract(const EE &e) const
Definition: Vec.h:705
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
ScalarNormSq normSqr() const
Definition: Vec.h:553
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:473
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
Definition: Vec.h:201
const THerm & transpose() const
Non-operator version of Hermitian transpose; just a recast.
Definition: Vec.h:607
CNT< ScalarNormSq >::TSqrt norm() const
Definition: Vec.h:555
Vec< MM, ELT, STRIDE > & updSubVec(int i)
Extract a writable reference to a sub-Vec with size known at compile time.
Definition: Vec.h:782
Vec< M, typename CNT< E >::template Result< P >::Sub, 1 > Sub
Definition: Vec.h:326
CNT< E >::TInvert EInvert
Packed type that can hold the value returned from invert(E), the inverse type of an element...
Definition: Vec.h:171
Vec< M, EComplex, STRIDE > TComplex
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:225
Definition: Vec.h:198
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:822
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:772
This class represents a small matrix whose size is known at compile time, containing elements of any ...
Definition: Mat.h:51
Vec & scalarDivideEqFromLeft(int ee)
Definition: Vec.h:753
K::TComplex TComplex
Definition: CompositeNumericalTypes.h:143
Vec & scalarTimesEq(int ee)
Definition: Vec.h:749
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:478
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:232
bool isInf() const
Return true if any element of this Vec contains a +Infinity or -Infinity somewhere but no element con...
Definition: Vec.h:872
Vec & scalarDivideEq(const EE &ee)
Definition: Vec.h:740
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:493
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:800
Vec(const E &e0, const E &e1, const E &e2, const E &e3, const E &e4)
Definition: Vec.h:441
Vec< M, ENeg, STRIDE > TNeg
Type this Vec would have if its elements were interpreted as negated.
Definition: Vec.h:213
CNT< E >::Number ENumber
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:177
ELT E
Element type of this Vec.
Definition: Vec.h:138
EScalarNormSq ScalarNormSq
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:258
K::TSqHermT TSqHermT
Definition: CompositeNumericalTypes.h:146
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:912
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:819
Vec(const E &e0, const E &e1, const E &e2, const E &e3, const E &e4, const E &e5)
Definition: Vec.h:444
CNT< E >::ULessScalar EULessScalar
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:176
AddOp::Type Add
Definition: Vec.h:350
Vec TCol
Type of a column of this CNT object (for a Vec, the whole thing).
Definition: Vec.h:238
EULessScalar ULessScalar
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:254
K::THerm THerm
Definition: CompositeNumericalTypes.h:144
Vec()
Default construction initializes Vec's elements to NaN when debugging but leaves them uninitialized g...
Definition: Vec.h:370
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:508
Vec< M, typename CNT< E >::template Result< EE >::Dvd > scalarDivide(const EE &e) const
Definition: Vec.h:684
Vec & scalarMinusEq(const EE &ee)
Definition: Vec.h:732
static int ncol()
The number of columns in a Vec is always 1.
Definition: Vec.h:267
EScalar Scalar
These compile-time constants are required of every Composite Numerical Type (CNT).
Definition: Vec.h:253
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:397
Vec & scalarDivideEqFromLeft(const EE &ee)
Definition: Vec.h:742
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:653
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:430
CNT< E >::TNeg ENeg
Negated version of this Vec's element type; ENeg==negator< E >.
Definition: Vec.h:140
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< M, typename CNT< EE >::template Result< E >::Dvd > scalarDivideFromLeft(const EE &e) const
Definition: Vec.h:690
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:488
DvdOp::Type Dvd
Definition: Vec.h:345
Vec< M, EWithoutNegator, STRIDE > TWithoutNegator
Type of this Vec with negator removed from its element type, if the element is negated.
Definition: Vec.h:216
Vec< M, typename CNT< E >::template Result< P >::Dvd, 1 > Dvd
Definition: Vec.h:324
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:849
K::TAbs TAbs
Definition: CompositeNumericalTypes.h:155
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:334