Simbody  3.5
MatrixBase.h
Go to the documentation of this file.
1 #ifndef SimTK_SIMMATRIX_MATRIXBASE_H_
2 #define SimTK_SIMMATRIX_MATRIXBASE_H_
3 
4 /* -------------------------------------------------------------------------- *
5  * Simbody(tm): SimTKcommon *
6  * -------------------------------------------------------------------------- *
7  * This is part of the SimTK biosimulation toolkit originating from *
8  * Simbios, the NIH National Center for Physics-Based Simulation of *
9  * Biological Structures at Stanford, funded under the NIH Roadmap for *
10  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11  * *
12  * Portions copyright (c) 2005-13 Stanford University and the Authors. *
13  * Authors: Michael Sherman *
14  * Contributors: *
15  * *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17  * not use this file except in compliance with the License. You may obtain a *
18  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19  * *
20  * Unless required by applicable law or agreed to in writing, software *
21  * distributed under the License is distributed on an "AS IS" BASIS, *
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23  * See the License for the specific language governing permissions and *
24  * limitations under the License. *
25  * -------------------------------------------------------------------------- */
26 
31 namespace SimTK {
32 
33 //==============================================================================
34 // MATRIX BASE
35 //==============================================================================
67 // ----------------------------------------------------------------------------
68 template <class ELT> class MatrixBase {
69 public:
70  // These typedefs are handy, but despite appearances you cannot
71  // treat a MatrixBase as a composite numerical type. That is,
72  // CNT<MatrixBase> will not compile, or if it does it won't be
73  // meaningful.
74 
75  typedef ELT E;
76  typedef typename CNT<E>::TNeg ENeg;
78  typedef typename CNT<E>::TReal EReal;
79  typedef typename CNT<E>::TImag EImag;
80  typedef typename CNT<E>::TComplex EComplex;
81  typedef typename CNT<E>::THerm EHerm;
82  typedef typename CNT<E>::TPosTrans EPosTrans;
83 
84  typedef typename CNT<E>::TAbs EAbs;
85  typedef typename CNT<E>::TStandard EStandard;
86  typedef typename CNT<E>::TInvert EInvert;
87  typedef typename CNT<E>::TNormalize ENormalize;
88  typedef typename CNT<E>::TSqHermT ESqHermT;
89  typedef typename CNT<E>::TSqTHerm ESqTHerm;
90 
91  typedef typename CNT<E>::Scalar EScalar;
92  typedef typename CNT<E>::Number ENumber;
93  typedef typename CNT<E>::StdNumber EStdNumber;
94  typedef typename CNT<E>::Precision EPrecision;
96 
97  typedef EScalar Scalar; // the underlying Scalar type
98  typedef ENumber Number; // negator removed from Scalar
99  typedef EStdNumber StdNumber; // conjugate goes to complex
100  typedef EPrecision Precision; // complex removed from StdNumber
101  typedef EScalarNormSq ScalarNormSq; // type of scalar^2
102 
103  typedef MatrixBase<E> T;
111 
116  typedef MatrixBase<ESqHermT> TSqHermT; // ~Mat*Mat
117  typedef MatrixBase<ESqTHerm> TSqTHerm; // Mat*~Mat
118 
120  const MatrixCharacter& getMatrixCharacter() const {return helper.getMatrixCharacter();}
121 
124  void commitTo(const MatrixCommitment& mc)
125  { helper.commitTo(mc); }
126 
127  // This gives the resulting matrix type when (m(i,j) op P) is applied to each element.
128  // It will have element types which are the regular composite result of E op P.
129  template <class P> struct EltResult {
130  typedef MatrixBase<typename CNT<E>::template Result<P>::Mul> Mul;
131  typedef MatrixBase<typename CNT<E>::template Result<P>::Dvd> Dvd;
132  typedef MatrixBase<typename CNT<E>::template Result<P>::Add> Add;
133  typedef MatrixBase<typename CNT<E>::template Result<P>::Sub> Sub;
134  };
135 
137  int nrow() const {return helper.nrow();}
139  int ncol() const {return helper.ncol();}
140 
148  ptrdiff_t nelt() const {return helper.nelt();}
149 
152 
153  enum {
155  CppNScalarsPerElement = sizeof(E) / sizeof(Scalar)
156  };
157 
162 
165  MatrixBase(int m, int n)
167 
173  explicit MatrixBase(const MatrixCommitment& commitment)
174  : helper(NScalarsPerElement,CppNScalarsPerElement,commitment) {}
175 
176 
181  MatrixBase(const MatrixCommitment& commitment, int m, int n)
182  : helper(NScalarsPerElement,CppNScalarsPerElement,commitment,m,n) {}
183 
186  : helper(b.helper.getCharacterCommitment(),
187  b.helper, typename MatrixHelper<Scalar>::DeepCopy()) { }
188 
191  MatrixBase(const TNeg& b)
192  : helper(b.helper.getCharacterCommitment(),
193  b.helper, typename MatrixHelper<Scalar>::DeepCopy()) { }
194 
198  helper.copyAssign(b.helper);
199  return *this;
200  }
201  MatrixBase& operator=(const MatrixBase& b) { return copyAssign(b); }
202 
203 
213  helper.writableViewAssign(const_cast<MatrixHelper<Scalar>&>(src.helper));
214  return *this;
215  }
216 
217  // default destructor
218 
225  MatrixBase(const MatrixCommitment& commitment, int m, int n, const ELT& initialValue)
226  : helper(NScalarsPerElement, CppNScalarsPerElement, commitment, m, n)
227  { helper.fillWith(reinterpret_cast<const Scalar*>(&initialValue)); }
228 
239  MatrixBase(const MatrixCommitment& commitment, int m, int n,
240  const ELT* cppInitialValuesByRow)
241  : helper(NScalarsPerElement, CppNScalarsPerElement, commitment, m, n)
242  { helper.copyInByRowsFromCpp(reinterpret_cast<const Scalar*>(cppInitialValuesByRow)); }
243 
255 
257  MatrixBase(const MatrixCommitment& commitment,
258  const MatrixCharacter& character,
259  int spacing, const Scalar* data) // read only data
261  commitment, character, spacing, data) {}
262 
264  MatrixBase(const MatrixCommitment& commitment,
265  const MatrixCharacter& character,
266  int spacing, Scalar* data) // writable data
268  commitment, character, spacing, data) {}
270 
271  // Create a new MatrixBase from an existing helper. Both shallow and deep copies are possible.
272  MatrixBase(const MatrixCommitment& commitment,
274  const typename MatrixHelper<Scalar>::ShallowCopy& shallow)
275  : helper(commitment, source, shallow) {}
276  MatrixBase(const MatrixCommitment& commitment,
278  const typename MatrixHelper<Scalar>::ShallowCopy& shallow)
279  : helper(commitment, source, shallow) {}
280  MatrixBase(const MatrixCommitment& commitment,
282  const typename MatrixHelper<Scalar>::DeepCopy& deep)
283  : helper(commitment, source, deep) {}
284 
288  void clear() {helper.clear();}
289 
290  MatrixBase& operator*=(const StdNumber& t) { helper.scaleBy(t); return *this; }
291  MatrixBase& operator/=(const StdNumber& t) { helper.scaleBy(StdNumber(1)/t); return *this; }
292  MatrixBase& operator+=(const MatrixBase& r) { helper.addIn(r.helper); return *this; }
293  MatrixBase& operator-=(const MatrixBase& r) { helper.subIn(r.helper); return *this; }
294 
295  template <class EE> MatrixBase(const MatrixBase<EE>& b)
296  : helper(MatrixCommitment(),b.helper, typename MatrixHelper<Scalar>::DeepCopy()) { }
297 
298  template <class EE> MatrixBase& operator=(const MatrixBase<EE>& b)
299  { helper = b.helper; return *this; }
300  template <class EE> MatrixBase& operator+=(const MatrixBase<EE>& b)
301  { helper.addIn(b.helper); return *this; }
302  template <class EE> MatrixBase& operator-=(const MatrixBase<EE>& b)
303  { helper.subIn(b.helper); return *this; }
304 
315  MatrixBase& operator=(const ELT& t) {
316  setToZero(); updDiag().setTo(t);
317  return *this;
318  }
319 
325  template <class S> inline MatrixBase&
326  scalarAssign(const S& s) {
327  setToZero(); updDiag().setTo(s);
328  return *this;
329  }
330 
334  template <class S> inline MatrixBase&
335  scalarAddInPlace(const S& s) {
336  updDiag().elementwiseAddScalarInPlace(s);
337  }
338 
339 
343  template <class S> inline MatrixBase&
345  updDiag().elementwiseSubtractScalarInPlace(s);
346  }
347 
350  template <class S> inline MatrixBase&
352  negateInPlace();
353  updDiag().elementwiseAddScalarInPlace(s); // yes, add
354  }
355 
362  template <class S> inline MatrixBase&
363  scalarMultiplyInPlace(const S&);
364 
368  template <class S> inline MatrixBase&
370 
377  template <class S> inline MatrixBase&
378  scalarDivideInPlace(const S&);
379 
383  template <class S> inline MatrixBase&
384  scalarDivideFromLeftInPlace(const S&);
385 
386 
389  template <class EE> inline MatrixBase&
391 
394  template <class EE> inline void
395  rowScale(const VectorBase<EE>& r, typename EltResult<EE>::Mul& out) const;
396 
397  template <class EE> inline typename EltResult<EE>::Mul
398  rowScale(const VectorBase<EE>& r) const {
399  typename EltResult<EE>::Mul out(nrow(), ncol()); rowScale(r,out); return out;
400  }
401 
404  template <class EE> inline MatrixBase&
406 
407  template <class EE> inline void
408  colScale(const VectorBase<EE>& c, typename EltResult<EE>::Mul& out) const;
409 
410  template <class EE> inline typename EltResult<EE>::Mul
411  colScale(const VectorBase<EE>& c) const {
412  typename EltResult<EE>::Mul out(nrow(), ncol()); colScale(c,out); return out;
413  }
414 
415 
420  template <class ER, class EC> inline MatrixBase&
422 
423  template <class ER, class EC> inline void
424  rowAndColScale(const VectorBase<ER>& r, const VectorBase<EC>& c,
425  typename EltResult<typename VectorBase<ER>::template EltResult<EC>::Mul>::Mul& out) const;
426 
427  template <class ER, class EC> inline typename EltResult<typename VectorBase<ER>::template EltResult<EC>::Mul>::Mul
428  rowAndColScale(const VectorBase<ER>& r, const VectorBase<EC>& c) const {
429  typename EltResult<typename VectorBase<ER>::template EltResult<EC>::Mul>::Mul
430  out(nrow(), ncol());
431  rowAndColScale(r,c,out); return out;
432  }
433 
441  template <class S> inline MatrixBase&
442  elementwiseAssign(const S& s);
443 
446  { return elementwiseAssign<Real>(Real(s)); }
447 
450 
451  void elementwiseInvert(MatrixBase<typename CNT<E>::TInvert>& out) const;
452 
455  elementwiseInvert(out);
456  return out;
457  }
458 
466  template <class S> inline MatrixBase&
467  elementwiseAddScalarInPlace(const S& s);
468 
469  template <class S> inline void
470  elementwiseAddScalar(const S& s, typename EltResult<S>::Add&) const;
471 
472  template <class S> inline typename EltResult<S>::Add
473  elementwiseAddScalar(const S& s) const {
474  typename EltResult<S>::Add out(nrow(), ncol());
475  elementwiseAddScalar(s,out);
476  return out;
477  }
478 
486  template <class S> inline MatrixBase&
488 
489  template <class S> inline void
490  elementwiseSubtractScalar(const S& s, typename EltResult<S>::Sub&) const;
491 
492  template <class S> inline typename EltResult<S>::Sub
493  elementwiseSubtractScalar(const S& s) const {
494  typename EltResult<S>::Sub out(nrow(), ncol());
496  return out;
497  }
498 
507  template <class S> inline MatrixBase&
509 
510  template <class S> inline void
512  const S&,
514 
515  template <class S> inline typename MatrixBase<S>::template EltResult<E>::Sub
516  elementwiseSubtractFromScalar(const S& s) const {
517  typename MatrixBase<S>::template EltResult<E>::Sub out(nrow(), ncol());
518  elementwiseSubtractFromScalar<S>(s,out);
519  return out;
520  }
521 
523  template <class EE> inline MatrixBase&
525 
526  template <class EE> inline void
527  elementwiseMultiply(const MatrixBase<EE>&, typename EltResult<EE>::Mul&) const;
528 
529  template <class EE> inline typename EltResult<EE>::Mul
531  typename EltResult<EE>::Mul out(nrow(), ncol());
532  elementwiseMultiply<EE>(m,out);
533  return out;
534  }
535 
537  template <class EE> inline MatrixBase&
539 
540  template <class EE> inline void
542  const MatrixBase<EE>&,
544 
545  template <class EE> inline typename MatrixBase<EE>::template EltResult<E>::Mul
547  typename EltResult<EE>::Mul out(nrow(), ncol());
548  elementwiseMultiplyFromLeft<EE>(m,out);
549  return out;
550  }
551 
553  template <class EE> inline MatrixBase&
555 
556  template <class EE> inline void
557  elementwiseDivide(const MatrixBase<EE>&, typename EltResult<EE>::Dvd&) const;
558 
559  template <class EE> inline typename EltResult<EE>::Dvd
561  typename EltResult<EE>::Dvd out(nrow(), ncol());
562  elementwiseDivide<EE>(m,out);
563  return out;
564  }
565 
567  template <class EE> inline MatrixBase&
569 
570  template <class EE> inline void
572  const MatrixBase<EE>&,
574 
575  template <class EE> inline typename MatrixBase<EE>::template EltResult<EE>::Dvd
577  typename MatrixBase<EE>::template EltResult<E>::Dvd out(nrow(), ncol());
578  elementwiseDivideFromLeft<EE>(m,out);
579  return out;
580  }
581 
583  MatrixBase& setTo(const ELT& t) {helper.fillWith(reinterpret_cast<const Scalar*>(&t)); return *this;}
584  MatrixBase& setToNaN() {helper.fillWithScalar(CNT<StdNumber>::getNaN()); return *this;}
585  MatrixBase& setToZero() {helper.fillWithScalar(StdNumber(0)); return *this;}
586 
587  // View creating operators.
588  inline RowVectorView_<ELT> row(int i) const; // select a row
589  inline RowVectorView_<ELT> updRow(int i);
590  inline VectorView_<ELT> col(int j) const; // select a column
591  inline VectorView_<ELT> updCol(int j);
592 
593  RowVectorView_<ELT> operator[](int i) const {return row(i);}
595  VectorView_<ELT> operator()(int j) const {return col(j);}
596  VectorView_<ELT> operator()(int j) {return updCol(j);}
597 
598  // Select a block.
599  inline MatrixView_<ELT> block(int i, int j, int m, int n) const;
600  inline MatrixView_<ELT> updBlock(int i, int j, int m, int n);
601 
602  MatrixView_<ELT> operator()(int i, int j, int m, int n) const
603  { return block(i,j,m,n); }
604  MatrixView_<ELT> operator()(int i, int j, int m, int n)
605  { return updBlock(i,j,m,n); }
606 
607  // Hermitian transpose.
608  inline MatrixView_<EHerm> transpose() const;
610 
613 
616  inline VectorView_<ELT> diag() const;
619  inline VectorView_<ELT> updDiag();
623 
624  // Create a view of the real or imaginary elements. TODO
625  //inline MatrixView_<EReal> real() const;
626  //inline MatrixView_<EReal> updReal();
627  //inline MatrixView_<EImag> imag() const;
628  //inline MatrixView_<EImag> updImag();
629 
630  // Overload "real" and "imag" for both read and write as a nod to convention. TODO
631  //MatrixView_<EReal> real() {return updReal();}
632  //MatrixView_<EReal> imag() {return updImag();}
633 
634  // TODO: this routine seems ill-advised but I need it for the IVM port at the moment
635  TInvert invert() const { // return a newly-allocated inverse; dump negator
636  TInvert m(*this);
637  m.helper.invertInPlace();
638  return m; // TODO - bad: makes an extra copy
639  }
640 
641  void invertInPlace() {helper.invertInPlace();}
642 
644  void dump(const char* msg=0) const {
645  helper.dump(msg);
646  }
647 
656  const ELT& getElt(int i, int j) const { return *reinterpret_cast<const ELT*>(helper.getElt(i,j)); }
657  ELT& updElt(int i, int j) { return *reinterpret_cast< ELT*>(helper.updElt(i,j)); }
658 
659  const ELT& operator()(int i, int j) const {return getElt(i,j);}
660  ELT& operator()(int i, int j) {return updElt(i,j);}
661 
666  void getAnyElt(int i, int j, ELT& value) const
667  { helper.getAnyElt(i,j,reinterpret_cast<Scalar*>(&value)); }
668  ELT getAnyElt(int i, int j) const {ELT e; getAnyElt(i,j,e); return e;}
669 
672  // TODO: very slow! Should be optimized at least for the case
673  // where ELT is a Scalar.
674  ScalarNormSq scalarNormSqr() const {
675  const int nr=nrow(), nc=ncol();
676  ScalarNormSq sum(0);
677  for(int j=0;j<nc;++j)
678  for (int i=0; i<nr; ++i)
679  sum += CNT<E>::scalarNormSqr((*this)(i,j));
680  return sum;
681  }
682 
686  // TODO: very slow! Should be optimized at least for the case
687  // where ELT is a Scalar.
688  void abs(TAbs& mabs) const {
689  const int nr=nrow(), nc=ncol();
690  mabs.resize(nr,nc);
691  for(int j=0;j<nc;++j)
692  for (int i=0; i<nr; ++i)
693  mabs(i,j) = CNT<E>::abs((*this)(i,j));
694  }
695 
699  TAbs abs() const { TAbs mabs; abs(mabs); return mabs; }
700 
711  TStandard standardize() const {
712  const int nr=nrow(), nc=ncol();
713  TStandard mstd(nr, nc);
714  for(int j=0;j<nc;++j)
715  for (int i=0; i<nr; ++i)
716  mstd(i,j) = CNT<E>::standardize((*this)(i,j));
717  return mstd;
718  }
719 
723  ScalarNormSq normSqr() const { return scalarNormSqr(); }
724  // TODO -- not good; unnecessary overflow
725  typename CNT<ScalarNormSq>::TSqrt
727 
731  typename CNT<ScalarNormSq>::TSqrt
732  normRMS() const {
733  if (!CNT<ELT>::IsScalar)
734  SimTK_THROW1(Exception::Cant, "normRMS() only defined for scalar elements");
735  if (nelt() == 0)
736  return typename CNT<ScalarNormSq>::TSqrt(0);
738  }
739 
742  const int cols = ncol();
743  RowVector_<ELT> row(cols);
744  for (int j = 0; j < cols; ++j)
745  helper.colSum(j, reinterpret_cast<Scalar*>(&row[j]));
746  return row;
747  }
749  RowVector_<ELT> sum() const {return colSum();}
750 
753  const int rows = nrow();
754  Vector_<ELT> col(rows);
755  for (int i = 0; i < rows; ++i)
756  helper.rowSum(i, reinterpret_cast<Scalar*>(&col[i]));
757  return col;
758  }
759 
760  //TODO: make unary +/- return a self-view so they won't reallocate?
761  const MatrixBase& operator+() const {return *this; }
762  const TNeg& negate() const {return *reinterpret_cast<const TNeg*>(this); }
763  TNeg& updNegate() {return *reinterpret_cast<TNeg*>(this); }
764 
765  const TNeg& operator-() const {return negate();}
766  TNeg& operator-() {return updNegate();}
767 
768  MatrixBase& negateInPlace() {(*this) *= EPrecision(-1); return *this;}
769 
774  MatrixBase& resize(int m, int n) { helper.resize(m,n); return *this; }
780  MatrixBase& resizeKeep(int m, int n) { helper.resizeKeep(m,n); return *this; }
781 
782  // This prevents shape changes in a Matrix that would otherwise allow it. No harm if is
783  // are called on a Matrix that is locked already; it always succeeds.
784  void lockShape() {helper.lockShape();}
785 
786  // This allows shape changes again for a Matrix which was constructed to allow them
787  // but had them locked with the above routine. No harm if this is called on a Matrix
788  // that is already unlocked, but it is not allowed to call this on a Matrix which
789  // *never* allowed resizing. An exception will be thrown in that case.
790  void unlockShape() {helper.unlockShape();}
791 
792  // An assortment of handy conversions
793  const MatrixView_<ELT>& getAsMatrixView() const { return *reinterpret_cast<const MatrixView_<ELT>*>(this); }
794  MatrixView_<ELT>& updAsMatrixView() { return *reinterpret_cast< MatrixView_<ELT>*>(this); }
795  const Matrix_<ELT>& getAsMatrix() const { return *reinterpret_cast<const Matrix_<ELT>*>(this); }
796  Matrix_<ELT>& updAsMatrix() { return *reinterpret_cast< Matrix_<ELT>*>(this); }
797 
799  { assert(ncol()==1); return *reinterpret_cast<const VectorView_<ELT>*>(this); }
801  { assert(ncol()==1); return *reinterpret_cast< VectorView_<ELT>*>(this); }
802  const Vector_<ELT>& getAsVector() const
803  { assert(ncol()==1); return *reinterpret_cast<const Vector_<ELT>*>(this); }
805  { assert(ncol()==1); return *reinterpret_cast< Vector_<ELT>*>(this); }
807  { assert(ncol()==1); return *reinterpret_cast<const VectorBase<ELT>*>(this); }
809  { assert(ncol()==1); return *reinterpret_cast< VectorBase<ELT>*>(this); }
810 
812  { assert(nrow()==1); return *reinterpret_cast<const RowVectorView_<ELT>*>(this); }
814  { assert(nrow()==1); return *reinterpret_cast< RowVectorView_<ELT>*>(this); }
816  { assert(nrow()==1); return *reinterpret_cast<const RowVector_<ELT>*>(this); }
818  { assert(nrow()==1); return *reinterpret_cast< RowVector_<ELT>*>(this); }
820  { assert(nrow()==1); return *reinterpret_cast<const RowVectorBase<ELT>*>(this); }
822  { assert(nrow()==1); return *reinterpret_cast< RowVectorBase<ELT>*>(this); }
823 
824  // Access to raw data. We have to return the raw data
825  // pointer as pointer-to-scalar because we may pack the elements tighter
826  // than a C++ array would.
827 
832 
836  int getPackedSizeofElement() const {return NScalarsPerElement*sizeof(Scalar);}
837 
838  bool hasContiguousData() const {return helper.hasContiguousData();}
839  ptrdiff_t getContiguousScalarDataLength() const {
840  return helper.getContiguousDataLength();
841  }
842  const Scalar* getContiguousScalarData() const {
843  return helper.getContiguousData();
844  }
846  return helper.updContiguousData();
847  }
848  void replaceContiguousScalarData(Scalar* newData, ptrdiff_t length, bool takeOwnership) {
849  helper.replaceContiguousData(newData,length,takeOwnership);
850  }
851  void replaceContiguousScalarData(const Scalar* newData, ptrdiff_t length) {
852  helper.replaceContiguousData(newData,length);
853  }
854  void swapOwnedContiguousScalarData(Scalar* newData, ptrdiff_t length, Scalar*& oldData) {
855  helper.swapOwnedContiguousData(newData,length,oldData);
856  }
857 
862  explicit MatrixBase(MatrixHelperRep<Scalar>* hrep) : helper(hrep) {}
863 
864 protected:
865  const MatrixHelper<Scalar>& getHelper() const {return helper;}
866  MatrixHelper<Scalar>& updHelper() {return helper;}
867 
868 private:
869  MatrixHelper<Scalar> helper; // this is just one pointer
870 
871  template <class EE> friend class MatrixBase;
872 
873  // ============================= Unimplemented =============================
874  // This routine is useful for implementing friendlier Matrix expressions and operators.
875  // It maps closely to the Level-3 BLAS family of pxxmm() routines like sgemm(). The
876  // operation performed assumes that "this" is the result, and that "this" has
877  // already been sized correctly to receive the result. We'll compute
878  // this = beta*this + alpha*A*B
879  // If beta is 0 then "this" can be uninitialized. If alpha is 0 we promise not
880  // to look at A or B. The routine can work efficiently even if A and/or B are transposed
881  // by their views, so an expression like
882  // C += s * ~A * ~B
883  // can be performed with the single equivalent call
884  // C.matmul(1., s, Tr(A), Tr(B))
885  // where Tr(A) indicates a transposed view of the original A.
886  // The ultimate efficiency of this call depends on the data layout and views which
887  // are used for the three matrices.
888  // NOTE: neither A nor B can be the same matrix as 'this', nor views of the same data
889  // which would expose elements of 'this' that will be modified by this operation.
890  template <class ELT_A, class ELT_B>
891  MatrixBase& matmul(const StdNumber& beta, // applied to 'this'
892  const StdNumber& alpha, const MatrixBase<ELT_A>& A, const MatrixBase<ELT_B>& B)
893  {
894  helper.matmul(beta,alpha,A.helper,B.helper);
895  return *this;
896  }
897 
898 };
899 
900 } //namespace SimTK
901 
902 #endif // SimTK_SIMMATRIX_MATRIXBASE_H_
Here we define class MatrixHelper<S>, the scalar-type templatized helper class for the more general...
Definition: MatrixHelper.h:79
VectorView_< ELT > operator()(int j) const
Definition: MatrixBase.h:595
void unlockShape()
Definition: MatrixBase.h:790
CNT< E >::Precision EPrecision
Definition: MatrixBase.h:94
MatrixBase & setToNaN()
Definition: MatrixBase.h:584
MatrixView_< ELT > operator()(int i, int j, int m, int n)
Definition: MatrixBase.h:604
K::ScalarNormSq ScalarNormSq
Definition: CompositeNumericalTypes.h:166
Vector_< ELT > & updAsVector()
Definition: MatrixBase.h:804
const VectorView_< ELT > & getAsVectorView() const
Definition: MatrixBase.h:798
const MatrixCharacter & getMatrixCharacter() const
Definition: MatrixBase.h:120
MatrixBase< ESqTHerm > TSqTHerm
Definition: MatrixBase.h:117
MatrixBase(const MatrixCommitment &commitment, int m, int n, const ELT *cppInitialValuesByRow)
Initializing constructor with the initially-allocated elements initialized from a C++ array of elemen...
Definition: MatrixBase.h:239
EScalarNormSq ScalarNormSq
Definition: MatrixBase.h:101
const TNeg & negate() const
Definition: MatrixBase.h:762
K::TReal TReal
Definition: CompositeNumericalTypes.h:141
MatrixBase & copyAssign(const MatrixBase &b)
Copy assignment is a deep copy but behavior depends on type of lhs: if view, rhs must match...
Definition: MatrixBase.h:197
MatrixBase< EStandard > TStandard
Definition: MatrixBase.h:113
CNT< E >::TNormalize ENormalize
Definition: MatrixBase.h:87
Definition: MatrixHelper.h:48
const VectorBase< ELT > & getAsVectorBase() const
Definition: MatrixBase.h:806
This is the vector class intended to appear in user code for large, variable size column vectors...
Definition: BigMatrix.h:171
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation source
Definition: LICENSE.txt:26
This is a dataless rehash of the MatrixBase class to specialize it for RowVectors.
Definition: BigMatrix.h:165
CNT< E >::TImag EImag
Definition: MatrixBase.h:79
const MatrixCommitment & getCharacterCommitment() const
Definition: MatrixBase.h:119
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
EltResult< EE >::Mul colScale(const VectorBase< EE > &c) const
Definition: MatrixBase.h:411
CNT< E >::TNeg ENeg
Definition: MatrixBase.h:76
K::TSqrt TSqrt
Definition: CompositeNumericalTypes.h:154
VectorBase< ELT > & updAsVectorBase()
Definition: MatrixBase.h:808
MatrixHelper< Scalar > & updHelper()
Definition: MatrixBase.h:866
MatrixBase & elementwiseSubtractScalarInPlace(const S &s)
Set M(i,j)-=s for every element of M and some value s.
CNT< E >::TStandard EStandard
Definition: MatrixBase.h:85
Definition: MatrixBase.h:129
static TSqrt sqrt(const K &t)
Definition: CompositeNumericalTypes.h:239
void commitTo(const MatrixCommitment &mc)
Change the handle commitment for this matrix handle; only allowed if the handle is currently clear...
Definition: MatrixBase.h:124
CNT< E >::THerm EHerm
Definition: MatrixBase.h:81
ScalarNormSq normSqr() const
This is the scalar Frobenius norm, and its square.
Definition: MatrixBase.h:723
RowVectorView_< ELT > row(int i) const
Definition: BigMatrix.h:270
const MatrixCharacter & getMatrixCharacter() const
MatrixBase< typename CNT< E >::TInvert > elementwiseInvert() const
Definition: MatrixBase.h:453
K::Scalar Scalar
Definition: CompositeNumericalTypes.h:160
void elementwiseDivide(const MatrixBase< EE > &, typename EltResult< EE >::Dvd &) const
A MatrixCharacter is a set containing a value for each of the matrix characteristics except element t...
Definition: MatrixCharacteristics.h:597
K::TNormalize TNormalize
Definition: CompositeNumericalTypes.h:158
TStandard standardize() const
Return a Matrix of the same shape and contents as this one but with the element type converted to one...
Definition: MatrixBase.h:711
MatrixBase()
The default constructor builds a 0x0 matrix managed by a helper that understands how many scalars the...
Definition: MatrixBase.h:161
CNT< E >::TComplex EComplex
Definition: MatrixBase.h:80
MatrixBase & elementwiseDivideFromLeftInPlace(const MatrixBase< EE > &)
M(i,j) = R(i,j) / M(i,j); R must have same dimensions as this.
MatrixBase & rowAndColScaleInPlace(const VectorBase< ER > &r, const VectorBase< EC > &c)
M = diag(r) * M * diag(c); r must have nrow() elements; must have ncol() elements.
MatrixBase & elementwiseMultiplyFromLeftInPlace(const MatrixBase< EE > &)
M(i,j) = R(i,j) * M(i,j); R must have same dimensions as this.
MatrixBase & elementwiseAssign(const S &s)
Set M(i,j)=s for every element of M and some value s.
MatrixView_< EHerm > operator~()
Definition: MatrixBase.h:612
void replaceContiguousScalarData(const Scalar *newData, ptrdiff_t length)
Definition: MatrixBase.h:851
VectorView_< ELT > updCol(int j)
Definition: BigMatrix.h:261
MatrixBase & operator/=(const StdNumber &t)
Definition: MatrixBase.h:291
CNT< ScalarNormSq >::TSqrt normRMS() const
We only allow RMS norm if the elements are scalars.
Definition: MatrixBase.h:732
void replaceContiguousScalarData(Scalar *newData, ptrdiff_t length, bool takeOwnership)
Definition: MatrixBase.h:848
MatrixBase & resizeKeep(int m, int n)
Change the size of this matrix, retaining as much of the old data as will fit.
Definition: MatrixBase.h:780
Scalar * updContiguousScalarData()
Definition: MatrixBase.h:845
MatrixBase< EHerm > THerm
Definition: MatrixBase.h:109
K::TImag TImag
Definition: CompositeNumericalTypes.h:142
CNT< E >::Number ENumber
Definition: MatrixBase.h:92
Definition: Exception.h:297
RowVectorView_< ELT > updRow(int i)
Definition: BigMatrix.h:279
ELT & updElt(int i, int j)
Definition: MatrixBase.h:657
ELT E
Definition: MatrixBase.h:75
int getNScalarsPerElement() const
This is the number of consecutive scalars used to represent one element of type ELT.
Definition: MatrixBase.h:831
ptrdiff_t getContiguousScalarDataLength() const
Definition: MatrixBase.h:839
MatrixBase & viewAssign(const MatrixBase &src)
View assignment is a shallow copy, meaning that we disconnect the MatrixBase from whatever it used to...
Definition: MatrixBase.h:212
TNeg & operator-()
Definition: MatrixBase.h:766
EltResult< S >::Sub elementwiseSubtractScalar(const S &s) const
Definition: MatrixBase.h:493
EltResult< typename VectorBase< ER >::template EltResult< EC >::Mul >::Mul rowAndColScale(const VectorBase< ER > &r, const VectorBase< EC > &c) const
Definition: MatrixBase.h:428
MatrixBase(const MatrixCommitment &commitment, const MatrixCharacter &character, int spacing, const Scalar *data)
Construct a read-only view of pre-existing data.
Definition: MatrixBase.h:257
MatrixBase(const MatrixCommitment &commitment, MatrixHelper< Scalar > &source, const typename MatrixHelper< Scalar >::ShallowCopy &shallow)
Definition: MatrixBase.h:272
void elementwiseMultiplyFromLeft(const MatrixBase< EE > &, typename MatrixBase< EE >::template EltResult< E >::Mul &) const
Definition: BigMatrix.h:484
void elementwiseDivideFromLeft(const MatrixBase< EE > &, typename MatrixBase< EE >::template EltResult< E >::Dvd &) const
Definition: BigMatrix.h:533
VectorView_< ELT > operator()(int j)
Definition: MatrixBase.h:596
MatrixBase(const MatrixCommitment &commitment, int m, int n)
This constructor takes a handle commitment and allocates the default matrix for that kind of commitme...
Definition: MatrixBase.h:181
SimTK_Real Real
This is the default compiled-in floating point type for SimTK, either float or double.
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:593
MatrixBase & scalarMultiplyInPlace(const S &)
Set M(i,j) = M(i,j)*S for some "scalar" S.
CNT< E >::TWithoutNegator EWithoutNegator
Definition: MatrixBase.h:77
MatrixBase & operator-=(const MatrixBase &r)
Definition: MatrixBase.h:293
MatrixBase & operator*=(const StdNumber &t)
Definition: MatrixBase.h:290
Matrix_< ELT > & updAsMatrix()
Definition: MatrixBase.h:796
static TStandard standardize(const K &t)
Definition: CompositeNumericalTypes.h:241
CNT< ScalarNormSq >::TSqrt norm() const
Definition: MatrixBase.h:726
void getAnyElt(int i, int j, ELT &value) const
This returns a copy of the element value for any position in the logical matrix, regardless of whethe...
Definition: MatrixBase.h:666
m
Definition: CMakeCache.txt:469
void abs(TAbs &mabs) const
abs() is elementwise absolute value; that is, the return value has the same dimension as this Matrix ...
Definition: MatrixBase.h:688
const Matrix_< ELT > & getAsMatrix() const
Definition: MatrixBase.h:795
const RowVector_< ELT > & getAsRowVector() const
Definition: MatrixBase.h:815
(Advanced) This class is identical to RowVector_ except that it has shallow (reference) copy and assi...
Definition: BigMatrix.h:173
CNT< E >::TInvert EInvert
Definition: MatrixBase.h:86
RowVectorView_< ELT > operator[](int i)
Definition: MatrixBase.h:594
MatrixBase< typename CNT< E >::template Result< P >::Sub > Sub
Definition: MatrixBase.h:133
RowVector_< ELT > & updAsRowVector()
Definition: MatrixBase.h:817
K::TSqTHerm TSqTHerm
Definition: CompositeNumericalTypes.h:147
MatrixBase< EComplex > TComplex
Definition: MatrixBase.h:108
CNT< E >::StdNumber EStdNumber
Definition: MatrixBase.h:93
MatrixView_< EHerm > transpose() const
Definition: BigMatrix.h:222
MatrixView_< ELT > updBlock(int i, int j, int m, int n)
Definition: BigMatrix.h:211
EltResult< S >::Add elementwiseAddScalar(const S &s) const
Definition: MatrixBase.h:473
VectorView_< ELT > diag()
This non-const version of diag() is an alternate name for updDiag() available for historical reasons...
Definition: MatrixBase.h:622
int nrow() const
Return the number of rows m in the logical shape of this matrix.
Definition: MatrixBase.h:137
RowVector_< ELT > colSum() const
Form the column sums of this matrix, returned as a RowVector.
Definition: MatrixBase.h:741
MatrixBase< EImag > TImag
Definition: MatrixBase.h:107
void elementwiseSubtractScalar(const S &s, typename EltResult< S >::Sub &) const
K::Precision Precision
Definition: CompositeNumericalTypes.h:164
TNeg & updNegate()
Definition: MatrixBase.h:763
Vector_< ELT > rowSum() const
Form the row sums of this matrix, returned as a Vector.
Definition: MatrixBase.h:752
MatrixBase< E > TPosTrans
Definition: MatrixBase.h:110
(Advanced) This class is identical to Matrix_ except that it has shallow (reference) copy and assignm...
Definition: BigMatrix.h:167
void dump(const char *msg=0) const
Matlab-compatible debug output.
Definition: MatrixBase.h:644
ScalarNormSq scalarNormSqr() const
Scalar norm square is sum( squares of all scalars ).
Definition: MatrixBase.h:674
RowVector_< ELT > sum() const
Alternate name for colSum(); behaves like the Matlab function sum().
Definition: MatrixBase.h:749
EltResult< EE >::Mul elementwiseMultiply(const MatrixBase< EE > &m) const
Definition: MatrixBase.h:530
MatrixBase & elementwiseAssign(int s)
Overloaded to allow an integer argument, which is converted to Real.
Definition: MatrixBase.h:445
K::TInvert TInvert
Definition: CompositeNumericalTypes.h:157
MatrixBase & scalarAddInPlace(const S &s)
Add a scalar to M&#39;s diagonal.
Definition: MatrixBase.h:335
const RowVectorBase< ELT > & getAsRowVectorBase() const
Definition: MatrixBase.h:819
MatrixView_< ELT > block(int i, int j, int m, int n) const
Definition: BigMatrix.h:200
CNT< E >::TSqHermT ESqHermT
Definition: MatrixBase.h:88
MatrixView_< EHerm > updTranspose()
Definition: BigMatrix.h:230
аЯ рЁБ с ўџ З Й ўџџџ Г Д Е Ж џџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџьЅС € ј П ч bjbjcTcT кй Г У Л t џџ џџ џџ З Ÿ С K K K D џџџџ    € ‹2 ”  ZЦ j J a n u a r A b s t r a c t W e d e s c r i b e t h e g o a l s a n d d e s i g n d e c i s i o n b e h i n d S i m m a t r i t h e S i m T K m a t r i x a n d l i n e a r a l g e b r a l i b r a r a n d p r o v i d e r e f e r e n c e i n f o r m a t i o n f o r u s i n g i t T h e i d e a i s t o p r o v i d e t h e p o w e r
Definition: Simmatrix.doc:7
CNT< E >::TReal EReal
Definition: MatrixBase.h:78
VectorView_< ELT > updDiag()
Select main diagonal (of largest leading square if rectangular) and return it as a writable view of t...
Definition: BigMatrix.h:245
MatrixBase(const MatrixCommitment &commitment, const MatrixCharacter &character, int spacing, Scalar *data)
Construct a writable view of pre-existing data.
Definition: MatrixBase.h:264
ENumber Number
Definition: MatrixBase.h:98
MatrixBase & scalarSubtractFromLeftInPlace(const S &s)
Set M(i,i) = S - M(i,i), M(i,j) = -M(i,j) for i!=j.
Definition: MatrixBase.h:351
MatrixBase< typename CNT< E >::template Result< P >::Add > Add
Definition: MatrixBase.h:132
RowVectorBase< ELT > & updAsRowVectorBase()
Definition: MatrixBase.h:821
MatrixBase(const TNeg &b)
Implicit conversion from matrix with negated elements (otherwise this is just like the copy construct...
Definition: MatrixBase.h:191
MatrixBase< typename CNT< E >::template Result< P >::Dvd > Dvd
Definition: MatrixBase.h:131
MatrixBase< E > T
Definition: MatrixBase.h:103
#define SimTK_THROW1(exc, a1)
Definition: Exception.h:311
void rowScale(const VectorBase< EE > &r, typename EltResult< EE >::Mul &out) const
Return type is a new matrix which will have the same dimensions as &#39;this&#39; but will have element types...
аЯ рЁБ с ўџ З Й ўџџџ Г Д Е Ж џџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџьЅС € ј П ч bjbjcTcT кй Г У Л t џџ џџ џџ З Ÿ С K K K D џџџџ    € ‹2 ”  ZЦ j J a n u a r A b s t r a c t W e d e s c r i b e t h e g o a l s a n d d e s i g n d e c i s i o n b e h i n d S i m m a t r i t h e S i m T K m a t r i x a n d l i n e a r a l g e b r a l i b r a r a n d p r o v i d e r e f e r e n c e i n f o r m a t i o n f o r u s i n g i t T h e i d e a i s t o p r o v i d e t h e p o w e n a t u r a l n e s s
Definition: Simmatrix.doc:7
MatrixBase< EInvert > TInvert
Definition: MatrixBase.h:114
const ELT & getElt(int i, int j) const
Element selection for stored elements.
Definition: MatrixBase.h:656
MatrixBase< ENormalize > TNormalize
Definition: MatrixBase.h:115
CNT< E >::TPosTrans EPosTrans
Definition: MatrixBase.h:82
MatrixBase< EAbs > TAbs
Definition: MatrixBase.h:112
void lockShape()
Definition: MatrixBase.h:784
K::TPosTrans TPosTrans
Definition: CompositeNumericalTypes.h:145
EStdNumber StdNumber
Definition: MatrixBase.h:99
TInvert invert() const
Definition: MatrixBase.h:635
MatrixBase< EWithoutNegator > TWithoutNegator
Definition: MatrixBase.h:105
Definition: MatrixBase.h:155
MatrixBase< EReal > TReal
Definition: MatrixBase.h:106
bool isResizeable() const
Return true if either dimension of this Matrix is resizable.
Definition: MatrixBase.h:151
EltResult< EE >::Mul rowScale(const VectorBase< EE > &r) const
Definition: MatrixBase.h:398
const TNeg & operator-() const
Definition: MatrixBase.h:765
const MatrixView_< ELT > & getAsMatrixView() const
Definition: MatrixBase.h:793
MatrixBase & elementwiseInvertInPlace()
Set M(i,j) = M(i,j)^-1.
Definition: BigMatrix.h:361
MatrixBase & rowScaleInPlace(const VectorBase< EE > &)
M = diag(r) * M; r must have nrow() elements.
const Vector_< ELT > & getAsVector() const
Definition: MatrixBase.h:802
This is the matrix class intended to appear in user code for large, variable size matrices...
Definition: BigMatrix.h:168
int getPackedSizeofElement() const
This is like sizeof(ELT), but returning the number of bytes we use to store the element which may be ...
Definition: MatrixBase.h:836
CNT< E >::TSqTHerm ESqTHerm
Definition: MatrixBase.h:89
MatrixView_< EHerm > operator~() const
Definition: MatrixBase.h:611
MatrixBase & elementwiseAddScalarInPlace(const S &s)
Set M(i,j)+=s for every element of M and some value s.
MatrixBase & operator+=(const MatrixBase &r)
Definition: MatrixBase.h:292
K::StdNumber StdNumber
Definition: CompositeNumericalTypes.h:163
ELT getAnyElt(int i, int j) const
Definition: MatrixBase.h:668
void colScale(const VectorBase< EE > &c, typename EltResult< EE >::Mul &out) const
MatrixBase & operator=(const MatrixBase< EE > &b)
Definition: MatrixBase.h:298
void elementwiseMultiply(const MatrixBase< EE > &, typename EltResult< EE >::Mul &) const
MatrixBase & setToZero()
Definition: MatrixBase.h:585
MatrixBase< S >::template EltResult< E >::Sub elementwiseSubtractFromScalar(const S &s) const
Definition: MatrixBase.h:516
MatrixBase(const MatrixCommitment &commitment, int m, int n, const ELT &initialValue)
Initializing constructor with all of the initially-allocated elements initialized to the same value...
Definition: MatrixBase.h:225
gјiЌтkDdёMV wfлaIJуtюц ЩAАйЉt”џ‡1Лƒ  J†љŠcA nrш “S qо is†І3 уЏ ЇжЇ Ы –ТгVфЦKф Cž ‰д9Z €У ЉD Ўq FxnЙцТ n єT ЉY Н‡< щ['ЖjdЛ< K JvTMЯH"ЋˆяОsђ™Ыw>}љіo_Йљ…Зo”ЖЃ?Ї zџШЎ'z:mЄІуЧV$ќКРŠyЁnаgЭ–џiлИ”J{и ž”хЩїTaК*АдdКВŽE|lєzƒbXс@!^Рклѕ‘гOЌoi_г=ўінOП}&ŒкХВQUŠŠ­V…ЅWT­shЃ!ГљPЌ_‰ŸЊЕС7šЅDR›AVъfЎ‘вЪПЈЛЅbOждЙЩЋtЎ0оY!О|л'ђЉx'žўУГ§нЅК—:/ўќПќ V[ц,тЇо}-Bжž§Ъ/ПјиџіЌм‚;у:Žх;яОй;IюЫПЇо˜й[nK4Ћ#ІЁ-Б='ЈGf€\lЙчѕœb41лЉŸ> ѓйOчsчЂ7x f p§€ъZ„‘zB рI •рƒЮ gЊБЁ Њ ˆ n
Definition: SimmathUserGuide.doc:2262
void elementwiseAddScalar(const S &s, typename EltResult< S >::Add &) const
Specialized information about Composite Numerical Types which allows us to define appropriate templat...
Definition: CompositeNumericalTypes.h:136
const RowVectorView_< ELT > & getAsRowVectorView() const
Definition: MatrixBase.h:811
MatrixBase & operator-=(const MatrixBase< EE > &b)
Definition: MatrixBase.h:302
void invertInPlace()
Definition: MatrixBase.h:641
MatrixBase(const MatrixCommitment &commitment)
This constructor takes a handle commitment and allocates the default matrix for that kind of commitme...
Definition: MatrixBase.h:173
CNT< E >::ScalarNormSq EScalarNormSq
Definition: MatrixBase.h:95
MatrixBase & scalarDivideInPlace(const S &)
Set M(i,j) = M(i,j)/S for some "scalar" S.
MatrixBase< EE >::template EltResult< EE >::Dvd elementwiseDivideFromLeft(const MatrixBase< EE > &m) const
Definition: MatrixBase.h:576
VectorView_< ELT > diag() const
Select main diagonal (of largest leading square if rectangular) and return it as a read-only view of ...
Definition: BigMatrix.h:238
MatrixBase & operator=(const MatrixBase &b)
Definition: MatrixBase.h:201
MatrixBase(int m, int n)
This constructor allocates the default matrix a completely uncommitted matrix commitment, given particular initial dimensions.
Definition: MatrixBase.h:165
const MatrixHelper< Scalar > & getHelper() const
Definition: MatrixBase.h:865
CNT< E >::TAbs EAbs
Definition: MatrixBase.h:84
K::TNeg TNeg
Definition: CompositeNumericalTypes.h:139
This is a dataless rehash of the MatrixBase class to specialize it for Vectors.
Definition: BigMatrix.h:164
MatrixBase & scalarDivideFromLeftInPlace(const S &)
Set M(i,j) = S/M(i,j) for some "scalar" S.
K::TStandard TStandard
Definition: CompositeNumericalTypes.h:156
Definition: MatrixBase.h:154
K::TWithoutNegator TWithoutNegator
Definition: CompositeNumericalTypes.h:140
CNT< E >::Scalar EScalar
Definition: MatrixBase.h:91
const Scalar * getContiguousScalarData() const
Definition: MatrixBase.h:842
RowVectorView_< ELT > operator[](int i) const
Definition: MatrixBase.h:593
Represents a variable size row vector; much less common than the column vector type Vector_...
Definition: BigMatrix.h:174
void commitTo(const MatrixCommitment &)
A MatrixCommitment provides a set of acceptable matrix characteristics.
Definition: MatrixCharacteristics.h:832
VectorView_< ELT > & updAsVectorView()
Definition: MatrixBase.h:800
void swapOwnedContiguousScalarData(Scalar *newData, ptrdiff_t length, Scalar *&oldData)
Definition: MatrixBase.h:854
MatrixBase< EE >::template EltResult< E >::Mul elementwiseMultiplyFromLeft(const MatrixBase< EE > &m) const
Definition: MatrixBase.h:546
MatrixBase(MatrixHelperRep< Scalar > *hrep)
Helper rep-stealing constructor.
Definition: MatrixBase.h:862
ptrdiff_t nelt() const
Return the number of elements in the logical shape of this matrix.
Definition: MatrixBase.h:148
void elementwiseSubtractFromScalar(const S &, typename MatrixBase< S >::template EltResult< E >::Sub &) const
Definition: BigMatrix.h:435
TAbs abs() const
abs() with the result as a function return.
Definition: MatrixBase.h:699
bool isResizeable() const
Definition: MatrixCharacteristics.h:925
MatrixBase & elementwiseDivideInPlace(const MatrixBase< EE > &)
M(i,j) /= R(i,j); R must have same dimensions as this.
MatrixBase(const MatrixCommitment &commitment, const MatrixHelper< Scalar > &source, const typename MatrixHelper< Scalar >::ShallowCopy &shallow)
Definition: MatrixBase.h:276
K::TComplex TComplex
Definition: CompositeNumericalTypes.h:143
This is the common base class for Simbody&#39;s Vector_ and Matrix_ classes for handling large...
Definition: BigMatrix.h:163
K::Number Number
Definition: CompositeNumericalTypes.h:162
MatrixBase & operator=(const ELT &t)
Matrix assignment to an element sets only the *diagonal* elements to the indicated value; everything ...
Definition: MatrixBase.h:315
static TAbs abs(const K &t)
Definition: CompositeNumericalTypes.h:240
MatrixBase & scalarAssign(const S &s)
Set M&#39;s diagonal elements to a "scalar" value S, and all off-diagonal elements to zero...
Definition: MatrixBase.h:326
MatrixBase(const MatrixBase< EE > &b)
Definition: MatrixBase.h:295
MatrixBase & elementwiseMultiplyInPlace(const MatrixBase< EE > &)
M(i,j) *= R(i,j); R must have same dimensions as this.
MatrixBase & colScaleInPlace(const VectorBase< EE > &)
M = M * diag(c); c must have ncol() elements.
void clear()
This restores the MatrixBase to the state it would be in had it been constructed specifying only its ...
Definition: MatrixBase.h:288
MatrixBase< ENeg > TNeg
Definition: MatrixBase.h:104
int ncol() const
Return the number of columns n in the logical shape of this matrix.
Definition: MatrixBase.h:139
MatrixBase & setTo(const ELT &t)
Fill every element in current allocation with given element (or NaN or 0).
Definition: MatrixBase.h:583
RowVectorView_< ELT > & updAsRowVectorView()
Definition: MatrixBase.h:813
MatrixBase & operator+=(const MatrixBase< EE > &b)
Definition: MatrixBase.h:300
K::TSqHermT TSqHermT
Definition: CompositeNumericalTypes.h:146
EltResult< EE >::Dvd elementwiseDivide(const MatrixBase< EE > &m) const
Definition: MatrixBase.h:560
MatrixBase & resize(int m, int n)
Change the size of this matrix.
Definition: MatrixBase.h:774
bool hasContiguousData() const
Definition: MatrixBase.h:838
MatrixBase & scalarMultiplyFromLeftInPlace(const S &)
Set M(i,j) = S * M(i,j) for some "scalar" S.
void rowAndColScale(const VectorBase< ER > &r, const VectorBase< EC > &c, typename EltResult< typename VectorBase< ER >::template EltResult< EC >::Mul >::Mul &out) const
Definition: BigMatrix.h:337
MatrixBase< typename CNT< E >::template Result< P >::Mul > Mul
Definition: MatrixBase.h:130
MatrixBase & negateInPlace()
Definition: MatrixBase.h:768
MatrixBase(const MatrixCommitment &commitment, const MatrixHelper< Scalar > &source, const typename MatrixHelper< Scalar >::DeepCopy &deep)
Definition: MatrixBase.h:280
(Advanced) This class is identical to Vector_ except that it has shallow (reference) copy and assignm...
Definition: BigMatrix.h:170
ELT & operator()(int i, int j)
Definition: MatrixBase.h:660
MatrixBase & elementwiseSubtractFromScalarInPlace(const S &s)
Set M(i,j) = s - M(i,j) for every element of M and some value s.
K::THerm THerm
Definition: CompositeNumericalTypes.h:144
MatrixView_< ELT > & updAsMatrixView()
Definition: MatrixBase.h:794
const MatrixCommitment & getCharacterCommitment() const
MatrixView_< ELT > operator()(int i, int j, int m, int n) const
Definition: MatrixBase.h:602
const ELT & operator()(int i, int j) const
Definition: MatrixBase.h:659
MatrixBase & scalarSubtractInPlace(const S &s)
Subtract a scalar from M&#39;s diagonal.
Definition: MatrixBase.h:344
MatrixBase(const MatrixBase &b)
Copy constructor is a deep copy (not appropriate for views!).
Definition: MatrixBase.h:185
EPrecision Precision
Definition: MatrixBase.h:100
EScalar Scalar
Definition: MatrixBase.h:97
MatrixBase< ESqHermT > TSqHermT
Definition: MatrixBase.h:116
K::TAbs TAbs
Definition: CompositeNumericalTypes.h:155
VectorView_< ELT > col(int j) const
Definition: BigMatrix.h:252
const MatrixBase & operator+() const
Definition: MatrixBase.h:761