Actin®  Version 5.2.0
Software for Robotics Simulation and Control
ecReArray.h
Go to the documentation of this file.
1 #ifndef ecReArray_H_
2 #define ecReArray_H_
3 //------------------------------------------------------------------------------
4 // Copyright (c) 2001-2013 Energid Technologies. All rights reserved.
5 //
10 //
11 //------------------------------------------------------------------------------
12 #include <foundCore/ecConfig.h> // Required to be first header.
13 #include <foundCore/ecVector.h>
14 
16 {
17 public:
19  EcReArray
20  (
21  );
22 
24  EcReArray
25  (
26  EcSizeT rows,
27  EcSizeT columns
28  );
29 
33  EcReArray
34  (
35  const EcRealVector& vector,
36  EcBoolean isColumn
37  );
38 
40  virtual ~EcReArray
41  (
42  );
43 
45  EcReArray
46  (
47  const EcReArray& orig
48  );
49 
51  EcRealVector& operator[]
52  (
53  EcSizeT index
54  )
55  {
56  EcTOGGLE_THROW_IF(index >= m_vvInternal.size(), std::out_of_range)
57  return m_vvInternal[index];
58  }
59 
61  const EcRealVector& operator[]
62  (
63  EcSizeT index
64  ) const
65  {
66  EcTOGGLE_THROW_IF(index >= m_vvInternal.size(), std::out_of_range)
67  return m_vvInternal[index];
68  }
69 
71  void assign
72  (
73  EcSizeT size,
74  const EcRealVector& v
75  ) { m_vvInternal.assign(size, v); }
76 
78  void clear
79  (
80  ) { m_vvInternal.clear(); }
81 
83  void push_back
84  (
85  const EcRealVector& v
86  ) { m_vvInternal.push_back(v); }
87 
89  void reserve
90  (
91  EcSizeT size
92  ) { m_vvInternal.reserve(size); }
93 
95  void resize
96  (
97  EcSizeT newsize,
99  ) { m_vvInternal.resize(newsize, v); }
100 
102  EcSizeT size
103  (
104  ) const { return m_vvInternal.size(); }
105 
107  operator EcRealVectorVector&() { return m_vvInternal; }
108 
110  EcReArray& operator=
111  (
112  const EcReArray& orig
113  );
114 
116  EcReArray& operator=
117  (
118  const EcRealVector& vOrig
119  );
120 
122  EcBoolean operator==
123  (
124  const EcReArray& other
125  ) const;
126 
129  EcReArray operator+
130  (
131  const EcReArray& other
132  ) const;
133 
136  EcReArray& operator+=
137  (
138  const EcReArray& other
139  );
140 
143  EcReArray operator-
144  (
145  const EcReArray& other
146  ) const;
147 
150  EcReArray& operator-=
151  (
152  const EcReArray& other
153  );
154 
158  EcReArray operator*
159  (
160  const EcReArray& other
161  ) const;
162 
165  EcRealVector operator*
166  (
167  const EcRealVector& vOther
168  ) const;
169 
171 
175  EcVector operator*
176  (
177  const EcVector& vOther
178  ) const;
179 
181 
185  EcReArray& operator*=
186  (
187  EcReal scalar
188  );
189 
191 
195  EcReArray operator*
196  (
197  EcReal scalar
198  )const;
199 
204  virtual EcReal trace
205  (
206  ) const ;
207 
210 
213  void setToDiagonal
214  (
215  const EcRealVector& vDiagTerms
216  ) ;
217 
221 
225  virtual void transform
226  (
227  const EcReArray& from,
228  EcReArray& to
229  ) const;
230 
234 
238  virtual void transform
239  (
240  const EcRealVector& vFrom,
241  EcRealVector& vTo
242  ) const;
243 
248 
252  virtual void transform
253  (
254  const EcRealVector& vFrom,
255  EcReArray& to
256  ) const;
257 
262 
266  virtual void transposeTransform
267  (
268  const EcRealVector& vFrom,
269  EcRealVector& vTo
270  ) const;
271 
277 
281  virtual void leftTransposeTransform
282  (
283  const EcReArray& from,
284  EcReArray& to
285  ) const;
286 
293 
297  virtual void leftTransposeTransform
298  (
299  const EcRealVector& vFrom,
300  EcReArray& to
301  ) const;
302 
309  virtual EcReArray& leftMultiplyDiagonal
310  (
311  const EcRealVector& vDiagTerms
312  );
313 
315 
318  virtual void elementInverse
319  (
320  EcReArray& result
321  ) const;
322 
324 
327  virtual void elementCosine
328  (
329  EcReArray& result
330  ) const;
331 
333 
336  virtual void elementSine
337  (
338  EcReArray& result
339  ) const;
340 
342 
345  virtual void elementLog
346  (
347  EcReArray& result
348  ) const ;
349 
351 
355  virtual void elementLogN
356  (
357  EcReArray& result,
358  EcReal base
359  ) const ;
360 
362 
366  virtual void elementPow
367  (
368  EcReArray& result,
369  EcReal exp
370  ) const ;
371 
373  virtual EcReArray transpose
374  (
375  ) const;
376 
378 
381  virtual void transpose
382  (
383  EcReArray& out
384  ) const;
385 
388 
391  virtual void addSelfOuterProduct
392  (
393  const EcRealVector& v
394  );
395 
398 
402  virtual void addWeightedSelfOuterProduct
403  (
404  const EcRealVector& v,
405  EcReal a
406  );
407 
413  virtual void qrDecomposition
414  (
415  EcReArray* pR = EcNULL
416  );
417 
419  virtual EcBoolean choleskyDecomposition
420  (
421  EcReArray& choleskyL
422  ) const;
423 
427  virtual EcBoolean choleskyBackSubstitution
428  (
429  const EcReArray& input,
430  EcReArray& result
431  ) const;
432 
436  virtual EcBoolean choleskyBackSubstitutionOnTranspose
437  (
438  const EcReArray& input,
439  EcReArray& result
440  ) const;
441 
444  virtual EcBoolean lowerTriangularForwardSubstitution
445  (
446  const EcReArray& input,
447  EcReArray& result
448  ) const;
449 
452  virtual EcBoolean lowerTriangularForwardSubstitutionOnTranspose
453  (
454  const EcReArray& input,
455  EcReArray& result
456  ) const;
457 
460 
463  virtual EcBoolean underconstrainedNormal
464  (
465  EcReArray& squareResult
466  ) const;
467 
470 
473  virtual EcBoolean overconstrainedNormal
474  (
475  EcReArray& squareResult
476  ) const;
477 
479 
484  virtual EcBoolean approxEq
485  (
486  const EcReArray& other,
487  EcReal tol
488  ) const;
489 
491  virtual EcReal infinityNorm
492  (
493  ) const;
494 
496  virtual EcReal infinityNorm
497  (
498  const EcSizeT col
499  ) const;
500 
502  virtual EcReal columnNorm
503  (
504  EcSizeT col
505  ) const;
506 
508  virtual EcSizeT rows
509  (
510  ) const;
511 
513  virtual EcSizeT columns
514  (
515  ) const;
516 
518  virtual void setToZeros
519  (
520  EcSizeT rows,
521  EcSizeT columns
522  );
523 
525  virtual void setToValue
526  (
527  EcSizeT rows,
528  EcSizeT columns,
529  EcReal value
530  );
531 
533  virtual void setToIdentity
534  (
535  EcSizeT rows,
536  EcSizeT columns
537  );
538 
540  virtual void resizeArray
541  (
542  EcSizeT rows,
543  EcSizeT columns
544  );
545 
547  virtual void copyEntriesOf
548  (
549  const EcReArray& other
550  );
551 
553  static EcReArray nullObject
554  (
555  );
556 
559 
563  virtual EcBoolean LUDecomposition
564  (
565  EcSizeT nRows, // works on the first n rows (do all if no input)
566  EcU32Vector& vIndices // pivot column index vector
567  );
568 
571 
577  virtual EcBoolean forwardAndBackSub
578  (
579  const EcU32Vector& indices, // indices produced by pivoting from LUDecomposition
580  const EcRealVector& b, // b
581  EcRealVector& x, // x
582  EcReal& det // determinant of A
583  ) const;
584 
586 
591  virtual EcBoolean solve
592  (
593  const EcRealVector& b, // b in Ax=b
594  EcRealVector& x, // x in Ax=b
595  EcReal* pDet=0 // optional determinant return
596  );
597 
599  virtual EcBoolean invertSquareMatrix
600  (
601  );
602 
605 
611  virtual EcBoolean LUDecompositionSparse
612  (
613  EcSizeT nRows, // works on the first n rows (do all if no input)
614  EcU32Vector& vIndices, // pivot column index vector
615  const EcU32Vector& vSparseInd, // sparse column index vector
616  const EcU32Vector& vZeroStart // zero start column index vector
617  );
618 
621 
624  virtual EcReal determinant
625  (
626  );
627 
629 
635  virtual EcBoolean nullSpace
636  (
637  EcReArray& nSpace, // the null space output
638  EcSizeT nRows, // the rows in this array that are used
639  EcU32Vector& vIndices // pivot Column index vector (default to nullobject)
640  );
641 
643 
651  virtual EcBoolean nullSpaceSparse
652  (
653  EcReArray& nSpace, // the null space output
654  EcSizeT nRows, // the rows in this array that are used
655  EcU32Vector& vIndices, // pivot Column index vector
656  const EcU32Vector& vSparseInd, // sparse column index vector
657  const EcU32Vector& vZeroStart // zero start column index vector
658  );
659 
663 
666  virtual EcBoolean calculateZeroStartIndices
667  (
668  EcU32Vector& vZeroStartIndices
669  ) const;
670 
672 
676  virtual EcBoolean dump
677  (
678  const char* fileName
679  ) const;
680 
682 
686  virtual EcBoolean dumpMath
687  (
688  const char* fileName
689  ) const;
690 
692  virtual EcBoolean combineIndices
693  (
694  const EcU32Vector& vInd1,
695  const EcU32Vector& vInd2,
696  EcU32Vector& vIndResult
697  ) const;
698 
700  virtual EcBoolean inv2
701  (
702  EcReArray& M2 // result matrix
703  ) const;
704 
706  virtual EcBoolean inv3
707  (
708  EcReArray& M2 // result matrix
709  ) const;
710 
712 
716  virtual EcBoolean writeBin
717  (
718  const EcString& fname
719  )const;
720 
722 
726  virtual EcBoolean readBin
727  (
728  const EcString& fname
729  );
730 
732  virtual void getColumn
733  (
734  EcRealVector& vCol, // destination
735  const EcSizeT col // column number
736  ) const;
737 
739  virtual void getRow
740  (
741  EcRealVector& vRow, // destination
742  const EcSizeT row // row id
743  ) const;
744 
746  virtual void maximum
747  (
748  EcReal& val, // max value
749  EcSizeT& row, // row id
750  EcSizeT& col // column id
751  ) const;
752 
754  virtual void minimum
755  (
756  EcReal& val, // min value
757  EcSizeT& row, // row id
758  EcSizeT& col // column id
759  ) const;
760 
762  virtual EcReal sum
763  (
764  ) const;
765 
769 
773  virtual EcBoolean kroneckerTensorProduct
774  (
775  const EcReArray& arrayB,
776  EcReArray& arrayC
777  ) const;
778 
779 private:
781  mutable EcU32Vector m_vIndices;
782 
783  // temporary parameters as member variables for speed
784  mutable EcU32Vector m_vColOrder1;
785  mutable EcU32Vector m_vColOrder2;
786  mutable EcU32Vector m_vColOrder3;
787 
788  EcRealVector m_vTempVec;
789  EcRealVector m_vTempVec2;
790 
791  EcRealVectorVector m_TempArray;
792  EcRealVectorVector m_vvInternal;
793 };
794 
797 
799 typedef std::vector<EcManipulatorJacobian> EcManipulatorJacobianVector;
800 
802 typedef std::vector<EcReArray> EcReArrayVector;
803 
805 typedef std::vector<EcReArrayVector> EcReArrayVectorVector;
806 
807 // -----------------------------------------------
808 // read in and write out below
809 // -----------------------------------------------
810 
813 inline EC_STABLE_MATRIXUTILITIES_DECL std::ostream& operator<<
814  (
815  std::ostream& stream,
816  const EcReArray& val
817  )
818 {
819  stream << val.rows() << std::endl;
820  const EcSizeT size = val.rows();
821  for (EcSizeT ii = 0; ii<size; ++ii)
822  {
823  // write the row size
824  stream << val[ii].size() << " ";
825 
826  const EcSizeT sizeCol = val[ii].size();
827  for (EcSizeT jj = 0; jj<sizeCol; ++jj)
828  {
829  stream << EcDOUBLE2STRING(val[ii][jj]) << " ";
830  }
831 
832  stream << std::endl;
833  }
834 
835  return stream;
836 }
837 
838 
841 inline EC_STABLE_MATRIXUTILITIES_DECL std::istream& operator>>
842  (
843  std::istream& stream,
844  EcReArray& val
845  )
846 {
847  EcSizeT rows;
848  EcSizeT size;
849  EcReal value;
850 
851 
852  stream >> rows;
853  val.reserve(rows);
854 
855  for (EcSizeT ii = 0; ii<rows; ++ii)
856  {
857  stream >> size;
858  EcRealVector vec;
859  vec.clear();
860  vec.reserve(size);
861 
862  for (EcSizeT jj = 0; jj<size; ++jj)
863  {
864  stream >> value;
865  vec.push_back(value);
866  }
867 
868  val.push_back(vec);
869  }
870 
871  return stream;
872 }
873 
874 
875 // -----------------------------------------------
876 // extra operators below
877 // -----------------------------------------------
878 
881  (
882  const EcReArray& a1
883  );
884 
885 #endif // ecReArray_H_
#define EcNULL
a null pointer variable
Definition: ecConstants.h:120
Holds a class to describe real arrays. Includes operations such as addition, subtraction, and multiplication.
Definition: ecReArray.h:15
#define EC_STABLE_MATRIXUTILITIES_DECL
matrixUtilities directory
Definition: ecConfig.h:159
std::vector< EcManipulatorJacobian > EcManipulatorJacobianVector
convenience type for a vector of jacobians using std::vector
Definition: ecReArray.h:799
Specify some global configuration parameters and values.
std::vector< EcReArray > EcReArrayVector
Vector of EcReArray using std::vector.
Definition: ecReArray.h:802
EC_ACTINCORE_FOUNDCOMMON_DECL EcSecondMoment transform(const EcOrientation &q, const EcSecondMoment &m)
expresses the second moment in a rotated frame
std::size_t EcSizeT
unsigned integer type used to represent indices and the sizes of containers
Definition: ecTypes.h:129
EC_STABLE_FOUNDCORE_DECL EcString EcDOUBLE2STRING(const EcReal value)
convert a double to a string
bool EcBoolean
Boolean (0 or 1)
Definition: ecTypes.h:21
#define EcTOGGLE_THROW_IF(expression, type)
std::vector< EcReal > EcRealVector
a general floating-point vector
Definition: ecTypes.h:168
EcF64 EcReal
Alias for 64-bit float.
Definition: ecTypes.h:30
std::vector< EcRealVector > EcRealVectorVector
a general floating-point array
Definition: ecTypes.h:207
std::basic_string< char > EcString
a character string
Definition: ecTypes.h:116
std::vector< EcReArrayVector > EcReArrayVectorVector
A 2D vector of arrays using std::vector.
Definition: ecReArray.h:805
EcReArray EcManipulatorJacobian
convenience type for the jacobian
Definition: ecReArray.h:796
std::vector< EcU32 > EcU32Vector
a general 32-bit unsigned integer vector
Definition: ecTypes.h:171
A three-element vector.
Definition: ecVector.h:20
Created by Energid Technologies www.energid.com
Copyright © 2016 Energid. All trademarks mentioned in this document are property of their respective owners.