cisst-saw
Loading...
Searching...
No Matches
vctFixedSizeConstMatrixBase.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5 Author(s): Ofri Sadowsky, Anton Deguet
6 Created on: 2003-11-04
7
8 (C) Copyright 2003-2018 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19#pragma once
20#ifndef _vctFixedSizeConstMatrixBase_h
21#define _vctFixedSizeConstMatrixBase_h
22
27
29
35
36#include <stdio.h>
37
38/* Forward declarations */
39#ifndef DOXYGEN
40template <vct::size_type _rows, vct::size_type _cols,
41 vct::stride_type _rowStride, vct::stride_type _colStride, class _dataPtrType,
42 vct::stride_type __rowStride, vct::stride_type __colStride, class __dataPtrType,
43 class _elementType,
44 class _elementOperationType>
46vctFixedSizeMatrixElementwiseCompareMatrix(const vctFixedSizeConstMatrixBase<_rows, _cols, _rowStride, _colStride,
47 _elementType, _dataPtrType> & matrix1,
48 const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
49 _elementType, __dataPtrType> & matrix2);
50
51template <vct::size_type _rows, vct::size_type _cols,
52 vct::stride_type _rowStride, vct::stride_type _colStride, class _dataPtrType,
53 class _elementType,
54 class _elementOperationType>
56vctFixedSizeMatrixElementwiseCompareScalar(const vctFixedSizeConstMatrixBase<_rows, _cols, _rowStride, _colStride,
57 _elementType, _dataPtrType> & matrix,
58 const _elementType & scalar);
59#endif // DOXYGEN
60
100template<vct::size_type _rows, vct::size_type _cols,
101 vct::stride_type _rowStride, vct::stride_type _colStride,
102 class _elementType, class _dataPtrType>
104{
105 public:
106 /* Declare the container-defined typed required by STL, plus the
107 types completed by our traits class */
108
109 /* define most types from vctContainerTraits */
111 enum {DIMENSION = 2};
113
115 typedef vctFixedSizeConstMatrixBase<_rows, _cols,
116 _rowStride, _colStride, _elementType, _dataPtrType> ThisType;
117
119 typedef vctFixedSizeMatrixTraits<_elementType, _rows, _cols,
120 _rowStride, _colStride> MatrixTraits;
121
124
127
130
133
140
144
169
176
179
182
183
186 typedef vctFixedSizeConstMatrixRef<_elementType, _cols, _rows,
187 _colStride, _rowStride> ConstRefTransposeType;
188
191 typedef vctFixedSizeMatrixRef<_elementType, _cols, _rows,
192 _colStride, _rowStride> RefTransposeType;
193
197 typedef vctFixedSizeMatrix<_elementType, COLS, ROWS,
199
203 typedef vctFixedSizeMatrix<_elementType, ROWS, COLS,
205
209 typedef vctFixedSizeMatrix<bool, ROWS, COLS,
211
212 typedef _dataPtrType DataType;
213
214 protected:
217
218
220 inline void ThrowUnlessValidIndex(size_type index) const CISST_THROW(std::out_of_range) {
221 if (! ValidIndex(index)) {
222 cmnThrow(std::out_of_range("vctFixedSizeMatrix: Invalid index"));
223 }
224 }
225
226
228 inline void ThrowUnlessValidIndex(size_type rowIndex, size_type colIndex) const CISST_THROW(std::out_of_range) {
229 if (! ValidIndex(rowIndex, colIndex)) {
230 cmnThrow(std::out_of_range("vctFixedSizeMatrix: Invalid indices"));
231 }
232 }
233
234
235 public:
239 return const_iterator(Data, 0);
240 }
241
242
246 return const_iterator(Data) + LENGTH;
247 }
248
249
253 return const_reverse_iterator(Pointer(ROWS - 1, COLS - 1), 0);
254 }
255
256
261 COLSTRIDE * (COLS - 1), 0);
262 }
263
266 size_type size() const {
267 return LENGTH;
268 }
269
271 const nsize_type & sizes(void) const {
272 static nsize_type staticSizes(ROWS, COLS);
273 return staticSizes;
274 }
275
277 size_type rows() const {
278 return ROWS;
279 }
280
282 size_type cols() const {
283 return COLS;
284 }
285
286
290 size_type max_size() const {
291 return LENGTH;
292 }
293
294
296 const nstride_type & strides(void) const {
297 static nstride_type staticStrides(ROWSTRIDE, COLSTRIDE);
298 return staticStrides;
299 }
300
303 difference_type row_stride() const {
304 return ROWSTRIDE;
305 }
306
309 difference_type col_stride() const {
310 return COLSTRIDE;
311 }
312
315 bool empty() const {
316 return (LENGTH == 0);
317 }
318
321 ConstRowRefType operator[](size_type index) const {
322 return ConstRowRefType(Data + ROWSTRIDE * index);
323 }
324
325
329 const_pointer Pointer(size_type rowIndex, size_type colIndex) const {
330 return Data + ROWSTRIDE * rowIndex + COLSTRIDE * colIndex;
331 }
332
336 const_pointer Pointer(void) const {
337 return Data;
338 }
339
342 inline bool ValidIndex(size_type index) const {
343 return (index < size());
344 }
345
348 inline bool ValidIndex(size_type rowIndex, size_type colIndex) const {
349 return ((rowIndex < rows())
350 && (colIndex < cols()));
351 }
352
354 inline bool ValidRowIndex(size_type rowIndex) const {
355 return (rowIndex < rows());
356 }
357
359 inline bool ValidColIndex(size_type colIndex) const {
360 return (colIndex < cols());
361 }
362
363
368 const_reference at(size_type index) const CISST_THROW(std::out_of_range) {
370 return (begin())[index];
371 }
372
373
378 const_reference at(size_type rowIndex, size_type colIndex) const CISST_THROW(std::out_of_range) {
379 ThrowUnlessValidIndex(rowIndex, colIndex);
380 return *(Pointer(rowIndex, colIndex));
381 }
382
383#ifndef SWIG
386 const_reference operator()(size_type rowIndex, size_type colIndex) const CISST_THROW(std::out_of_range) {
387 return at(rowIndex, colIndex);
388 }
389#endif
390
391
397 const_reference Element(size_type rowIndex, size_type colIndex) const {
398 return *(Pointer(rowIndex, colIndex));
399 }
400
401
402 ConstRowRefType Row(size_type index) const {
403 return ConstRowRefType(Data + ROWSTRIDE * index);
404 }
405
406 ConstColumnRefType Column(size_type index) const {
407 return ConstColumnRefType(Data + COLSTRIDE * index);
408 }
409
411 {
413 }
414
416 template <vct::size_type __subRows, vct::size_type __subCols>
418 Ref(const size_type startRow = 0, const size_type startCol = 0) const CISST_THROW(std::out_of_range) {
420 result(*this, startRow, startCol);
421 return result;
422 }
423
427
430 inline value_type SumOfElements() const {
431 return vctFixedSizeMatrixLoopEngines::
432 SoMi<typename vctBinaryOperations<value_type>::Addition,
434 Run(*this);
435 }
436
440 return vctFixedSizeMatrixLoopEngines::
441 SoMi<typename vctBinaryOperations<value_type>::Multiplication,
443 Run(*this);
444 }
445
450 inline value_type Trace(void) const {
451 return this->Diagonal().SumOfElements();
452 }
453
456 inline value_type NormSquare(void) const {
457 return vctFixedSizeMatrixLoopEngines::
458 SoMi<typename vctBinaryOperations<value_type>::Addition,
460 Run(*this);
461 }
462
465 inline NormType Norm(void) const {
466 return sqrt(NormType(NormSquare()));
467 }
468
473 inline value_type L1Norm(void) const {
474 return vctFixedSizeMatrixLoopEngines::
475 SoMi<typename vctBinaryOperations<value_type>::Addition,
477 Run(*this);
478 }
479
486 inline value_type LinfNorm(void) const {
487 return this->MaxAbsElement();
488 }
489
492 inline value_type MaxElement(void) const {
493 return vctFixedSizeMatrixLoopEngines::
494 SoMi<typename vctBinaryOperations<value_type>::Maximum,
496 Run(*this);
497 }
498
501 inline value_type MinElement(void) const {
502 return vctFixedSizeMatrixLoopEngines::
503 SoMi<typename vctBinaryOperations<value_type>::Minimum,
505 Run(*this);
506 }
507
514 inline value_type MaxAbsElement(void) const {
515 return vctFixedSizeMatrixLoopEngines::
516 SoMi<typename vctBinaryOperations<value_type>::Maximum,
518 Run(*this);
519 }
520
525 inline value_type MinAbsElement(void) const {
526 return vctFixedSizeMatrixLoopEngines::
527 SoMi<typename vctBinaryOperations<value_type>::Minimum,
529 Run(*this);
530 }
531
539 inline void MinAndMaxElement(value_type & minElement, value_type & maxElement) const
540 {
541 vctFixedSizeMatrixLoopEngines::MinAndMax::Run((*this), minElement, maxElement);
542 }
543
546 inline bool IsPositive(void) const {
547 return vctFixedSizeMatrixLoopEngines::
548 SoMi<typename vctBinaryOperations<bool>::And,
550 Run(*this);
551 }
552
555 inline bool IsNonNegative(void) const {
556 return vctFixedSizeMatrixLoopEngines::
557 SoMi<typename vctBinaryOperations<bool>::And,
559 Run(*this);
560 }
561
564 inline bool IsNonPositive(void) const {
565 return vctFixedSizeMatrixLoopEngines::
566 SoMi<typename vctBinaryOperations<bool>::And,
568 Run(*this);
569 }
570
573 inline bool IsNegative (void) const {
574 return vctFixedSizeMatrixLoopEngines::
575 SoMi< typename vctBinaryOperations<bool>::And,
577 Run(*this);
578 }
579
582 inline bool All(void) const {
583 return vctFixedSizeMatrixLoopEngines::
584 SoMi< typename vctBinaryOperations<bool>::And,
586 Run(*this);
587 }
588
591 inline bool Any(void) const {
592 return vctFixedSizeMatrixLoopEngines::
593 SoMi< typename vctBinaryOperations<bool>::Or,
595 Run(*this);
596 }
597
600 inline bool IsFinite(void) const {
601 return vctFixedSizeMatrixLoopEngines::
602 SoMi< typename vctBinaryOperations<bool>::And,
604 Run(*this);
605 }
606
609 inline bool HasNaN(void) const {
610 return vctFixedSizeMatrixLoopEngines::
611 SoMi< typename vctBinaryOperations<bool>::Or,
613 Run(*this);
614 }
615
616
617
620
625 inline bool IsColMajor(void) const {
626 return (row_stride() <= col_stride());
627 }
628
633 inline bool IsRowMajor(void) const {
634 return (col_stride() <= row_stride());
635 }
636
639 inline bool IsCompact(void) const {
640 return (((row_stride() == 1) && (col_stride() == static_cast<stride_type>(rows())))
641 || ((col_stride() == 1) && (row_stride() == static_cast<stride_type>(cols()))));
642 }
643
649 inline bool IsFortran(void) const {
650 return (IsColMajor() && (row_stride() == 1) && (col_stride() == static_cast<stride_type>(rows())));
651 }
652
655 inline bool StorageOrder(void) const {
656 return this->IsRowMajor();
657 }
658
660 inline bool IsSquare(void) const {
661 return (this->rows() == this->cols());
662 }
663
665 inline bool IsSquare(size_type size) const {
666 return ((this->rows() == size)
667 && (this->cols() == size));
668 }
669
672 template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, class __dataPtrType>
677
680 template<class __matrixOwnerType>
682 {
683 return vctFastCopy::MatrixCopyCompatible(*this, source);
684 }
685
686
687
691
703 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
704 inline bool Equal(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
705 value_type, __dataPtrType> & otherMatrix) const {
706 return vctFixedSizeMatrixLoopEngines::
707 SoMiMi<typename vctBinaryOperations<bool>::And,
709 Run(*this, otherMatrix);
710 }
711
712 /* documented above */
713 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
714 inline bool operator == (const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
715 value_type, __dataPtrType> & otherMatrix) const {
716 return Equal(otherMatrix);
717 }
718
719 /* documented above */
720 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
721 inline bool AlmostEqual(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
722 value_type, __dataPtrType> & otherMatrix,
723 value_type tolerance) const {
724 return ((*this - otherMatrix).LinfNorm() <= tolerance);
725 }
726
727 /* documented above */
728 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
729 inline bool AlmostEqual(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
730 value_type, __dataPtrType> & otherMatrix) const {
731 return ((*this - otherMatrix).LinfNorm() <= cmnTypeTraits<_elementType>::Tolerance());
732 }
733
734 /* documented above */
735 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
736 inline bool NotEqual(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
737 value_type, __dataPtrType> & otherMatrix) const {
738 return vctFixedSizeMatrixLoopEngines::
739 SoMiMi<typename vctBinaryOperations<bool>::Or,
741 Run(*this, otherMatrix);
742 }
743
744 /* documented above */
745 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
746 inline bool operator != (const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
747 value_type, __dataPtrType> & otherMatrix) const {
748 return NotEqual(otherMatrix);
749 }
750
751 /* documented above */
752 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
753 inline bool Lesser(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
754 value_type, __dataPtrType> & otherMatrix) const {
755 return vctFixedSizeMatrixLoopEngines::
756 SoMiMi<typename vctBinaryOperations<bool>::And,
758 Run(*this, otherMatrix);
759 }
760
761 /* documented above */
762 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
763 inline bool LesserOrEqual(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
764 value_type, __dataPtrType> & otherMatrix) const {
765 return vctFixedSizeMatrixLoopEngines::
766 SoMiMi<typename vctBinaryOperations<bool>::And,
768 Run(*this, otherMatrix);
769 }
770
771 /* documented above */
772 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
773 inline bool Greater(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
774 value_type, __dataPtrType> & otherMatrix) const {
775 return vctFixedSizeMatrixLoopEngines::
776 SoMiMi<typename vctBinaryOperations<bool>::And,
778 Run(*this, otherMatrix);
779 }
780
781 /* documented above */
782 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
783 inline bool GreaterOrEqual(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
784 value_type, __dataPtrType> & otherMatrix) const {
785 return vctFixedSizeMatrixLoopEngines::
786 SoMiMi<typename vctBinaryOperations<bool>::And,
788 Run(*this, otherMatrix);
789 }
790
792
796
808 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
810 ElementwiseEqual(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
811 value_type, __dataPtrType> & otherMatrix) const {
813 _rows, _cols,
814 _rowStride, _colStride, _dataPtrType,
815 __rowStride, __colStride, __dataPtrType,
818 }
819
820 /* documented above */
821 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
823 ElementwiseNotEqual(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
824 value_type, __dataPtrType> & otherMatrix) const {
826 _rows, _cols,
827 _rowStride, _colStride, _dataPtrType,
828 __rowStride, __colStride, __dataPtrType,
831 }
832
833 /* documented above */
834 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
836 ElementwiseLesser(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
837 value_type, __dataPtrType> & otherMatrix) const {
839 _rows, _cols,
840 _rowStride, _colStride, _dataPtrType,
841 __rowStride, __colStride, __dataPtrType,
844 }
845
846 /* documented above */
847 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
849 ElementwiseLesserOrEqual(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
850 value_type, __dataPtrType> & otherMatrix) const {
852 _rows, _cols,
853 _rowStride, _colStride, _dataPtrType,
854 __rowStride, __colStride, __dataPtrType,
857 }
858
859 /* documented above */
860 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
862 ElementwiseGreater(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
863 value_type, __dataPtrType> & otherMatrix) const {
865 _rows, _cols,
866 _rowStride, _colStride, _dataPtrType,
867 __rowStride, __colStride, __dataPtrType,
870 }
871
872 /* documented above */
873 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
875 ElementwiseGreaterOrEqual(const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
876 value_type, __dataPtrType> & otherMatrix) const {
878 _rows, _cols,
879 _rowStride, _colStride, _dataPtrType,
880 __rowStride, __colStride, __dataPtrType,
883 }
884
885
889
900 inline bool Equal(const value_type & scalar) const {
901 return vctFixedSizeMatrixLoopEngines::
902 SoMiSi<typename vctBinaryOperations<bool>::And,
904 Run(*this, scalar);
905 }
906
907 /* documented above */
908 inline bool operator == (const value_type & scalar) const {
909 return Equal(scalar);
910 }
911
912 /* documented above */
913 inline bool NotEqual(const value_type & scalar) const {
914 return vctFixedSizeMatrixLoopEngines::
915 SoMiSi<typename vctBinaryOperations<bool>::Or,
917 Run(*this, scalar);
918 }
919
920 /* documented above */
921 inline bool operator != (const value_type & scalar) const {
922 return NotEqual(scalar);
923 }
924
925 /* documented above */
926 inline bool Lesser(const value_type & scalar) const {
927 return vctFixedSizeMatrixLoopEngines::
928 SoMiSi<typename vctBinaryOperations<bool>::And,
930 Run(*this, scalar);
931 }
932
933 /* documented above */
934 inline bool LesserOrEqual(const value_type & scalar) const {
935 return vctFixedSizeMatrixLoopEngines::
936 SoMiSi<typename vctBinaryOperations<bool>::And,
938 Run(*this, scalar);
939 }
940
941 /* documented above */
942 inline bool Greater(const value_type & scalar) const {
943 return vctFixedSizeMatrixLoopEngines::
944 SoMiSi<typename vctBinaryOperations<bool>::And,
946 Run(*this, scalar);
947 }
948
949 /* documented above */
950 inline bool GreaterOrEqual(const value_type & scalar) const {
951 return vctFixedSizeMatrixLoopEngines::
952 SoMiSi<typename vctBinaryOperations<bool>::And,
954 Run(*this, scalar);
955 }
956
958
959
963
974 inline BoolMatrixValueType ElementwiseEqual(const value_type & scalar) const {
976 _rows, _cols,
977 _rowStride, _colStride, _dataPtrType,
980 }
981
982 /* documented above */
985 _rows, _cols,
986 _rowStride, _colStride, _dataPtrType,
989 }
990
991 /* documented above */
992 inline BoolMatrixValueType ElementwiseLesser(const value_type & scalar) const {
994 _rows, _cols,
995 _rowStride, _colStride, _dataPtrType,
998 }
999
1000 /* documented above */
1003 _rows, _cols,
1004 _rowStride, _colStride, _dataPtrType,
1005 value_type,
1007 }
1008
1009 /* documented above */
1012 _rows, _cols,
1013 _rowStride, _colStride, _dataPtrType,
1014 value_type,
1016 }
1017
1018 /* documented above */
1021 _rows, _cols,
1022 _rowStride, _colStride, _dataPtrType,
1023 value_type,
1025 }
1026
1028
1032
1039 inline MatrixValueType Abs(void) const;
1040
1041 /* documented above */
1042 inline MatrixValueType Negation(void) const;
1043
1044 /* documented above */
1045 inline MatrixValueType Floor(void) const;
1046
1047 /* documented above */
1048 inline MatrixValueType Ceil(void) const;
1050
1051
1057
1061 {
1063 }
1064
1078 template <size_type _subRows, size_type _subCols>
1085
1097 static const MatrixValueType & Eye(void);
1098
1100 std::string ToString(void) const {
1101 std::stringstream outputStream;
1102 ToStream(outputStream);
1103 return outputStream.str();
1104 }
1105
1107 void ToStream(std::ostream & outputStream) const {
1108 const size_type myRows = rows();
1109 const size_type myCols = cols();
1110 // preserve the formatting flags as they were
1111 const std::streamsize width = outputStream.width(12);
1112 const std::streamsize precision = outputStream.precision(6);
1113 bool showpoint = ((outputStream.flags() & std::ios_base::showpoint) != 0);
1114 outputStream << std::setprecision(6) << std::showpoint;
1115 size_type indexRow, indexCol;
1116 for (indexRow = 0; indexRow < myRows; ++indexRow) {
1117 for (indexCol = 0; indexCol < myCols; ++indexCol) {
1118 outputStream << std::setw(12) << this->Element(indexRow, indexCol);
1119 if (indexCol < (myCols-1)) {
1120 outputStream << " ";
1121 }
1122 }
1123 // end of line between rows, not at the end
1124 if (indexRow != (myRows - 1)) {
1125 outputStream << std::endl;
1126 }
1127 }
1128 // resume the formatting flags
1129 outputStream << std::setprecision(precision) << std::setw(width);
1130 if (!showpoint) {
1131 outputStream << std::noshowpoint;
1132 }
1133 }
1134
1136 void ToStreamRaw(std::ostream & outputStream, const char delimiter = ' ',
1137 bool headerOnly = false, const std::string & headerPrefix = "") const
1138 {
1139 const size_type myRows = rows();
1140 const size_type myCols = cols();
1141 size_type indexRow, indexCol;
1142
1143 if (headerOnly) {
1144 for (indexRow = 0; indexRow < myRows; ++indexRow) {
1145 for (indexCol = 0; indexCol < myCols; ++indexCol) {
1146 outputStream << headerPrefix << "-m" << indexRow << "_" << indexCol;
1147 // delimiter between elements
1148 if (indexCol < (myCols - 1)) {
1149 outputStream << delimiter;
1150 }
1151 }
1152 // delimiter between rows, not at the end
1153 if (indexRow < (myRows - 1)) {
1154 outputStream << delimiter;
1155 }
1156 }
1157 } else {
1158 for (indexRow = 0; indexRow < myRows; ++indexRow) {
1159 for (indexCol = 0; indexCol < myCols; ++indexCol) {
1160 outputStream << this->Element(indexRow, indexCol);
1161 // delimiter between elements
1162 if (indexCol < (myCols - 1)) {
1163 outputStream << delimiter;
1164 }
1165 }
1166 // delimiter between rows, not at the end
1167 if (indexRow < (myRows - 1)) {
1168 outputStream << delimiter;
1169 }
1170 }
1171 }
1172 }
1173
1175 void SerializeRaw(std::ostream & outputStream) const
1176 {
1177 const size_type myRows = rows();
1178 const size_type myCols = cols();
1179 size_type indexRow, indexCol;
1180
1181 for (indexRow = 0; indexRow < myRows; ++indexRow) {
1182 for (indexCol = 0; indexCol < myCols; ++indexCol) {
1183 cmnSerializeRaw(outputStream, this->Element(indexRow, indexCol));
1184 }
1185 }
1186 }
1187
1188};
1189
1190
1191
1193template <vct::size_type _rows, vct::size_type _cols,
1194 vct::stride_type _rowStride, vct::stride_type _colStride,
1195 class _elementType, class _dataPtrType>
1199
1201template <vct::size_type _rows, vct::size_type _cols,
1202 vct::stride_type _rowStride, vct::stride_type _colStride,
1203 class _elementType, class _dataPtrType>
1207
1209template <vct::size_type _rows, vct::size_type _cols,
1210 vct::stride_type _rowStride, vct::stride_type _colStride,
1211 class _elementType, class _dataPtrType>
1212std::ostream & operator << (std::ostream & output,
1214 matrix.ToStream(output);
1215 return output;
1216}
1217
1218
1219#endif // _vctFixedSizeConstMatrixBase_h
static Type Tolerance(void)
Definition cmnTypeTraits.h:170
Test for equality between input1 and input2.
Definition vctBinaryOperations.h:282
Test if input1 is greater than input2.
Definition vctBinaryOperations.h:363
Test if input1 is greater than or equal to input2.
Definition vctBinaryOperations.h:384
Test if input1 is lesser than input2.
Definition vctBinaryOperations.h:322
Test if input1 is lesser than or equal to input2.
Definition vctBinaryOperations.h:343
Test for non equality between input1 and input2.
Definition vctBinaryOperations.h:302
Definition vctForwardDeclarations.h:145
static bool MatrixCopyCompatible(const _matrix1Type &matrix1, const _matrix2Type &matrix2)
Definition vctFastCopy.h:135
Definition vctFixedSizeConstMatrixBase.h:1080
vctFixedSizeConstMatrixRef< value_type, _subRows, _subCols, ROWSTRIDE, COLSTRIDE > Type
Definition vctFixedSizeConstMatrixBase.h:1083
A template for a fixed size matrix with fixed spacing in memory.
Definition vctFixedSizeConstMatrixBase.h:104
vctFixedSizeMatrixTraits< _elementType, _rows, _cols, _rowStride, _colStride > MatrixTraits
Definition vctFixedSizeConstMatrixBase.h:120
bool HasNaN(void) const
Definition vctFixedSizeConstMatrixBase.h:609
BoolMatrixValueType ElementwiseLesser(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:836
const_pointer Pointer(size_type rowIndex, size_type colIndex) const
Definition vctFixedSizeConstMatrixBase.h:329
const_reference at(size_type rowIndex, size_type colIndex) const CISST_THROW(std
Definition vctFixedSizeConstMatrixBase.h:378
bool operator!=(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:746
bool AlmostEqual(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:729
bool IsNonNegative(void) const
Definition vctFixedSizeConstMatrixBase.h:555
vctFixedSizeVector< _elementType, COLS > RowValueType
Definition vctFixedSizeConstMatrixBase.h:172
value_type MaxElement(void) const
Definition vctFixedSizeConstMatrixBase.h:492
bool IsSquare(void) const
Definition vctFixedSizeConstMatrixBase.h:660
bool IsNegative(void) const
Definition vctFixedSizeConstMatrixBase.h:573
bool IsNonPositive(void) const
Definition vctFixedSizeConstMatrixBase.h:564
size_type cols() const
Definition vctFixedSizeConstMatrixBase.h:282
void ToStreamRaw(std::ostream &outputStream, const char delimiter=' ', bool headerOnly=false, const std::string &headerPrefix="") const
Definition vctFixedSizeConstMatrixBase.h:1136
bool operator==(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:714
vctFixedSizeVector< _elementType, ROWS > ColumnValueType
Definition vctFixedSizeConstMatrixBase.h:175
BoolMatrixValueType ElementwiseNotEqual(const value_type &scalar) const
Definition vctFixedSizeConstMatrixBase.h:983
vctFixedSizeConstMatrixRef< _elementType, __subRows, __subCols, _rowStride, _colStride > Ref(const size_type startRow=0, const size_type startCol=0) const CISST_THROW(std
Definition vctFixedSizeConstMatrixBase.h:418
difference_type row_stride() const
Definition vctFixedSizeConstMatrixBase.h:303
void ToStream(std::ostream &outputStream) const
Definition vctFixedSizeConstMatrixBase.h:1107
_dataPtrType DataType
Definition vctFixedSizeConstMatrixBase.h:212
vctFixedSizeVectorRef< _elementType, COLS, COLSTRIDE > RowRefType
Definition vctFixedSizeConstMatrixBase.h:152
bool IsCompact(void) const
Definition vctFixedSizeConstMatrixBase.h:639
bool Lesser(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:753
bool IsFortran(void) const
Definition vctFixedSizeConstMatrixBase.h:649
bool Any(void) const
Definition vctFixedSizeConstMatrixBase.h:591
value_type SumOfElements() const
Definition vctFixedSizeConstMatrixBase.h:430
vctFixedSizeMatrix< bool, ROWS, COLS, COLSTRIDE<=ROWSTRIDE > BoolMatrixValueType
Definition vctFixedSizeConstMatrixBase.h:210
BoolMatrixValueType ElementwiseGreater(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:862
bool IsColMajor(void) const
Definition vctFixedSizeConstMatrixBase.h:625
bool Greater(const value_type &scalar) const
Definition vctFixedSizeConstMatrixBase.h:942
const nstride_type & strides(void) const
Definition vctFixedSizeConstMatrixBase.h:296
size_type rows() const
Definition vctFixedSizeConstMatrixBase.h:277
vctFixedSizeConstMatrixRef< _elementType, _cols, _rows, _colStride, _rowStride > ConstRefTransposeType
Definition vctFixedSizeConstMatrixBase.h:187
const nsize_type & sizes(void) const
Definition vctFixedSizeConstMatrixBase.h:271
bool GreaterOrEqual(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:783
MatrixValueType Negation(void) const
Definition vctFixedSizeMatrix.h:392
vctFixedSizeConstMatrixRef< _elementType, _rows, _cols, _rowStride, _colStride > ConstRefType
Definition vctFixedSizeConstMatrixBase.h:178
value_type MinElement(void) const
Definition vctFixedSizeConstMatrixBase.h:501
MatrixTraits::iterator iterator
Definition vctFixedSizeConstMatrixBase.h:123
MatrixValueType Abs(void) const
Definition vctFixedSizeMatrix.h:381
bool FastCopyCompatible(const vctDynamicConstMatrixBase< __matrixOwnerType, value_type > &source) const
Definition vctFixedSizeConstMatrixBase.h:681
vctFixedSizeConstVectorRef< _elementType, DIAGONAL_LENGTH, DIAGONAL_STRIDE > ConstDiagonalRefType
Definition vctFixedSizeConstMatrixBase.h:164
BoolMatrixValueType ElementwiseLesserOrEqual(const value_type &scalar) const
Definition vctFixedSizeConstMatrixBase.h:1001
value_type L1Norm(void) const
Definition vctFixedSizeConstMatrixBase.h:473
bool ValidIndex(size_type rowIndex, size_type colIndex) const
Definition vctFixedSizeConstMatrixBase.h:348
TransposeValueType Transpose() const
Definition vctFixedSizeConstMatrixBase.h:1060
size_type max_size() const
Definition vctFixedSizeConstMatrixBase.h:290
vctFixedSizeConstVectorRef< _elementType, ROWS, ROWSTRIDE > ConstColumnRefType
Definition vctFixedSizeConstMatrixBase.h:156
BoolMatrixValueType ElementwiseGreaterOrEqual(const value_type &scalar) const
Definition vctFixedSizeConstMatrixBase.h:1019
difference_type col_stride() const
Definition vctFixedSizeConstMatrixBase.h:309
vctFixedSizeConstVectorRef< _elementType, COLS, COLSTRIDE > ConstRowRefType
Definition vctFixedSizeConstMatrixBase.h:148
BoolMatrixValueType ElementwiseNotEqual(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:823
MatrixTraits::reverse_iterator reverse_iterator
Definition vctFixedSizeConstMatrixBase.h:129
BoolMatrixValueType ElementwiseGreater(const value_type &scalar) const
Definition vctFixedSizeConstMatrixBase.h:1010
value_type ProductOfElements() const
Definition vctFixedSizeConstMatrixBase.h:439
value_type MinAbsElement(void) const
Definition vctFixedSizeConstMatrixBase.h:525
vctFixedSizeConstMatrixBase< _rows, _cols, _rowStride, _colStride, _elementType, _dataPtrType > ThisType
Definition vctFixedSizeConstMatrixBase.h:116
MatrixTraits::const_reverse_iterator const_reverse_iterator
Definition vctFixedSizeConstMatrixBase.h:132
MatrixTraits::const_iterator const_iterator
Definition vctFixedSizeConstMatrixBase.h:126
void SerializeRaw(std::ostream &outputStream) const
Definition vctFixedSizeConstMatrixBase.h:1175
vctFixedSizeMatrixRef< _elementType, _cols, _rows, _colStride, _rowStride > RefTransposeType
Definition vctFixedSizeConstMatrixBase.h:192
const_reverse_iterator rbegin() const
Definition vctFixedSizeConstMatrixBase.h:252
const_reference Element(size_type rowIndex, size_type colIndex) const
Definition vctFixedSizeConstMatrixBase.h:397
BoolMatrixValueType ElementwiseLesser(const value_type &scalar) const
Definition vctFixedSizeConstMatrixBase.h:992
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
NormType Norm(void) const
Definition vctFixedSizeConstMatrixBase.h:465
vctFixedSizeMatrixRef< _elementType, _rows, _cols, _rowStride, _colStride > RefType
Definition vctFixedSizeConstMatrixBase.h:181
bool GreaterOrEqual(const value_type &scalar) const
Definition vctFixedSizeConstMatrixBase.h:950
vctFixedSizeVectorRef< _elementType, ROWS, ROWSTRIDE > ColumnRefType
Definition vctFixedSizeConstMatrixBase.h:160
bool AlmostEqual(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix, value_type tolerance) const
Definition vctFixedSizeConstMatrixBase.h:721
BoolMatrixValueType ElementwiseEqual(const value_type &scalar) const
Definition vctFixedSizeConstMatrixBase.h:974
bool Equal(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:704
bool Equal(const value_type &scalar) const
Definition vctFixedSizeConstMatrixBase.h:900
value_type Trace(void) const
Definition vctFixedSizeConstMatrixBase.h:450
bool IsRowMajor(void) const
Definition vctFixedSizeConstMatrixBase.h:633
bool LesserOrEqual(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:763
ConstColumnRefType Column(size_type index) const
Definition vctFixedSizeConstMatrixBase.h:406
const_reference at(size_type index) const CISST_THROW(std
Definition vctFixedSizeConstMatrixBase.h:368
bool NotEqual(const value_type &scalar) const
Definition vctFixedSizeConstMatrixBase.h:913
bool empty() const
Definition vctFixedSizeConstMatrixBase.h:315
VCT_NARRAY_TRAITS_TYPEDEFS(DIMENSION)
bool ValidIndex(size_type index) const
Definition vctFixedSizeConstMatrixBase.h:342
value_type LinfNorm(void) const
Definition vctFixedSizeConstMatrixBase.h:486
void MinAndMaxElement(value_type &minElement, value_type &maxElement) const
Definition vctFixedSizeConstMatrixBase.h:539
bool IsPositive(void) const
Definition vctFixedSizeConstMatrixBase.h:546
bool All(void) const
Definition vctFixedSizeConstMatrixBase.h:582
size_type size() const
Definition vctFixedSizeConstMatrixBase.h:266
vctFixedSizeMatrix< _elementType, COLS, ROWS, COLSTRIDE<=ROWSTRIDE > TransposeValueType
Definition vctFixedSizeConstMatrixBase.h:198
bool NotEqual(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:736
BoolMatrixValueType ElementwiseGreaterOrEqual(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:875
vctFixedSizeMatrix< _elementType, ROWS, COLS, COLSTRIDE<=ROWSTRIDE > MatrixValueType
Definition vctFixedSizeConstMatrixBase.h:204
bool Greater(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:773
const_pointer Pointer(void) const
Definition vctFixedSizeConstMatrixBase.h:336
ConstRowRefType operator[](size_type index) const
Definition vctFixedSizeConstMatrixBase.h:321
value_type NormSquare(void) const
Definition vctFixedSizeConstMatrixBase.h:456
ConstDiagonalRefType Diagonal(void) const
Definition vctFixedSizeConstMatrixBase.h:410
bool ValidColIndex(size_type colIndex) const
Definition vctFixedSizeConstMatrixBase.h:359
bool IsSquare(size_type size) const
Definition vctFixedSizeConstMatrixBase.h:665
std::string ToString(void) const
Definition vctFixedSizeConstMatrixBase.h:1100
const_reverse_iterator rend() const
Definition vctFixedSizeConstMatrixBase.h:259
MatrixValueType Ceil(void) const
Definition vctFixedSizeMatrix.h:414
const_reference operator()(size_type rowIndex, size_type colIndex) const CISST_THROW(std
Definition vctFixedSizeConstMatrixBase.h:386
void ThrowUnlessValidIndex(size_type rowIndex, size_type colIndex) const CISST_THROW(std
Definition vctFixedSizeConstMatrixBase.h:228
bool FastCopyCompatible(const vctFixedSizeConstMatrixBase< __rows, __cols, __rowStride, __colStride, value_type, __dataPtrType > &source) const
Definition vctFixedSizeConstMatrixBase.h:673
MatrixValueType Floor(void) const
Definition vctFixedSizeMatrix.h:403
bool ValidRowIndex(size_type rowIndex) const
Definition vctFixedSizeConstMatrixBase.h:354
vctFixedSizeVectorRef< _elementType, DIAGONAL_LENGTH, DIAGONAL_STRIDE > DiagonalRefType
Definition vctFixedSizeConstMatrixBase.h:168
ConstRowRefType Row(size_type index) const
Definition vctFixedSizeConstMatrixBase.h:402
bool StorageOrder(void) const
Definition vctFixedSizeConstMatrixBase.h:655
BoolMatrixValueType ElementwiseEqual(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:810
void ThrowUnlessValidIndex(size_type index) const CISST_THROW(std
Definition vctFixedSizeConstMatrixBase.h:220
bool Lesser(const value_type &scalar) const
Definition vctFixedSizeConstMatrixBase.h:926
const_iterator begin() const
Definition vctFixedSizeConstMatrixBase.h:238
const_iterator end() const
Definition vctFixedSizeConstMatrixBase.h:245
bool IsFinite(void) const
Definition vctFixedSizeConstMatrixBase.h:600
bool LesserOrEqual(const value_type &scalar) const
Definition vctFixedSizeConstMatrixBase.h:934
BoolMatrixValueType ElementwiseLesserOrEqual(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix) const
Definition vctFixedSizeConstMatrixBase.h:849
static const MatrixValueType & Eye(void)
Definition vctFixedSizeMatrix.h:425
ConstRefTransposeType TransposeRef(void) const
Definition vctFixedSizeConstMatrixRef.h:172
Definition vctForwardDeclarations.h:106
Definition vctForwardDeclarations.h:86
Implementation of a fixed-size matrix using template metaprogramming.
Definition vctFixedSizeMatrix.h:54
static void Run(const _inputMatrixType &inputMatrix, typename _inputMatrixType::value_type &minValue, typename _inputMatrixType::value_type &maxValue)
Definition vctFixedSizeMatrixLoopEngines.h:762
Definition vctForwardDeclarations.h:110
Define common container related types based on the properties of a fixed size container.
Definition vctFixedSizeMatrixTraits.h:47
vctFixedStrideMatrixConstIterator< _elementType, -_colStride, _cols, -_rowStride > const_reverse_iterator
Definition vctFixedSizeMatrixTraits.h:62
@ COLSTRIDE
Definition vctFixedSizeMatrixTraits.h:74
@ ROWSTRIDE
Definition vctFixedSizeMatrixTraits.h:74
vctFixedStrideMatrixIterator< _elementType, _colStride, _cols, _rowStride > iterator
Definition vctFixedSizeMatrixTraits.h:53
@ ROWS
Definition vctFixedSizeMatrixTraits.h:67
@ LENGTH
Definition vctFixedSizeMatrixTraits.h:67
@ COLS
Definition vctFixedSizeMatrixTraits.h:67
vctFixedStrideMatrixConstIterator< _elementType, _colStride, _cols, _rowStride > const_iterator
Definition vctFixedSizeMatrixTraits.h:56
vctFixedStrideMatrixIterator< _elementType, -_colStride, _cols, -_rowStride > reverse_iterator
Definition vctFixedSizeMatrixTraits.h:59
Implementation of a fixed-size vector using template metaprogramming.
Definition vctFixedSizeVector.h:54
Definition vctForwardDeclarations.h:89
Returns the absolute value of the input as an OutputType object.
Definition vctUnaryOperations.h:80
Returns the input as an OutputType object.
Definition vctUnaryOperations.h:65
Definition vctUnaryOperations.h:186
Definition vctUnaryOperations.h:194
Definition vctUnaryOperations.h:170
Definition vctUnaryOperations.h:154
Definition vctUnaryOperations.h:162
Definition vctUnaryOperations.h:178
Definition vctUnaryOperations.h:146
Returns the square of the input as an OutputType object.
Definition vctUnaryOperations.h:119
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
Declaration of cmnSerializer and functions cmnSerializeRaw.
void cmnSerializeRaw(std::ostream &outputStream, const _elementType &data) CISST_THROW(std
Definition cmnSerializer.h:76
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition cmnThrow.h:76
STL namespace.
size_t size_type
Definition vctContainerTraits.h:35
ptrdiff_t stride_type
Definition vctContainerTraits.h:37
bool vctAll(const vctDynamicConstMatrixBase< _matrixOwnerType, _elementType > &matrix)
Definition vctDynamicConstMatrixBase.h:1176
bool vctAny(const vctDynamicConstMatrixBase< _matrixOwnerType, _elementType > &matrix)
Definition vctDynamicConstMatrixBase.h:1182
size_type width() const
Definition vctDynamicConstMatrixBase.h:253
vctFixedSizeMatrix< bool, _rows, _cols > vctFixedSizeMatrixElementwiseCompareMatrix(const vctFixedSizeConstMatrixBase< _rows, _cols, _rowStride, _colStride, _elementType, _dataPtrType > &matrix1, const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, _elementType, __dataPtrType > &matrix2)
Definition vctFixedSizeMatrix.h:442
std::ostream & operator<<(std::ostream &output, const vctFixedSizeConstMatrixBase< _rows, _cols, _rowStride, _colStride, _elementType, _dataPtrType > &matrix)
Definition vctFixedSizeConstMatrixBase.h:1212
vctFixedSizeMatrix< bool, _rows, _cols > vctFixedSizeMatrixElementwiseCompareScalar(const vctFixedSizeConstMatrixBase< _rows, _cols, _rowStride, _colStride, _elementType, _dataPtrType > &matrix, const _elementType &scalar)
Definition vctFixedSizeMatrix.h:458
Declaration of vctFixedSizeMatrixLoopEngines.
Declaration of vctFixedSizeMatrixTraits.
Declaration of vctFixedSizeVector.
Declaration of vctFixedSizeVectorRef.