cisst-saw
Loading...
Searching...
No Matches
vctFixedSizeMatrix.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
6 Created on: 2003-11-04
7
8 (C) Copyright 2003-2020 Johns Hopkins University (JHU), All Rights
9 Reserved.
10
11--- begin cisst license - do not edit ---
12
13This software is provided "as is" under an open source license, with
14no warranty. The complete license can be found in license.txt and
15http://www.cisst.org/cisst/license.txt.
16
17--- end cisst license ---
18*/
19
20#pragma once
21#ifndef _vctFixedSizeMatrix_h
22#define _vctFixedSizeMatrix_h
23
28
31
32
49
50template<class _elementType, vct::size_type _rows, vct::size_type _cols, bool _rowMajor>
52<_rows, _cols, _rowMajor?_cols:1, _rowMajor?1:_rows, _elementType,
53 typename vctFixedSizeMatrixTraits<_elementType, _rows, _cols, _rowMajor?_cols:1, _rowMajor?1:_rows>::array >
54{
55 public:
56 /* define most types from vctContainerTraits */
58
59 /* no need to document, inherit doxygen documentation from vctFixedSizeVectorBase */
61
63 typedef vctFixedSizeMatrixBase<_rows, _cols, _rowMajor?_cols:1, _rowMajor?1:_rows, _elementType,
64 typename vctFixedSizeMatrixTraits<_elementType, _rows, _cols,
65 _rowMajor?_cols:1, _rowMajor?1:_rows>::array >
68
73
76
79
81 inline vctFixedSizeMatrix(const ThisType & other) {
82 this->Assign(other);
83 }
84
88 explicit inline vctFixedSizeMatrix(const value_type & value) {
89 this->SetAll(value);
90 }
91
105 inline vctFixedSizeMatrix(const value_type element0, const value_type element1, ...)
106 {
107 CMN_ASSERT( this->size() > 1 );
108 (*this).at(0) = element0;
109 (*this).at(1) = element1;
110 index_type elementIndex = 2;
111 const size_type numElements = this->size();
112 va_list nextArg;
113 va_start(nextArg, element1);
114 for (; elementIndex < numElements; ++elementIndex) {
115 (*this).at(elementIndex) = value_type( va_arg(nextArg, ElementVaArgPromotion) );
116 }
117 va_end(nextArg);
118 }
119
125 template <class __elementType, stride_type __rowStride, stride_type __colStride, class __dataPtrType>
126 explicit inline
130
140 template <class __matrixOwnerType>
142 {
143 this->Assign(matrix);
144 }
145
146 template <stride_type __rowStride, stride_type __colStride, class __elementType, class __dataPtrType>
148 // Experimental static_cast replacing reinterpret_cast. Return the reinterpret_cast if you encounter
149 // compilation errors.
150 return static_cast<ThisType &>(this->Assign(other));
151 }
152
153 inline ThisType & operator = (const ThisType & other) {
154 return static_cast<ThisType &>(this->Assign(other));
155 }
156
157 template <stride_type __rowStride, stride_type __colStride>
159 {
160 return static_cast<ThisType &>(this->Assign(other));
161 }
162
163 template <stride_type __rowStride, stride_type __colStride, class __elementType>
165 {
166 this->Assign(other);
167 return *this;
168 }
169
171 inline ThisType & operator = (const value_type & value) {
172 this->SetAll(value);
173 return *this;
174 }
175
176};
177
178
179
180
183
187template <vct::size_type _rows, vct::size_type _cols,
188 vct::stride_type _input1RowStride, vct::stride_type _input1ColStride, class _input1Data,
189 vct::stride_type _input2RowStride, vct::stride_type _input2ColStride, class _input2Data, class _elementType>
197
198/* documented above */
199template <vct::size_type _rows, vct::size_type _cols,
200 vct::stride_type _input1RowStride, vct::stride_type _input1ColStride, class _input1Data,
201 vct::stride_type _input2RowStride, vct::stride_type _input2ColStride, class _input2Data, class _elementType>
209
210
211
214
218template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
221 const _elementType & scalar)
222{
224 result.SumOf(matrix, scalar);
225 return result;
226}
227
228/* documented above */
229template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
232 const _elementType & scalar)
233{
235 result.DifferenceOf(matrix, scalar);
236 return result;
237}
238
239/* documented above */
240template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
243 const _elementType & scalar)
244{
246 result.ProductOf(matrix, scalar);
247 return result;
248}
249
250/* documented above */
251template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
254 const _elementType & scalar)
255{
257 result.RatioOf(matrix, scalar);
258 return result;
259}
260
261
262
265
269template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
271operator + (const _elementType & scalar,
273{
275 result.SumOf(scalar, matrix);
276 return result;
277}
278
279/* documented above */
280template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
282operator - (const _elementType & scalar,
284{
286 result.DifferenceOf(scalar, matrix);
287 return result;
288}
289
290/* documented above */
291template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
293operator * (const _elementType & scalar,
295{
297 result.ProductOf(scalar, matrix);
298 return result;
299}
300
301/* documented above */
302template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
304operator / (const _elementType & scalar,
306{
308 result.RatioOf(scalar, matrix);
309 return result;
310}
311
312
313
314
317
321template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
329
330
331
332template <vct::size_type _rows, vct::size_type _cols, vct::size_type _input1Cols,
333 vct::stride_type _input1RowStride, vct::stride_type _input1ColStride, class _input1DataPtrType,
334 vct::stride_type _input2RowStride, vct::stride_type _input2ColStride, class _input2DataPtrType,
335 class _elementType>
343
344
345template <vct::size_type _rows, vct::size_type _cols,
346 vct::stride_type _inputMatrixRowStride, vct::stride_type _inputMatrixColStride, class _inputMAtrixDataPtrType,
347 vct::stride_type _inputVectorStride, class _inputVectorDataPtrType,
348 class _elementType>
357
358
359template <vct::size_type _rows, vct::size_type _cols,
360 vct::stride_type _inputVectorStride, class _inputVectorDataPtrType,
361 vct::stride_type _inputMatrixRowStride, vct::stride_type _inputMatrixColStride, class _inputMatrixDataPtrType,
362 class _elementType>
371
372
373/*
374 Methods declared previously and implemented here because they require vctFixedSizeVector
375*/
376#ifndef DOXYGEN
377
378/* documented in class vctFixedSizeConstMatrixBase */
379template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
382 MatrixValueType result;
383 vctFixedSizeMatrixLoopEngines::
384 MoMi<typename vctUnaryOperations<_elementType>::AbsValue>::
385 Run(result, *this);
386 return result;
387}
388
389/* documented in class vctFixedSizeConstMatrixBase */
390template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
393 MatrixValueType result;
394 vctFixedSizeMatrixLoopEngines::
395 MoMi<typename vctUnaryOperations<_elementType>::Negation>::
396 Run(result, *this);
397 return result;
398}
399
400/* documented in class vctFixedSizeConstMatrixBase */
401template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
404 MatrixValueType result;
405 vctFixedSizeMatrixLoopEngines::
406 MoMi<typename vctUnaryOperations<_elementType>::Floor>::
407 Run(result, *this);
408 return result;
409}
410
411/* documented in class vctFixedSizeConstMatrixBase */
412template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
415 MatrixValueType result;
416 vctFixedSizeMatrixLoopEngines::
417 MoMi<typename vctUnaryOperations<_elementType>::Ceil>::
418 Run(result, *this);
419 return result;
420}
421
422/* documented in class vctFixedSizeConstMatrixBase */
423template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
426 static MatrixValueType result(_elementType(0));
427#if (CISST_COMPILER == CISST_GCC) || (CISST_COMPILER == CISST_CLANG)
428 result.Diagonal().SetAll(_elementType(1));
429#else
430 static _elementType value(result.Diagonal().SetAll(_elementType(1)));
431#endif
432 return result;
433}
434
435/* documented in class vctFixedSizeConstMatrixBase */
436template <vct::size_type _rows, vct::size_type _cols,
437 vct::stride_type _rowStride, vct::stride_type _colStride, class _dataPtrType,
438 vct::stride_type __rowStride, vct::stride_type __colStride, class __dataPtrType,
439 class _elementType,
440 class _elementOperationType>
443 _elementType, _dataPtrType> & matrix1,
444 const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
445 _elementType, __dataPtrType> & matrix2) {
448 MoMiMi<_elementOperationType>::Run(result, matrix1, matrix2);
449 return result;
450}
451
452/* documented in class vctFixedSizeConstMatrixBase */
453template <vct::size_type _rows, vct::size_type _cols,
454 vct::stride_type _rowStride, vct::stride_type _colStride, class _dataPtrType,
455 class _elementType,
456 class _elementOperationType>
459 _elementType, _dataPtrType> & matrix,
460 const _elementType & scalar) {
463 MoMiSi<_elementOperationType>::Run(result, matrix, scalar);
464 return result;
465}
466#endif // DOXYGEN
467
468
469#endif // _vctFixedSizeMatrix_h
470
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition cmnTypeTraits.h:155
cmnVaArgPromotion< value_type >::Type VaArgPromotion
Definition cmnTypeTraits.h:167
_elementType value_type
Definition mtsGenericObjectProxy.h:329
Definition vctForwardDeclarations.h:145
A template for a fixed size matrix with fixed spacing in memory.
Definition vctFixedSizeConstMatrixBase.h:104
MatrixValueType Negation(void) const
Definition vctFixedSizeMatrix.h:392
MatrixValueType Abs(void) const
Definition vctFixedSizeMatrix.h:381
vctFixedSizeMatrix< _elementType, ROWS, COLS, COLSTRIDE<=ROWSTRIDE > MatrixValueType
Definition vctFixedSizeConstMatrixBase.h:204
MatrixValueType Ceil(void) const
Definition vctFixedSizeMatrix.h:414
MatrixValueType Floor(void) const
Definition vctFixedSizeMatrix.h:403
static const MatrixValueType & Eye(void)
Definition vctFixedSizeMatrix.h:425
Definition vctForwardDeclarations.h:106
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeConstVectorBase.h:108
A template for a fixed size matrix with fixed spacings in memory.
Definition vctFixedSizeMatrixBase.h:60
ThisType & DifferenceOf(const vctFixedSizeConstMatrixBase< _rows, _cols, __input1RowStride, __input1ColStride, value_type, __input1DataPtrType > &input1Matrix, const vctFixedSizeConstMatrixBase< _rows, _cols, __input2RowStride, __input2ColStride, value_type, __input2DataPtrType > &input2Matrix)
Definition vctFixedSizeMatrixBase.h:729
ThisType & NegationOf(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix)
Definition vctFixedSizeMatrixBase.h:1159
DiagonalRefType Diagonal(void)
Definition vctFixedSizeMatrixBase.h:254
ThisType & ProductOf(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &matrix, const value_type scalar)
Definition vctFixedSizeMatrixBase.h:909
ThisType & RatioOf(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &matrix, const value_type scalar)
Definition vctFixedSizeMatrixBase.h:919
ThisType & SumOf(const vctFixedSizeConstMatrixBase< _rows, _cols, __input1RowStride, __input1ColStride, value_type, __input1DataPtrType > &input1Matrix, const vctFixedSizeConstMatrixBase< _rows, _cols, __input2RowStride, __input2ColStride, value_type, __input2DataPtrType > &input2Matrix)
Definition vctFixedSizeMatrixBase.h:717
ThisType & Assign(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, __elementType, __dataPtrType > &other)
Definition vctFixedSizeMatrixBase.h:475
Implementation of a fixed-size matrix using template metaprogramming.
Definition vctFixedSizeMatrix.h:54
MatrixTraits::const_reverse_iterator const_reverse_iterator
Definition vctFixedSizeMatrix.h:72
vctFixedSizeMatrixTraits< _elementType, _rows, _cols, _rowMajor?_cols:1, _rowMajor?1:_rows > MatrixTraits
Definition vctFixedSizeMatrix.h:60
MatrixTraits::iterator iterator
Definition vctFixedSizeMatrix.h:69
vctFixedSizeMatrix< _elementType, _rows, _cols, _rowMajor > ThisType
Definition vctFixedSizeMatrix.h:67
vctFixedSizeMatrix(const vctDynamicConstMatrixBase< __matrixOwnerType, value_type > &matrix)
Definition vctFixedSizeMatrix.h:141
TypeTraits::VaArgPromotion ElementVaArgPromotion
Definition vctFixedSizeMatrix.h:75
MatrixTraits::const_iterator const_iterator
Definition vctFixedSizeMatrix.h:70
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
vctFixedSizeMatrix()
Definition vctFixedSizeMatrix.h:78
vctFixedSizeMatrix(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, __elementType, __dataPtrType > &matrix)
Definition vctFixedSizeMatrix.h:127
vctFixedSizeMatrixBase< _rows, _cols, _rowMajor?_cols:1, _rowMajor?1:_rows, _elementType, typename vctFixedSizeMatrixTraits< _elementType, _rows, _cols, _rowMajor?_cols:1, _rowMajor?1:_rows >::array > BaseType
Definition vctFixedSizeMatrix.h:66
vctFixedSizeMatrix(const ThisType &other)
Definition vctFixedSizeMatrix.h:81
vctFixedSizeMatrix(const value_type &value)
Definition vctFixedSizeMatrix.h:88
ThisType & operator=(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, __elementType, __dataPtrType > &other)
Definition vctFixedSizeMatrix.h:147
vctFixedSizeMatrix(const value_type element0, const value_type element1,...)
Definition vctFixedSizeMatrix.h:105
class cmnTypeTraits< value_type > TypeTraits
Definition vctFixedSizeMatrix.h:74
MatrixTraits::reverse_iterator reverse_iterator
Definition vctFixedSizeMatrix.h:71
static void Run(_outputMatrixType &outputMatrix, const _input1MatrixType &input1Matrix, const _input2MatrixType &input2Matrix)
Definition vctFixedSizeMatrixLoopEngines.h:79
static void Run(_outputMatrixType &outputMatrix, const _inputMatrixType &inputMatrix, const _inputScalarType inputScalar)
Definition vctFixedSizeMatrixLoopEngines.h:268
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
vctFixedStrideMatrixIterator< _elementType, _colStride, _cols, _rowStride > iterator
Definition vctFixedSizeMatrixTraits.h:53
vctFixedStrideMatrixConstIterator< _elementType, _colStride, _cols, _rowStride > const_iterator
Definition vctFixedSizeMatrixTraits.h:56
vctFixedStrideMatrixIterator< _elementType, -_colStride, _cols, -_rowStride > reverse_iterator
Definition vctFixedSizeMatrixTraits.h:59
ThisType & ProductOf(const vctFixedSizeConstVectorBase< _size, __stride, value_type, __dataPtrType > &vector, const value_type scalar)
Definition vctFixedSizeVectorBase.h:1003
Implementation of a fixed-size vector using template metaprogramming.
Definition vctFixedSizeVector.h:54
#define CMN_ASSERT(expr)
Definition cmnAssert.h:97
size_t size_type
Definition vctContainerTraits.h:35
ptrdiff_t stride_type
Definition vctContainerTraits.h:37
size_type size(void) const
Definition vctDynamicConstMatrixBase.h:228
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
vctFixedSizeMatrix< bool, _rows, _cols > vctFixedSizeMatrixElementwiseCompareScalar(const vctFixedSizeConstMatrixBase< _rows, _cols, _rowStride, _colStride, _elementType, _dataPtrType > &matrix, const _elementType &scalar)
Definition vctFixedSizeMatrix.h:458
Declaration of vctFixedSizeConstMatrixRef.
vctFixedSizeMatrix< _elementType, _rows, _cols > operator/(const vctFixedSizeConstMatrixBase< _rows, _cols, _rowStride, _colStride, _elementType, _dataPtrType > &matrix, const _elementType &scalar)
Definition vctFixedSizeMatrix.h:253
vctFixedSizeMatrix< _elementType, _rows, _cols > operator-(const vctFixedSizeConstMatrixBase< _rows, _cols, _input1RowStride, _input1ColStride, _elementType, _input1Data > &matrix1, const vctFixedSizeConstMatrixBase< _rows, _cols, _input2RowStride, _input2ColStride, _elementType, _input2Data > &matrix2)
Definition vctFixedSizeMatrix.h:203
vctFixedSizeMatrix< _elementType, _rows, _cols > operator*(const vctFixedSizeConstMatrixBase< _rows, _cols, _rowStride, _colStride, _elementType, _dataPtrType > &matrix, const _elementType &scalar)
Definition vctFixedSizeMatrix.h:242
vctFixedSizeMatrix< _elementType, _rows, _cols > operator+(const vctFixedSizeConstMatrixBase< _rows, _cols, _input1RowStride, _input1ColStride, _elementType, _input1Data > &matrix1, const vctFixedSizeConstMatrixBase< _rows, _cols, _input2RowStride, _input2ColStride, _elementType, _input2Data > &matrix2)
Definition vctFixedSizeMatrix.h:191
Declaration of vctFixedSizeMatrixRef.