/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */ /* Author(s): Ofri Sadowsky, Anton Deguet Created on: 2004-07-01 (C) Copyright 2004-2007 Johns Hopkins University (JHU), All Rights Reserved. --- begin cisst license - do not edit --- This software is provided "as is" under an open source license, with no warranty. The complete license can be found in license.txt and http://www.cisst.org/cisst/license.txt. --- end cisst license --- */ #pragma once #ifndef _vctDynamicMatrix_h #define _vctDynamicMatrix_h /*! \file \brief Declaration of vctDynamicMatrix */ #include #include #include #include /*! \ingroup cisstVector \brief A matrix object of dynamic size. This class defines a matrix object of dynamic size with memory allocation. The algebraic operations are mostly inherited from the base classes vctDynamicMatrixBase and vctDynamicConstMatrixBase. Here, we will briefly describe the specific properties of vctDynamicMatrix, with a few usage examples.
  1. The class is templated by its element type, that is, the matrix element. Normally, the element should be an arithmetic type, that is, support all the standard arithmetic operations: +, -, *, /, =, ==, <, >, <=, >=, ...
  2. The class uses dynamically allocated memory, and, more importantly, \em owns the memory. That is, a vctDynamicMatrix object automatically frees the allocated memory it owns when it is destroyed.
  3. To allocate the memory, use one of the following operations. \code // define a typical element type typedef double ElementType; // the matrixRows and matrixCols variables can be set to any value at // any time before creating the matrix. size_t matrixRows = 12; size_t matrixCols = 9; // constructor allocation vctDynamicMatrix m1(matrixRows, matrixCols); // Create an empty matrix and later allocate memory. vctDynamicMatrix m2; m2.SetSize(matrixRows, matrixCols); // Create a dynamic matrix of some size and then change it. // This operation does not preserve any elements in the resized // matrix vctDynamicMatrix m3(3 * matrixRows, 3 * matrixCols); m3.SetSize(2 * matrixRows, 2 * matrixCols); // resize a matrix and keep as many elements as possible. m3.resize(matrixRows, matrixCols); // Store an algebraic result to a new matrix. In this case, // memory is allocated by the algebraic operation, and then // attached to the matrix object. vctDynamicMatrix m4 = m3 - m2; \endcode
  4. The default storage order is row first. This can be modified using the different constructors as well as the method SetSize with the flags #VCT_ROW_MAJOR or #VCT_COL_MAJOR. \code // 12 by 7 matrix stored column first vctDynamicMatrix m1(12, 7, VCT_COL_MAJOR); // a similar matrix filled with zeroes vctDynamicMatrix m1(12, 7, 0.0, VCT_COL_MAJOR); // resize the matrix and change its storage order m1.SetSize(5, 7, VCT_ROW_MAJOR); \endcode
  5. Matrix assignment can be facilitated through the Assign method (defined in the base class) or as follows. \code // Initialize all elements to the same value vctDynamicMatrix v5(matrixRows, matrixCols, 2.0); // Initialize the elements by specific values. NOTE: All the // arguments MUST be of type ElementType vctDynamicMatrix matrix(2, 4); matrix.Assign(7.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0); // correct matrix.Assign(7, 1, 2, 3, 4, 5, 6, 7); // WRONG, missing dot // Assign one matrix to another. vctDynamicMatrix matrixInt; matrixInt.Assign(matrix); matrixInt = matrix; // same operation \endcode
A few more notes.
  • The elements lie in contiguous increasing memory addresses.
  • There is no direct way of ``disowning'' a vctDynamicMatrix, that is taking ownership of its memory.
  • When a function returns an allocating dynamic matrix object, it is better to return a vctReturnDynamicMatrix, which is a helper class designed for transfering the ownership of the allocated memory without reallocation.
\param _elementType the type of an element in the matrix \sa vctDynamicMatrixBase vctDynamicConstMatrixBase */ template class vctDynamicMatrix : public vctDynamicMatrixBase, _elementType> { friend class vctReturnDynamicMatrix<_elementType>; public: VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType); enum {DIMENSION = 2}; VCT_NARRAY_TRAITS_TYPEDEFS(DIMENSION); typedef vctDynamicMatrixBase, _elementType> BaseType; typedef vctDynamicMatrix<_elementType> ThisType; /*! Default constructor. Initialize an empty matrix. */ vctDynamicMatrix() // The default initialization of vctDynamicMatrixOwner is empty. {} /* Constructor: Create a matrix of the specified size. Elements initialized with default constructor. The storage order can be either #VCT_ROW_MAJOR or #VCT_COL_MAJOR. */ //@{ vctDynamicMatrix(size_type rows, size_type cols, bool storageOrder = VCT_DEFAULT_STORAGE) { this->SetSize(rows, cols, storageOrder); } vctDynamicMatrix(const nsize_type & matrixSize, bool storageOrder = VCT_DEFAULT_STORAGE) { this->SetSize(matrixSize, storageOrder); } //@} /*! Constructor: Create a matrix of the specified size and assign all elements a specific value. The storage order can be either #VCT_ROW_MAJOR or #VCT_COL_MAJOR.*/ //@{ vctDynamicMatrix(size_type rows, size_type cols, value_type value, bool storageOrder = VCT_DEFAULT_STORAGE) { this->SetSize(rows, cols, storageOrder); this->SetAll(value); } vctDynamicMatrix(const nsize_type & matrixSize, value_type value, bool storageOrder = VCT_DEFAULT_STORAGE) { this->SetSize(matrixSize, storageOrder); this->SetAll(value); } //@} /*! Special copy constructor: Take ownership of the data of a temporary matrix object of type vctReturnDynamicMatrix. Disown the other matrix. */ vctDynamicMatrix(const vctReturnDynamicMatrix & otherMatrix); /*! Copy constructor: Allocate memory to store a copy of the other matrix, and copy the elements of the other matrix to this matrix. */ vctDynamicMatrix(const ThisType & otherMatrix): BaseType() { this->SetSize(otherMatrix.rows(), otherMatrix.cols(), otherMatrix.StorageOrder()); this->Assign(otherMatrix); } /*! Copy constructor: Allocate memory and copy all the elements from the other matrix. The storage order can be either #VCT_ROW_MAJOR or #VCT_COL_MAJOR.*/ template vctDynamicMatrix(const vctDynamicConstMatrixBase<__matrixOwnerType, __otherMatrixElementType> & otherMatrix, bool storageOrder) { this->SetSize(otherMatrix.rows(), otherMatrix.cols(), storageOrder); this->Assign(otherMatrix); } /*! Copy constructor: Allocate memory and copy all the elements from the other matrix. The storage order of the copied matrix is defined by the source matrix. */ template vctDynamicMatrix(const vctDynamicConstMatrixBase<__matrixOwnerType, value_type> & otherMatrix) { this->SetSize(otherMatrix.rows(), otherMatrix.cols(), otherMatrix.StorageOrder()); this->Assign(otherMatrix); } /*! Copy constructor: Allocate memory and copy all the elements from the other matrix. The storage order of the copied matrix is defined by the source matrix. This constructor can also be used for type conversions. */ template explicit vctDynamicMatrix(const vctDynamicConstMatrixBase<__matrixOwnerType, __otherMatrixElementType> & otherMatrix) { this->SetSize(otherMatrix.rows(), otherMatrix.cols(), otherMatrix.StorageOrder()); this->Assign(otherMatrix); } /*! Constructor from a fixed size matrix. */ template explicit vctDynamicMatrix(const vctFixedSizeConstMatrixBase<__rows, __cols, __rowStride, __colStride, __elementType, __dataPtrType> & other) { this->ForceAssign(other); } /*! Assignment from a dynamic matrix to a matrix. The operation discards the old memory allocated for this matrix, and allocates new memory the size of the input matrix. Then the elements of the input matrix are copied into this matrix. \todo This assumes a row major storage. Needs more work. */ template ThisType & operator = (const vctDynamicConstMatrixBase<__matrixOwnerType, __elementType> & otherMatrix) { this->SetSize(otherMatrix.rows(), otherMatrix.cols()); this->Assign(otherMatrix); return *this; } /*! Assignment from a dynamic matrix to this matrix. The operation discards the old memory allocated for this matrix, and allocates new memory the size of the input matrix. Then the elements of the input matrix are copied into this matrix. */ ThisType & operator = (const ThisType & otherMatrix) { this->SetSize(otherMatrix.rows(), otherMatrix.cols(), otherMatrix.StorageOrder()); this->Assign(otherMatrix); return *this; } /*! Assignment from a fixed size matrix. This operator will resize the left side dynamic matrix to match the right side fixed size matrix. */ template ThisType & operator = (const vctFixedSizeConstMatrixBase<__rows, __cols, __rowStride, __colStride, __elementType, __dataPtrType> & other) { this->ForceAssign(other); return *this; } /*! Assignement from a transitional vctReturnDynamicMatrix to a vctDynamicMatrix variable. This specialized operation does not perform any element copy. Instead it transfers ownership of the data from the other matrix to this matrix, and disowns the other matrix. The right hand side operand must be a temporary object returned, e.g., from a function or overloaded operator. \todo This operator needs some revisions. */ ThisType & operator = (const vctReturnDynamicMatrix & otherMatrix); /*! Assignement of a scalar to all elements. See also SetAll. */ inline ThisType & operator = (const value_type & value) { this->SetAll(value); return *this; } // documented in base class template inline ThisType & ForceAssign(const vctDynamicConstMatrixBase<__matrixOwnerType, __elementType> & other) { this->SetSize(other.sizes(), other.StorageOrder()); this->Assign(other); return *this; } // documented in base class template inline ThisType & ForceAssign(const vctFixedSizeConstMatrixBase<__rows, __cols, __rowStride, __colStride, __elementType, __dataPtrType> & other) { this->SetSize(other.sizes(), other.StorageOrder()); this->Assign(other); return *this; } /*! Non-destructive size change. Change the size to the specified size, and preserve as many rows and columns as possible from the former matrix. \note If the storage order and the sizes (both rows and columns) are unchanged, this method does nothing. \note This method doesn't allow to change the storage order of the elements (i.e. stays either row or column major). \note If the size is set to zero, the data pointer is set to null (0). */ //@{ void resize(size_type rows, size_type cols) { this->resize(nsize_type(rows, cols)); } void resize(const nsize_type & newSizes) { if (newSizes == this->sizes()) return; const bool isRowMajor = this->IsRowMajor(); ThisType newData(newSizes, isRowMajor); const nsize_type corner(0); nsize_type minSizes; minSizes.ElementwiseMinOf(this->sizes(), newSizes); vctDynamicConstMatrixRef myDataMinSpaceRef(*this, corner, minSizes); vctDynamicMatrixRef newDataMinSpaceRef(newData, corner, minSizes); newDataMinSpaceRef.Assign(myDataMinSpaceRef); this->Matrix.Disown(); this->Matrix.Own(newSizes, isRowMajor, newData.Matrix.Release()); } //@} /*! DESTRUCTIVE size change. Change the size to the specified size. Discard of all the old values. The storage order can be either #VCT_ROW_MAJOR or #VCT_COL_MAJOR. If the storage order is not specified, it is not modified. */ //@{ void SetSize(size_type rows, size_type cols, bool storageOrder) { this->Matrix.SetSize(rows, cols, storageOrder); } void SetSize(const nsize_type & matrixSize, bool storageOrder) { this->Matrix.SetSize(matrixSize, storageOrder); } void SetSize(size_type rows, size_type cols) { this->Matrix.SetSize(rows, cols, this->StorageOrder()); } void SetSize(const nsize_type & matrixSize) { this->Matrix.SetSize(matrixSize, this->StorageOrder()); } //@} /*! Binary deserialization */ void DeSerializeRaw(std::istream & inputStream) { // get and set size size_type myRows = 0; size_type myCols = 0; cmnDeSerializeSizeRaw(inputStream, myRows); cmnDeSerializeSizeRaw(inputStream, myCols); this->SetSize(myRows, myCols); // get data size_type indexRow, indexCol; for (indexRow = 0; indexRow < myRows; ++indexRow) { for (indexCol = 0; indexCol < myCols; ++indexCol) { cmnDeSerializeRaw(inputStream, this->Element(indexRow, indexCol)); } } } }; /*! Class vctReturnDynamicMatrix is specialized to store a temporary matrix object by transfering ownership. An object of this class has all the methods inherited from vctDynamicMatrix, but can only be constructed in one way -- taking the ownership from another vctDynamicMatrix (or vctReturnDynamicMatrix) object. In turn, when an assignment occurs from a vctReturnDynamicMatrix to a vctDynamicMatrix (or likewise construction), the lhs vctDynamicMatrix strips this object from the ownership of the data. Use this class only when you want to return a newly created dynamic matrix from a function, without going through memory allocation and deallocation. Never use it on an object that is going to remain in scope after constructing the vctReturnDynamicMatrix. */ template class vctReturnDynamicMatrix : public vctDynamicMatrix<_elementType> { public: /*! Base type of vctReturnDynamicMatrix. */ typedef vctDynamicMatrix<_elementType> BaseType; VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType); explicit vctReturnDynamicMatrix(const BaseType & other) { BaseType & nonConstOther = const_cast(other); // if we don't save it in a variable, it will be destroyed in the Release operation const size_type rows = other.rows(); const size_type cols = other.cols(); const bool storageOrder = other.StorageOrder(); this->Matrix.Own(rows, cols, storageOrder, nonConstOther.Matrix.Release()); } }; // implementation of the special copy constuctor of vctDynamicMatrix template vctDynamicMatrix<_elementType>::vctDynamicMatrix(const vctReturnDynamicMatrix<_elementType> & other) { vctReturnDynamicMatrix<_elementType> & nonConstOther = const_cast< vctReturnDynamicMatrix<_elementType> & >(other); // if we don't save it in a variable, it will be destroyed in the Release operation const size_type rows = other.rows(); const size_type cols = other.cols(); const bool storageOrder = other.StorageOrder(); this->Matrix.Own(rows, cols, storageOrder, nonConstOther.Matrix.Release()); } // implementation of the special assignment operator from vctReturnDynamicMatrix to vctDynamicMatrix template vctDynamicMatrix<_elementType> & vctDynamicMatrix<_elementType>::operator = (const vctReturnDynamicMatrix<_elementType> & other) { vctReturnDynamicMatrix<_elementType> & nonConstOther = const_cast< vctReturnDynamicMatrix<_elementType> & >(other); // if we don't save it in a variable, it will be destroyed in the Release operation const size_type rows = other.rows(); const size_type cols = other.cols(); const bool storageOrder = other.StorageOrder(); this->Matrix.Disown(); this->Matrix.Own(rows, cols, storageOrder, nonConstOther.Matrix.Release()); return *this; } /*! \name Elementwise operations between dynamic matrices. */ //@{ /*! Operation between dynamic matrices (same size). \param inputMatrix1 The first operand of the binary operation. \param inputMatrix2 The second operand of the binary operation. \return The matrix result of \f$op(matrix1, matrix2)\f$. */ template vctReturnDynamicMatrix<_elementType> operator + (const vctDynamicConstMatrixBase<_matrixOwnerType1, _elementType> & inputMatrix1, const vctDynamicConstMatrixBase<_matrixOwnerType2, _elementType> & inputMatrix2) { typedef _elementType value_type; vctDynamicMatrix resultStorage(inputMatrix1); resultStorage.Add(inputMatrix2); return vctReturnDynamicMatrix(resultStorage); } /* documented above */ template vctReturnDynamicMatrix<_elementType> operator - (const vctDynamicConstMatrixBase<_matrixOwnerType1, _elementType> & inputMatrix1, const vctDynamicConstMatrixBase<_matrixOwnerType2, _elementType> & inputMatrix2) { typedef _elementType value_type; vctDynamicMatrix resultStorage(inputMatrix1); resultStorage.Subtract(inputMatrix2); return vctReturnDynamicMatrix(resultStorage); } //@} /*! \name Elementwise operations between a dynamic matrix and a scalar. */ //@{ /*! Operation between a dynamic matrix and a scalar. \param inputMatrix The first operand of the binary operation. \param inputScalar The second operand of the binary operation. \return The matrix result of \f$op(matrix, scalar)\f$. */ template vctReturnDynamicMatrix<_elementType> operator + (const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & inputMatrix, const _elementType & inputScalar) { typedef _elementType value_type; vctDynamicMatrix resultStorage(inputMatrix); resultStorage.Add(inputScalar); return vctReturnDynamicMatrix(resultStorage); } /* documented above */ template vctReturnDynamicMatrix<_elementType> operator - (const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & inputMatrix, const _elementType & inputScalar) { typedef _elementType value_type; vctDynamicMatrix resultStorage(inputMatrix); resultStorage.Subtract(inputScalar); return vctReturnDynamicMatrix(resultStorage); } /* documented above */ template vctReturnDynamicMatrix<_elementType> operator * (const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & inputMatrix, const _elementType & inputScalar) { typedef _elementType value_type; vctDynamicMatrix resultStorage(inputMatrix); resultStorage.Multiply(inputScalar); return vctReturnDynamicMatrix(resultStorage); } /* documented above */ template vctReturnDynamicMatrix<_elementType> operator / (const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & inputMatrix, const _elementType & inputScalar) { typedef _elementType value_type; vctDynamicMatrix resultStorage(inputMatrix); resultStorage.Divide(inputScalar); return vctReturnDynamicMatrix(resultStorage); } //@} /*! \name Elementwise operations between a scalar and a dynamic matrix. */ //@{ /*! Operation between a scalar and a dynamic matrix. \param inputScalar The first operand of the binary operation. \param inputMatrix The second operand of the binary operation. \return The matrix result of \f$op(scalar, matrix)\f$. */ template vctReturnDynamicMatrix<_elementType> operator + (const _elementType & inputScalar, const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & inputMatrix) { typedef _elementType value_type; vctDynamicMatrix resultStorage(inputMatrix.rows(), inputMatrix.cols()); resultStorage.SumOf(inputScalar, inputMatrix); return vctReturnDynamicMatrix(resultStorage); } /* documented above */ template vctReturnDynamicMatrix<_elementType> operator - (const _elementType & inputScalar, const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & inputMatrix) { typedef _elementType value_type; vctDynamicMatrix resultStorage(inputMatrix.rows(), inputMatrix.cols()); resultStorage.DifferenceOf(inputScalar, inputMatrix); return vctReturnDynamicMatrix(resultStorage); } /* documented above */ template vctReturnDynamicMatrix<_elementType> operator * (const _elementType & inputScalar, const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & inputMatrix) { typedef _elementType value_type; vctDynamicMatrix resultStorage(inputMatrix.rows(), inputMatrix.cols()); resultStorage.ProductOf(inputScalar, inputMatrix); return vctReturnDynamicMatrix(resultStorage); } /* documented above */ template vctReturnDynamicMatrix<_elementType> operator / (const _elementType & inputScalar, const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & inputMatrix) { typedef _elementType value_type; vctDynamicMatrix resultStorage(inputMatrix.rows(), inputMatrix.cols()); resultStorage.RatioOf(inputScalar, inputMatrix); return vctReturnDynamicMatrix(resultStorage); } //@} /*! \name Elementwise operations on a dynamic matrix. */ //@{ /*! Unary operation on a dynamic matrix. \param inputMatrix The operand of the unary operation \return The matrix result of \f$op(matrix)\f$. */ template vctReturnDynamicMatrix<_elementType> operator - (const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & inputMatrix) { typedef _elementType value_type; vctDynamicMatrix resultStorage(inputMatrix.rows(), inputMatrix.cols()); resultStorage.NegationOf(inputMatrix); return vctReturnDynamicMatrix(resultStorage); } //@} #ifndef DOXYGEN template vctReturnDynamicMatrix<_elementType> operator * (const vctDynamicConstMatrixBase<_matrixOwnerType1, _elementType> & inputMatrix1, const vctDynamicConstMatrixBase<_matrixOwnerType2, _elementType> & inputMatrix2) { typedef _elementType value_type; vctDynamicMatrix resultStorage(inputMatrix1.rows(), inputMatrix2.cols()); resultStorage.ProductOf(inputMatrix1, inputMatrix2); return vctReturnDynamicMatrix(resultStorage); } template vctReturnDynamicVector<_elementType> operator * (const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & inputMatrix, const vctDynamicConstVectorBase<_vectorOwnerType, _elementType> & inputVector) { typedef _elementType value_type; vctDynamicVector resultStorage(inputMatrix.rows()); resultStorage.ProductOf(inputMatrix, inputVector); return vctReturnDynamicVector(resultStorage); } template vctReturnDynamicVector<_elementType> operator * (const vctDynamicConstVectorBase<_vectorOwnerType, _elementType> & inputVector, const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & inputMatrix) { typedef _elementType value_type; vctDynamicVector resultStorage(inputMatrix.cols()); resultStorage.ProductOf(inputVector, inputMatrix); return vctReturnDynamicVector(resultStorage); } /* Methods declared previously and implemented here because they require vctReturnDynamicMatrix */ /* documented in class vctDynamicConstMatrixBase */ template inline typename vctDynamicConstMatrixBase<_matrixOwnerType, _elementType>::MatrixReturnType vctDynamicConstMatrixBase<_matrixOwnerType, _elementType>::Abs(void) const { typedef _elementType value_type; vctDynamicMatrix resultStorage(this->rows(), this->cols()); vctDynamicMatrixLoopEngines:: MoMi::AbsValue>:: Run(resultStorage, *this); return vctReturnDynamicMatrix(resultStorage); } /* documented in class vctDynamicConstMatrixBase */ template inline typename vctDynamicConstMatrixBase<_matrixOwnerType, _elementType>::MatrixReturnType vctDynamicConstMatrixBase<_matrixOwnerType, _elementType>::Negation(void) const { typedef _elementType value_type; vctDynamicMatrix resultStorage(this->rows(), this->cols()); vctDynamicMatrixLoopEngines:: MoMi::Negation>:: Run(resultStorage, *this); return vctReturnDynamicMatrix(resultStorage); } /* documented in class vctDynamicConstMatrixBase */ template inline typename vctDynamicConstMatrixBase<_matrixOwnerType, _elementType>::MatrixReturnType vctDynamicConstMatrixBase<_matrixOwnerType, _elementType>::Floor(void) const { typedef _elementType value_type; vctDynamicMatrix resultStorage(this->rows(), this->cols()); vctDynamicMatrixLoopEngines:: MoMi::Floor>:: Run(resultStorage, *this); return vctReturnDynamicMatrix(resultStorage); } /* documented in class vctDynamicConstMatrixBase */ template inline typename vctDynamicConstMatrixBase<_matrixOwnerType, _elementType>::MatrixReturnType vctDynamicConstMatrixBase<_matrixOwnerType, _elementType>::Ceil(void) const { typedef _elementType value_type; vctDynamicMatrix resultStorage(this->rows(), this->cols()); vctDynamicMatrixLoopEngines:: MoMi::Ceil>:: Run(resultStorage, *this); return vctReturnDynamicMatrix(resultStorage); } /* documented in class vctDynamicConstMatrixBase */ template typename vctDynamicConstMatrixBase<_matrixOwnerType, _elementType>::MatrixReturnType vctDynamicConstMatrixBase<_matrixOwnerType, _elementType>::Eye(size_type size) { vctDynamicMatrix resultStorage(size, size); resultStorage.SetAll(_elementType(0)); resultStorage.Diagonal().SetAll(_elementType(1)); return vctReturnDynamicMatrix(resultStorage); } /* Documented in class vctDynamicConstMatrixBase */ template inline vctReturnDynamicMatrix vctDynamicMatrixElementwiseCompareMatrix(const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & matrix1, const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & matrix2) { vctDynamicMatrix result(matrix1.rows(), matrix1.cols()); vctDynamicMatrixLoopEngines:: MoMiMi<_elementOperationType>::Run(result, matrix1, matrix2); return vctReturnDynamicMatrix(result); } /* documented in class vctDynamicConstMatrixBase */ template inline vctReturnDynamicMatrix vctDynamicMatrixElementwiseCompareScalar(const vctDynamicConstMatrixBase<_matrixOwnerType, _elementType> & matrix, const _elementType & scalar) { vctDynamicMatrix result(matrix.rows(), matrix.cols()); vctDynamicMatrixLoopEngines:: MoMiSi<_elementOperationType>::Run(result, matrix, scalar); return vctReturnDynamicMatrix(result); } #endif // DOXYGEN #endif // _vctDynamicMatrix_h