cxmat.hpp
资源名称:gabor.rar [点击查看]
上传用户:soukeisyuu
上传日期:2022-07-03
资源大小:5943k
文件大小:148k
源码类别:
波变换
开发平台:
Visual C++
- /*M///////////////////////////////////////////////////////////////////////////////////////
- //
- // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
- //
- // By downloading, copying, installing or using the software you agree to this license.
- // If you do not agree to this license, do not download, install,
- // copy or use the software.
- //
- //
- // License Agreement
- // For Open Source Computer Vision Library
- //
- // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
- // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
- // Third party copyrights are property of their respective owners.
- //
- // Redistribution and use in source and binary forms, with or without modification,
- // are permitted provided that the following conditions are met:
- //
- // * Redistribution's of source code must retain the above copyright notice,
- // this list of conditions and the following disclaimer.
- //
- // * Redistribution's in binary form must reproduce the above copyright notice,
- // this list of conditions and the following disclaimer in the documentation
- // and/or other materials provided with the distribution.
- //
- // * The name of the copyright holders may not be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // This software is provided by the copyright holders and contributors "as is" and
- // any express or implied warranties, including, but not limited to, the implied
- // warranties of merchantability and fitness for a particular purpose are disclaimed.
- // In no event shall the Intel Corporation or contributors be liable for any direct,
- // indirect, incidental, special, exemplary, or consequential damages
- // (including, but not limited to, procurement of substitute goods or services;
- // loss of use, data, or profits; or business interruption) however caused
- // and on any theory of liability, whether in contract, strict liability,
- // or tort (including negligence or otherwise) arising in any way out of
- // the use of this software, even if advised of the possibility of such damage.
- //
- //M*/
- #ifndef _OPENCV_CORE_MAT_OPERATIONS_H_
- #define _OPENCV_CORE_MAT_OPERATIONS_H_
- #ifndef SKIP_INCLUDES
- #include <limits.h>
- #endif // SKIP_INCLUDES
- #ifdef __cplusplus
- namespace cv
- {
- //////////////////////////////// Mat ////////////////////////////////
- inline Mat::Mat()
- : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0) {}
- inline Mat::Mat(int _rows, int _cols, int _type)
- : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0)
- {
- if( _rows > 0 && _cols > 0 )
- create( _rows, _cols, _type );
- }
- inline Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s)
- : flags(0), rows(0), cols(0), step(0), data(0), refcount(0),
- datastart(0), dataend(0)
- {
- if(_rows > 0 && _cols > 0)
- {
- create(_rows, _cols, _type);
- *this = _s;
- }
- }
- inline Mat::Mat(Size _size, int _type)
- : flags(0), rows(0), cols(0), step(0), data(0), refcount(0),
- datastart(0), dataend(0)
- {
- if( _size.height > 0 && _size.width > 0 )
- create( _size.height, _size.width, _type );
- }
- inline Mat::Mat(Size _size, int _type, const Scalar& _s)
- : flags(0), rows(0), cols(0), step(0), data(0), refcount(0),
- datastart(0), dataend(0)
- {
- if( _size.height > 0 && _size.width > 0 )
- {
- create( _size.height, _size.width, _type );
- *this = _s;
- }
- }
- inline Mat::Mat(const Mat& m)
- : flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data),
- refcount(m.refcount), datastart(m.datastart), dataend(m.dataend)
- {
- if( refcount )
- CV_XADD(refcount, 1);
- }
- inline Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step)
- : flags(MAGIC_VAL + (_type & TYPE_MASK)), rows(_rows), cols(_cols),
- step(_step), data((uchar*)_data), refcount(0),
- datastart((uchar*)_data), dataend((uchar*)_data)
- {
- size_t minstep = cols*elemSize();
- if( step == AUTO_STEP )
- {
- step = minstep;
- flags |= CONTINUOUS_FLAG;
- }
- else
- {
- if( rows == 1 ) step = minstep;
- CV_DbgAssert( step >= minstep );
- flags |= step == minstep ? CONTINUOUS_FLAG : 0;
- }
- dataend += step*(rows-1) + minstep;
- }
- inline Mat::Mat(Size _size, int _type, void* _data, size_t _step)
- : flags(MAGIC_VAL + (_type & TYPE_MASK)), rows(_size.height), cols(_size.width),
- step(_step), data((uchar*)_data), refcount(0),
- datastart((uchar*)_data), dataend((uchar*)_data)
- {
- size_t minstep = cols*elemSize();
- if( step == AUTO_STEP )
- {
- step = minstep;
- flags |= CONTINUOUS_FLAG;
- }
- else
- {
- if( rows == 1 ) step = minstep;
- CV_DbgAssert( step >= minstep );
- flags |= step == minstep ? CONTINUOUS_FLAG : 0;
- }
- dataend += step*(rows-1) + minstep;
- }
- inline Mat::Mat(const Mat& m, const Range& rowRange, const Range& colRange)
- {
- flags = m.flags;
- step = m.step; refcount = m.refcount;
- data = m.data; datastart = m.datastart; dataend = m.dataend;
- if( rowRange == Range::all() )
- rows = m.rows;
- else
- {
- CV_Assert( 0 <= rowRange.start && rowRange.start <= rowRange.end && rowRange.end <= m.rows );
- rows = rowRange.size();
- data += step*rowRange.start;
- }
- if( colRange == Range::all() )
- cols = m.cols;
- else
- {
- CV_Assert( 0 <= colRange.start && colRange.start <= colRange.end && colRange.end <= m.cols );
- cols = colRange.size();
- data += colRange.start*elemSize();
- flags &= cols < m.cols ? ~CONTINUOUS_FLAG : -1;
- }
- if( rows == 1 )
- flags |= CONTINUOUS_FLAG;
- if( refcount )
- CV_XADD(refcount, 1);
- if( rows <= 0 || cols <= 0 )
- rows = cols = 0;
- }
- inline Mat::Mat(const Mat& m, const Rect& roi)
- : flags(m.flags), rows(roi.height), cols(roi.width),
- step(m.step), data(m.data + roi.y*step), refcount(m.refcount),
- datastart(m.datastart), dataend(m.dataend)
- {
- flags &= roi.width < m.cols ? ~CONTINUOUS_FLAG : -1;
- data += roi.x*elemSize();
- CV_Assert( 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols &&
- 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows );
- if( refcount )
- CV_XADD(refcount, 1);
- if( rows <= 0 || cols <= 0 )
- rows = cols = 0;
- }
- inline Mat::Mat(const CvMat* m, bool copyData)
- : flags(MAGIC_VAL + (m->type & (CV_MAT_TYPE_MASK|CV_MAT_CONT_FLAG))),
- rows(m->rows), cols(m->cols), step(m->step), data(m->data.ptr), refcount(0),
- datastart(m->data.ptr), dataend(m->data.ptr)
- {
- if( step == 0 )
- step = cols*elemSize();
- size_t minstep = cols*elemSize();
- dataend += step*(rows-1) + minstep;
- if( copyData )
- {
- data = datastart = dataend = 0;
- Mat(m->rows, m->cols, m->type, m->data.ptr, m->step).copyTo(*this);
- }
- }
- template<typename _Tp> inline Mat::Mat(const vector<_Tp>& vec, bool copyData)
- : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG),
- rows(0), cols(0), step(0), data(0), refcount(0),
- datastart(0), dataend(0)
- {
- if(vec.empty())
- return;
- if( !copyData )
- {
- rows = (int)vec.size();
- cols = 1;
- step = sizeof(_Tp);
- data = datastart = (uchar*)&vec[0];
- dataend = datastart + rows*step;
- }
- else
- Mat((int)vec.size(), 1, DataType<_Tp>::type, (uchar*)&vec[0]).copyTo(*this);
- }
- inline Mat::~Mat()
- {
- release();
- }
- inline Mat& Mat::operator = (const Mat& m)
- {
- if( this != &m )
- {
- if( m.refcount )
- CV_XADD(m.refcount, 1);
- release();
- flags = m.flags;
- rows = m.rows; cols = m.cols;
- step = m.step; data = m.data;
- datastart = m.datastart; dataend = m.dataend;
- refcount = m.refcount;
- }
- return *this;
- }
- inline Mat Mat::row(int y) const { return Mat(*this, Range(y, y+1), Range::all()); }
- inline Mat Mat::col(int x) const { return Mat(*this, Range::all(), Range(x, x+1)); }
- inline Mat Mat::rowRange(int startrow, int endrow) const
- { return Mat(*this, Range(startrow, endrow), Range::all()); }
- inline Mat Mat::rowRange(const Range& r) const
- { return Mat(*this, r, Range::all()); }
- inline Mat Mat::colRange(int startcol, int endcol) const
- { return Mat(*this, Range::all(), Range(startcol, endcol)); }
- inline Mat Mat::colRange(const Range& r) const
- { return Mat(*this, Range::all(), r); }
- inline Mat Mat::diag(int d) const
- {
- Mat m = *this;
- size_t esz = elemSize();
- int len;
- if( d >= 0 )
- {
- len = std::min(cols - d, rows);
- m.data += esz*d;
- }
- else
- {
- len = std::min(rows + d, cols);
- m.data -= step*d;
- }
- CV_DbgAssert( len > 0 );
- m.rows = len;
- m.cols = 1;
- m.step += esz;
- if( m.rows > 1 )
- m.flags &= ~CONTINUOUS_FLAG;
- else
- m.flags |= CONTINUOUS_FLAG;
- return m;
- }
- inline Mat Mat::diag(const Mat& d)
- {
- Mat m(d.rows, d.rows, d.type(), Scalar(0)), md = m.diag();
- d.copyTo(md);
- return m;
- }
- inline Mat Mat::clone() const
- {
- Mat m;
- copyTo(m);
- return m;
- }
- inline void Mat::assignTo( Mat& m, int type ) const
- {
- if( type < 0 )
- m = *this;
- else
- convertTo(m, type);
- }
- inline void Mat::create(int _rows, int _cols, int _type)
- {
- _type &= TYPE_MASK;
- if( rows == _rows && cols == _cols && type() == _type && data )
- return;
- if( data )
- release();
- CV_DbgAssert( _rows >= 0 && _cols >= 0 );
- if( _rows > 0 && _cols > 0 )
- {
- flags = MAGIC_VAL + CONTINUOUS_FLAG + _type;
- rows = _rows;
- cols = _cols;
- step = elemSize()*cols;
- int64 _nettosize = (int64)step*rows;
- size_t nettosize = (size_t)_nettosize;
- if( _nettosize != (int64)nettosize )
- CV_Error(CV_StsNoMem, "Too big buffer is allocated");
- size_t datasize = alignSize(nettosize, (int)sizeof(*refcount));
- datastart = data = (uchar*)fastMalloc(datasize + sizeof(*refcount));
- dataend = data + nettosize;
- refcount = (int*)(data + datasize);
- *refcount = 1;
- }
- }
- inline void Mat::create(Size _size, int _type)
- {
- create(_size.height, _size.width, _type);
- }
- inline void Mat::addref()
- { if( refcount ) CV_XADD(refcount, 1); }
- inline void Mat::release()
- {
- if( refcount && CV_XADD(refcount, -1) == 1 )
- fastFree(datastart);
- data = datastart = dataend = 0;
- step = rows = cols = 0;
- refcount = 0;
- }
- inline void Mat::locateROI( Size& wholeSize, Point& ofs ) const
- {
- size_t esz = elemSize(), minstep;
- ptrdiff_t delta1 = data - datastart, delta2 = dataend - datastart;
- CV_DbgAssert( step > 0 );
- if( delta1 == 0 )
- ofs.x = ofs.y = 0;
- else
- {
- ofs.y = (int)(delta1/step);
- ofs.x = (int)((delta1 - step*ofs.y)/esz);
- CV_DbgAssert( data == datastart + ofs.y*step + ofs.x*esz );
- }
- minstep = (ofs.x + cols)*esz;
- wholeSize.height = (int)((delta2 - minstep)/step + 1);
- wholeSize.height = std::max(wholeSize.height, ofs.y + rows);
- wholeSize.width = (int)((delta2 - step*(wholeSize.height-1))/esz);
- wholeSize.width = std::max(wholeSize.width, ofs.x + cols);
- }
- inline Mat& Mat::adjustROI( int dtop, int dbottom, int dleft, int dright )
- {
- Size wholeSize; Point ofs;
- size_t esz = elemSize();
- locateROI( wholeSize, ofs );
- int row1 = std::max(ofs.y - dtop, 0), row2 = std::min(ofs.y + rows + dbottom, wholeSize.height);
- int col1 = std::max(ofs.x - dleft, 0), col2 = std::min(ofs.x + cols + dright, wholeSize.width);
- data += (row1 - ofs.y)*step + (col1 - ofs.x)*esz;
- rows = row2 - row1; cols = col2 - col1;
- if( esz*cols == step || rows == 1 )
- flags |= CONTINUOUS_FLAG;
- else
- flags &= ~CONTINUOUS_FLAG;
- return *this;
- }
- inline Mat Mat::operator()( Range rowRange, Range colRange ) const
- {
- return Mat(*this, rowRange, colRange);
- }
- inline Mat Mat::operator()( const Rect& roi ) const
- { return Mat(*this, roi); }
- inline Mat::operator CvMat() const
- {
- CvMat m = cvMat(rows, cols, type(), data);
- m.step = (int)step;
- m.type = (m.type & ~CONTINUOUS_FLAG) | (flags & CONTINUOUS_FLAG);
- return m;
- }
- inline Mat::operator IplImage() const
- {
- IplImage img;
- cvInitImageHeader(&img, size(), cvIplDepth(flags), channels());
- cvSetData(&img, data, (int)step);
- return img;
- }
- inline bool Mat::isContinuous() const { return (flags & CONTINUOUS_FLAG) != 0; }
- inline size_t Mat::elemSize() const { return CV_ELEM_SIZE(flags); }
- inline size_t Mat::elemSize1() const { return CV_ELEM_SIZE1(flags); }
- inline int Mat::type() const { return CV_MAT_TYPE(flags); }
- inline int Mat::depth() const { return CV_MAT_DEPTH(flags); }
- inline int Mat::channels() const { return CV_MAT_CN(flags); }
- inline size_t Mat::step1() const { return step/elemSize1(); }
- inline Size Mat::size() const { return Size(cols, rows); }
- inline bool Mat::empty() const { return data == 0; }
- inline uchar* Mat::ptr(int y)
- {
- CV_DbgAssert( (unsigned)y < (unsigned)rows );
- return data + step*y;
- }
- inline const uchar* Mat::ptr(int y) const
- {
- CV_DbgAssert( (unsigned)y < (unsigned)rows );
- return data + step*y;
- }
- template<typename _Tp> inline _Tp* Mat::ptr(int y)
- {
- CV_DbgAssert( (unsigned)y < (unsigned)rows );
- return (_Tp*)(data + step*y);
- }
- template<typename _Tp> inline const _Tp* Mat::ptr(int y) const
- {
- CV_DbgAssert( (unsigned)y < (unsigned)rows );
- return (const _Tp*)(data + step*y);
- }
- template<typename _Tp> inline _Tp& Mat::at(int y, int x)
- {
- CV_DbgAssert( (unsigned)y < (unsigned)rows && (unsigned)x < (unsigned)cols &&
- sizeof(_Tp) == elemSize() );
- return ((_Tp*)(data + step*y))[x];
- }
- template<typename _Tp> inline const _Tp& Mat::at(int y, int x) const
- {
- CV_DbgAssert( (unsigned)y < (unsigned)rows && (unsigned)x < (unsigned)cols &&
- sizeof(_Tp) == elemSize() );
- return ((const _Tp*)(data + step*y))[x];
- }
- template<typename _Tp> inline _Tp& Mat::at(Point pt)
- {
- CV_DbgAssert( (unsigned)pt.y < (unsigned)rows && (unsigned)pt.x < (unsigned)cols &&
- sizeof(_Tp) == elemSize() );
- return ((_Tp*)(data + step*pt.y))[pt.x];
- }
- template<typename _Tp> inline const _Tp& Mat::at(Point pt) const
- {
- CV_DbgAssert( (unsigned)pt.y < (unsigned)rows && (unsigned)pt.x < (unsigned)cols &&
- sizeof(_Tp) == elemSize() );
- return ((const _Tp*)(data + step*pt.y))[pt.x];
- }
- template<typename _Tp> inline MatConstIterator_<_Tp> Mat::begin() const
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- return MatConstIterator_<_Tp>((const Mat_<_Tp>*)this);
- }
- template<typename _Tp> inline MatConstIterator_<_Tp> Mat::end() const
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- MatConstIterator_<_Tp> it((const Mat_<_Tp>*)this);
- it.ptr = it.sliceEnd = (_Tp*)(data + step*(rows-1)) + cols;
- return it;
- }
- template<typename _Tp> inline MatIterator_<_Tp> Mat::begin()
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- return MatIterator_<_Tp>((Mat_<_Tp>*)this);
- }
- template<typename _Tp> inline MatIterator_<_Tp> Mat::end()
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- MatIterator_<_Tp> it((Mat_<_Tp>*)this);
- it.ptr = it.sliceEnd = (_Tp*)(data + step*(rows-1)) + cols;
- return it;
- }
- static inline void swap( Mat& a, Mat& b )
- {
- std::swap( a.flags, b.flags );
- std::swap( a.rows, b.rows ); std::swap( a.cols, b.cols );
- std::swap( a.step, b.step ); std::swap( a.data, b.data );
- std::swap( a.datastart, b.datastart );
- std::swap( a.dataend, b.dataend );
- std::swap( a.refcount, b.refcount );
- }
- inline SVD::SVD() {}
- inline SVD::SVD( const Mat& m, int flags ) { operator ()(m, flags); }
- inline void SVD::solveZ( const Mat& m, Mat& dst )
- {
- SVD svd(m);
- svd.vt.row(svd.vt.rows-1).reshape(1,svd.vt.cols).copyTo(dst);
- }
- ///////////////////////////////// Mat_<_Tp> ////////////////////////////////////
- template<typename _Tp> inline Mat_<_Tp>::Mat_() :
- Mat() { flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; }
- template<typename _Tp> inline Mat_<_Tp>::Mat_(int _rows, int _cols) :
- Mat(_rows, _cols, DataType<_Tp>::type) {}
- template<typename _Tp> inline Mat_<_Tp>::Mat_(int _rows, int _cols, const _Tp& value) :
- Mat(_rows, _cols, DataType<_Tp>::type) { *this = value; }
- template<typename _Tp> inline Mat_<_Tp>::Mat_(Size _size) :
- Mat(_size.height, _size.width, DataType<_Tp>::type) {}
- template<typename _Tp> inline Mat_<_Tp>::Mat_(Size _size, const _Tp& value) :
- Mat(_size.height, _size.width, DataType<_Tp>::type) { *this = value; }
- template<typename _Tp> inline Mat_<_Tp>::Mat_(const Mat& m) : Mat()
- { flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; *this = m; }
- template<typename _Tp> inline Mat_<_Tp>::Mat_(const Mat_& m) : Mat(m) {}
- template<typename _Tp> inline Mat_<_Tp>::Mat_(int _rows, int _cols, _Tp* _data, size_t _step)
- : Mat(_rows, _cols, DataType<_Tp>::type, _data, _step) {}
- template<typename _Tp> inline Mat_<_Tp>::Mat_(const Mat_& m, const Range& rowRange, const Range& colRange)
- : Mat(m, rowRange, colRange) {}
- template<typename _Tp> inline Mat_<_Tp>::Mat_(const Mat_& m, const Rect& roi)
- : Mat(m, roi) {}
- template<typename _Tp> template<int n> inline Mat_<_Tp>::Mat_(const Vec<_Tp, n>& vec)
- : Mat(n, 1, DataType<_Tp>::type)
- {
- _Tp* d = (_Tp*)data;
- for( int i = 0; i < n; i++ )
- d[i] = vec[i];
- }
- template<typename _Tp> inline Mat_<_Tp>::Mat_(const vector<_Tp>& vec, bool copyData)
- : Mat(vec, copyData)
- {}
- template<typename _Tp> inline Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m)
- {
- if( DataType<_Tp>::type == m.type() )
- {
- Mat::operator = (m);
- return *this;
- }
- if( DataType<_Tp>::depth == m.depth() )
- {
- return (*this = m.reshape(DataType<_Tp>::channels));
- }
- CV_DbgAssert(DataType<_Tp>::channels == m.channels());
- m.convertTo(*this, type());
- return *this;
- }
- template<typename _Tp> inline Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat_& m)
- {
- Mat::operator=(m);
- return *this;
- }
- template<typename _Tp> inline Mat_<_Tp>& Mat_<_Tp>::operator = (const _Tp& s)
- {
- Mat::operator=(Scalar(s));
- return *this;
- }
- template<typename _Tp> inline void Mat_<_Tp>::create(int _rows, int _cols)
- {
- Mat::create(_rows, _cols, DataType<_Tp>::type);
- }
- template<typename _Tp> inline void Mat_<_Tp>::create(Size _size)
- {
- Mat::create(_size, DataType<_Tp>::type);
- }
- template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::cross(const Mat_& m) const
- { return Mat_<_Tp>(Mat::cross(m)); }
- template<typename _Tp> template<typename T2> inline Mat_<_Tp>::operator Mat_<T2>() const
- { return Mat_<T2>(*this); }
- template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::row(int y) const
- { return Mat_(*this, Range(y, y+1), Range::all()); }
- template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::col(int x) const
- { return Mat_(*this, Range::all(), Range(x, x+1)); }
- template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::diag(int d) const
- { return Mat_(Mat::diag(d)); }
- template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::clone() const
- { return Mat_(Mat::clone()); }
- template<typename _Tp> inline size_t Mat_<_Tp>::elemSize() const
- {
- CV_DbgAssert( Mat::elemSize() == sizeof(_Tp) );
- return sizeof(_Tp);
- }
- template<typename _Tp> inline size_t Mat_<_Tp>::elemSize1() const
- {
- CV_DbgAssert( Mat::elemSize1() == sizeof(_Tp)/DataType<_Tp>::channels );
- return sizeof(_Tp)/DataType<_Tp>::channels;
- }
- template<typename _Tp> inline int Mat_<_Tp>::type() const
- {
- CV_DbgAssert( Mat::type() == DataType<_Tp>::type );
- return DataType<_Tp>::type;
- }
- template<typename _Tp> inline int Mat_<_Tp>::depth() const
- {
- CV_DbgAssert( Mat::depth() == DataType<_Tp>::depth );
- return DataType<_Tp>::depth;
- }
- template<typename _Tp> inline int Mat_<_Tp>::channels() const
- {
- CV_DbgAssert( Mat::channels() == DataType<_Tp>::channels );
- return DataType<_Tp>::channels;
- }
- template<typename _Tp> inline size_t Mat_<_Tp>::stepT() const { return step/elemSize(); }
- template<typename _Tp> inline size_t Mat_<_Tp>::step1() const { return step/elemSize1(); }
- template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::reshape(int _rows) const
- { return Mat_<_Tp>(Mat::reshape(0,_rows)); }
- template<typename _Tp> inline Mat_<_Tp>& Mat_<_Tp>::adjustROI( int dtop, int dbottom, int dleft, int dright )
- { return (Mat_<_Tp>&)(Mat::adjustROI(dtop, dbottom, dleft, dright)); }
- template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::operator()( const Range& rowRange, const Range& colRange ) const
- { return Mat_<_Tp>(*this, rowRange, colRange); }
- template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::operator()( const Rect& roi ) const
- { return Mat_<_Tp>(roi); }
- template<typename _Tp> inline _Tp* Mat_<_Tp>::operator [](int y)
- { return (_Tp*)ptr(y); }
- template<typename _Tp> inline const _Tp* Mat_<_Tp>::operator [](int y) const
- { return (const _Tp*)ptr(y); }
- template<typename _Tp> inline _Tp& Mat_<_Tp>::operator ()(int row, int col)
- {
- CV_DbgAssert( (unsigned)row < (unsigned)rows && (unsigned)col < (unsigned)cols );
- return ((_Tp*)(data + step*row))[col];
- }
- template<typename _Tp> inline const _Tp& Mat_<_Tp>::operator ()(int row, int col) const
- {
- CV_DbgAssert( (unsigned)row < (unsigned)rows && (unsigned)col < (unsigned)cols );
- return ((const _Tp*)(data + step*row))[col];
- }
- template<typename _Tp> inline _Tp& Mat_<_Tp>::operator ()(Point pt)
- {
- CV_DbgAssert( (unsigned)pt.y < (unsigned)rows && (unsigned)pt.x < (unsigned)cols );
- return ((_Tp*)(data + step*pt.y))[pt.x];
- }
- template<typename _Tp> inline const _Tp& Mat_<_Tp>::operator ()(Point pt) const
- {
- CV_DbgAssert( (unsigned)pt.y < (unsigned)rows && (unsigned)pt.x < (unsigned)cols );
- return ((const _Tp*)(data + step*pt.y))[pt.x];
- }
- template<typename _Tp> inline Mat_<_Tp>::operator vector<_Tp>() const
- {
- CV_Assert( rows == 1 || cols == 1 );
- return isContinuous() ? vector<_Tp>((size_t)(rows + cols - 1), (_Tp*)data) :
- (vector<_Tp>)((Mat_<_Tp>)this->t());
- }
- template<typename T1, typename T2, typename Op> inline void
- process( const Mat_<T1>& m1, Mat_<T2>& m2, Op op )
- {
- int y, x, rows = m1.rows, cols = m1.cols;
- int c1 = m1.channels(), c2 = m2.channels();
- CV_DbgAssert( m1.size() == m2.size() );
- for( y = 0; y < rows; y++ )
- {
- const T1* src = m1[y];
- T2* dst = m2[y];
- for( x = 0; x < cols; x++ )
- dst[x] = op(src[x]);
- }
- }
- template<typename T1, typename T2, typename T3, typename Op> inline void
- process( const Mat_<T1>& m1, const Mat_<T2>& m2, Mat_<T3>& m3, Op op )
- {
- int y, x, rows = m1.rows, cols = m1.cols;
- CV_DbgAssert( m1.size() == m2.size() );
- for( y = 0; y < rows; y++ )
- {
- const T1* src1 = m1[y];
- const T2* src2 = m2[y];
- T3* dst = m3[y];
- for( x = 0; x < cols; x++ )
- dst[x] = op( src1[x], src2[x] );
- }
- }
- template<typename M> class CV_EXPORTS MatExpr_Base_
- {
- public:
- MatExpr_Base_() {}
- virtual ~MatExpr_Base_() {}
- virtual void assignTo(M& m, int type=-1) const = 0;
- };
- template<typename E, typename M> class CV_EXPORTS MatExpr_ : public MatExpr_Base_<M>
- {
- public:
- MatExpr_(const E& _e) : e(_e) {}
- ~MatExpr_() {}
- operator M() const { return (M)e; }
- void assignTo(M& m, int type=-1) const { e.assignTo(m, type); }
- M row(int y) const { return ((M)e).row(y); }
- M col(int x) const { return ((M)e).col(x); }
- M diag(int d=0) const { return ((M)e).diag(d); }
- M operator()( const Range& rowRange, const Range& colRange ) const
- { return ((M)e)(rowRange, colRange); }
- M operator()( const Rect& roi ) const { return ((M)e)(roi); }
- M cross(const M& m) const { return ((M)e).cross(m); }
- double dot(const M& m) const { return ((M)e).dot(m); }
- MatExpr_<MatExpr_Op2_<M, double, M, MatOp_T_<Mat> >, M> t() const
- { return ((M)e).t(); }
- MatExpr_<MatExpr_Op2_<M, int, M, MatOp_Inv_<Mat> >, M> inv(int method=DECOMP_LU) const
- { return ((M)e).inv(method); }
- MatExpr_<MatExpr_Op4_<M, M, double, char, M, MatOp_MulDiv_<Mat> >, M>
- mul(const M& m, double scale=1) const
- { return ((M)e).mul(m, scale); }
- template<typename A> MatExpr_<MatExpr_Op4_<M, M, double, char, M, MatOp_MulDiv_<Mat> >, M >
- mul(const MatExpr_<A, M>& m, double scale=1) const
- { return ((M)e).mul(m, scale); }
- E e;
- };
- inline Mat::Mat(const MatExpr_Base& expr)
- : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0)
- {
- expr.assignTo(*this);
- }
- inline Mat& Mat::operator = (const MatExpr_Base& expr)
- {
- expr.assignTo(*this);
- return *this;
- }
- template<typename _Tp> inline Mat_<_Tp>::Mat_(const MatExpr_Base& e) : Mat()
- {
- e.assignTo(*this, DataType<_Tp>::type);
- }
- template<typename _Tp> inline Mat_<_Tp>& Mat_<_Tp>::operator = (const MatExpr_Base& e)
- {
- e.assignTo(*this, DataType<_Tp>::type);
- return *this;
- }
- template<typename _Tp> inline Mat_<_Tp>::operator MatExpr_<Mat_<_Tp>, Mat_<_Tp> >() const
- { return MatExpr_<Mat_<_Tp>, Mat_<_Tp> >(*this); }
- inline Mat::operator MatExpr_<Mat, Mat>() const
- { return MatExpr_<Mat, Mat>(*this); }
- template<typename M> class CV_EXPORTS MatOp_Sub_
- {
- public:
- MatOp_Sub_() {}
- static void apply(const M& a, const M& b, M& c, int type=-1)
- {
- if( type == a.type() || type < 0 )
- {
- subtract( a, b, c );
- }
- else
- {
- Mat temp;
- apply(a, b, temp);
- temp.convertTo(c, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_Scale_
- {
- public:
- MatOp_Scale_() {}
- static void apply(const M& a, double alpha, M& c, int type=-1)
- {
- a.convertTo(c, type, alpha, 0);
- }
- };
- template<typename M> class CV_EXPORTS MatOp_ScaleAddS_
- {
- public:
- MatOp_ScaleAddS_() {}
- static void apply(const M& a, double alpha, double beta, M& c, int type=-1)
- {
- a.convertTo(c, type, alpha, beta);
- }
- };
- template<typename M> class CV_EXPORTS MatOp_AddS_
- {
- public:
- MatOp_AddS_() {}
- static void apply(const M& a, const Scalar& s, M& c, int type=-1)
- {
- if( type == a.type() || type < 0 )
- {
- add(a, s, c);
- }
- else
- {
- Mat temp;
- apply(a, s, temp);
- temp.convertTo(c, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_AddEx_
- {
- public:
- MatOp_AddEx_() {}
- static void apply(const M& a, double alpha, const M& b,
- double beta, double gamma, M& c, int type=-1)
- {
- if( type == a.type() || type < 0 )
- {
- addWeighted(a, alpha, b, beta, gamma, c);
- }
- else
- {
- Mat temp;
- apply(a, alpha, b, beta, gamma, temp);
- temp.convertTo(c, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_Bin_
- {
- public:
- MatOp_Bin_() {}
- static void apply(const M& a, const M& b, int _op, M& c, int type=-1)
- {
- char op = (char)_op;
- if( type == a.type() || type < 0 )
- {
- if( op == '&' )
- bitwise_and( a, b, c );
- else if( op == '|' )
- bitwise_or( a, b, c );
- else if( op == '^' )
- bitwise_xor( a, b, c );
- else if( op == 'm' )
- min( a, b, c );
- else if( op == 'M' )
- max( a, b, c );
- else if( op == 'a' )
- absdiff( a, b, c );
- else
- assert(0);
- }
- else
- {
- Mat temp;
- apply(a, b, op, temp);
- temp.convertTo(c, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_BinS_
- {
- public:
- MatOp_BinS_() {}
- static void apply(const M& a, const Scalar& s, int _op, M& c, int type=-1)
- {
- char op = (char)_op;
- if( type == a.type() || type < 0 )
- {
- if( op == '&' )
- bitwise_and( a, s, c );
- else if( op == '|' )
- bitwise_or( a, s, c );
- else if( op == '^' )
- bitwise_xor( a, s, c );
- else if( op == 'm' )
- min( a, s[0], c );
- else if( op == 'M' )
- max( a, s[0], c );
- else if( op == 'a' )
- absdiff( a, s, c );
- else if( op == '~' )
- bitwise_not( a, c );
- else
- assert(0);
- }
- else
- {
- Mat temp;
- apply(a, s, op, temp);
- temp.convertTo(c, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_T_
- {
- public:
- MatOp_T_() {}
- static void apply(const M& a, double scale, M& c, int type=-1)
- {
- if( type == a.type() || type < 0 )
- {
- transpose(a, c);
- if( fabs(scale - 1) > DBL_EPSILON )
- c.convertTo(c, -1, scale, 0);
- }
- else
- {
- Mat temp;
- apply(a, scale, temp);
- temp.convertTo(c, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_MatMul_
- {
- public:
- MatOp_MatMul_() {}
- static void apply(const M& a, const M& b, double scale, int flags, M& c, int type=-1)
- {
- if( type == a.type() || type < 0 )
- {
- gemm(a, b, scale, Mat(), 0, c, flags);
- }
- else
- {
- Mat temp;
- apply(a, b, scale, flags, temp);
- temp.convertTo(c, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_MatMulAdd_
- {
- public:
- MatOp_MatMulAdd_() {}
- static void apply(const M& a, const M& b, double alpha,
- const M& c, double beta, int flags, M& d, int type=-1)
- {
- if( type == a.type() || type < 0 )
- {
- gemm(a, b, alpha, c, beta, d, flags);
- }
- else
- {
- Mat temp;
- apply(a, b, alpha, c, beta, flags, temp);
- temp.convertTo(d, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_Cmp_
- {
- public:
- MatOp_Cmp_() {}
- static void apply(const M& a, const M& b, int op, M& c, int type=-1)
- {
- if( type == CV_8UC1 || type == -1 )
- {
- compare(a, b, c, op);
- }
- else
- {
- Mat temp;
- apply(a, b, op, temp);
- temp.convertTo(c, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_CmpS_
- {
- public:
- MatOp_CmpS_() {}
- static void apply(const M& a, double alpha, int op, M& c, int type=-1)
- {
- if( type == CV_8UC1 || type == -1 )
- {
- compare(a, alpha, c, op);
- }
- else
- {
- Mat temp;
- apply(a, alpha, op, temp);
- temp.convertTo(c, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_MulDiv_
- {
- public:
- MatOp_MulDiv_() {}
- static void apply(const M& a, const M& b, double alpha, char op, M& c, int type=-1)
- {
- if( type == a.type() || type == -1 )
- {
- if( op == '*' )
- multiply( a, b, c, alpha );
- else
- divide( a, b, c, alpha );
- }
- else
- {
- Mat temp;
- apply(a, b, alpha, op, temp);
- temp.convertTo(c, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_DivRS_
- {
- public:
- MatOp_DivRS_() {}
- static void apply(const M& a, double alpha, M& c, int type=-1)
- {
- if( type == a.type() || type == -1 )
- {
- c.create(a.rows, a.cols, a.type());
- divide( alpha, a, c );
- }
- else
- {
- Mat temp;
- apply(a, alpha, temp);
- temp.convertTo(c, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_Inv_
- {
- public:
- MatOp_Inv_() {}
- static void apply(const M& a, int method, M& c, int type=-1)
- {
- if( type == a.type() || type == -1 )
- {
- invert(a, c, method);
- }
- else
- {
- Mat temp;
- apply(a, method, temp);
- temp.convertTo(c, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_Solve_
- {
- public:
- MatOp_Solve_() {}
- static void apply(const M& a, const M& b, int method, M& c, int type=-1)
- {
- if( type == a.type() || type == -1 )
- {
- solve(a, b, c, method);
- }
- else
- {
- Mat temp;
- apply(a, b, method, temp);
- temp.convertTo(c, type);
- }
- }
- };
- template<typename M> class CV_EXPORTS MatOp_Set_
- {
- public:
- MatOp_Set_() {}
- static void apply(Size size, int type0, const Scalar& s, int mtype, M& c, int type=-1)
- {
- if( type < 0 )
- type = type0;
- c.create(size.height, size.width, type);
- if( mtype == 0 )
- c = Scalar(0);
- else if( mtype == 1 )
- c = s;
- else if( mtype == 2 )
- setIdentity(c, s);
- }
- };
- template<typename A1, typename M, typename Op>
- class CV_EXPORTS MatExpr_Op1_
- {
- public:
- MatExpr_Op1_(const A1& _a1) : a1(_a1) {}
- void assignTo(Mat& m, int type=-1) const { Op::apply(a1, (M&)m, type); }
- operator M() const { M result; assignTo(result); return result; }
- A1 a1;
- };
- template<typename A1, typename A2, typename M, typename Op>
- class CV_EXPORTS MatExpr_Op2_
- {
- public:
- MatExpr_Op2_(const A1& _a1, const A2& _a2) : a1(_a1), a2(_a2) {}
- void assignTo(Mat& m, int type=-1) const { Op::apply(a1, a2, (M&)m, type); }
- operator M() const { M result; assignTo(result); return result; }
- A1 a1; A2 a2;
- };
- template<typename A1, typename A2, typename A3, typename M, typename Op>
- class CV_EXPORTS MatExpr_Op3_
- {
- public:
- MatExpr_Op3_(const A1& _a1, const A2& _a2, const A3& _a3) : a1(_a1), a2(_a2), a3(_a3) {}
- void assignTo(Mat& m, int type=-1) const { Op::apply(a1, a2, a3, (M&)m, type); }
- operator M() const { M result; assignTo(result); return result; }
- A1 a1; A2 a2; A3 a3;
- };
- template<typename A1, typename A2, typename A3, typename A4, typename M, typename Op>
- class CV_EXPORTS MatExpr_Op4_
- {
- public:
- MatExpr_Op4_(const A1& _a1, const A2& _a2, const A3& _a3, const A4& _a4)
- : a1(_a1), a2(_a2), a3(_a3), a4(_a4) {}
- void assignTo(Mat& m, int type=-1) const { Op::apply(a1, a2, a3, a4, (M&)m, type); }
- operator M() const { M result; assignTo(result); return result; }
- A1 a1; A2 a2; A3 a3; A4 a4;
- };
- template<typename A1, typename A2, typename A3, typename A4, typename A5, typename M, typename Op>
- class CV_EXPORTS MatExpr_Op5_
- {
- public:
- MatExpr_Op5_(const A1& _a1, const A2& _a2, const A3& _a3, const A4& _a4, const A5& _a5)
- : a1(_a1), a2(_a2), a3(_a3), a4(_a4), a5(_a5) {}
- void assignTo(Mat& m, int type=-1) const { Op::apply(a1, a2, a3, a4, a5, (M&)m, type); }
- operator M() const { M result; assignTo(result); return result; }
- A1 a1; A2 a2; A3 a3; A4 a4; A5 a5;
- };
- template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename M, typename Op>
- class CV_EXPORTS MatExpr_Op6_
- {
- public:
- MatExpr_Op6_(const A1& _a1, const A2& _a2, const A3& _a3,
- const A4& _a4, const A5& _a5, const A6& _a6)
- : a1(_a1), a2(_a2), a3(_a3), a4(_a4), a5(_a5), a6(_a6) {}
- void assignTo(Mat& m, int type=-1) const { Op::apply(a1, a2, a3, a4, a5, a6, (M&)m, type); }
- operator M() const { M result; assignTo(result); return result; }
- A1 a1; A2 a2; A3 a3; A4 a4; A5 a5; A6 a6;
- };
- ///////////////////////////////// Arithmetical Operations ///////////////////////////////////
- // A + B
- static inline MatExpr_<MatExpr_Op5_<Mat, double, Mat, double, double, Mat, MatOp_AddEx_<Mat> >, Mat>
- operator + (const Mat& a, const Mat& b)
- {
- typedef MatExpr_Op5_<Mat, double, Mat, double, double, Mat, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, 1, b, 1, 0));
- }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op5_<Mat_<_Tp>, double, Mat_<_Tp>,
- double, double, Mat_<_Tp>, MatOp_AddEx_<Mat> >, Mat_<_Tp> >
- operator + (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- typedef MatExpr_Op5_<Mat_<_Tp>, double, Mat_<_Tp>, double, double, Mat_<_Tp>, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(a, 1, b, 1, 0));
- }
- // E1 + E2
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<M, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const MatExpr_<A, M>& a, const MatExpr_<B, M>& b )
- {
- typedef MatExpr_Op5_<M, double, M, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a, 1, (M)b, 1, 0));
- }
- // A - B
- static inline MatExpr_<MatExpr_Op2_<Mat, Mat, Mat, MatOp_Sub_<Mat> >, Mat>
- operator - (const Mat& a, const Mat& b)
- {
- typedef MatExpr_Op2_<Mat, Mat, Mat, MatOp_Sub_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, b));
- }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op2_<Mat_<_Tp>, Mat_<_Tp>, Mat_<_Tp>, MatOp_Sub_<Mat> >, Mat_<_Tp> >
- operator - (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- typedef MatExpr_Op2_<Mat_<_Tp>, Mat_<_Tp>, Mat_<_Tp>, MatOp_Sub_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(a, b));
- }
- // E1 - E2
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op2_<M, M, M, MatOp_Sub_<Mat> >, M>
- operator - (const MatExpr_<A, M>& a, const MatExpr_<B, M>& b )
- {
- typedef MatExpr_Op2_<M, M, M, MatOp_Sub_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a, (M)b));
- }
- // -(E1 - E2)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op2_<B, A, M, MatOp_Sub_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op2_<A, B, M, MatOp_Sub_<Mat> >, M>& a )
- {
- typedef MatExpr_Op2_<B, A, M, MatOp_Sub_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a2, a.e.a1));
- }
- // (A - B)*alpha
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator * (const MatExpr_<MatExpr_Op2_<A, B, M, MatOp_Sub_<Mat> >, M>& a,
- double alpha)
- {
- typedef MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, alpha, a.e.a2, -alpha, 0));
- }
- // alpha*(A - B)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator * (double alpha,
- const MatExpr_<MatExpr_Op2_<A, B, M, MatOp_Sub_<Mat> >, M>& a)
- { return a*alpha; }
- // A*alpha
- static inline
- MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_Scale_<Mat> >, Mat>
- operator * (const Mat& a, double alpha)
- {
- typedef MatExpr_Op2_<Mat, double, Mat, MatOp_Scale_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, alpha));
- }
- // A*alpha
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op2_<Mat_<_Tp>, double, Mat_<_Tp>, MatOp_Scale_<Mat> >, Mat_<_Tp> >
- operator * (const Mat_<_Tp>& a, double alpha)
- {
- typedef MatExpr_Op2_<Mat_<_Tp>, double, Mat_<_Tp>, MatOp_Scale_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(a, alpha));
- }
- // alpha*A
- static inline
- MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_Scale_<Mat> >, Mat>
- operator * (double alpha, const Mat& a)
- { return a*alpha; }
- // alpha*A
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op2_<Mat_<_Tp>, double, Mat_<_Tp>, MatOp_Scale_<Mat> >, Mat_<_Tp> >
- operator * (double alpha, const Mat_<_Tp>& a)
- { return a*alpha; }
- // A/alpha
- static inline
- MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_Scale_<Mat> >, Mat>
- operator / (const Mat& a, double alpha)
- { return a*(1./alpha); }
- // A/alpha
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op2_<Mat_<_Tp>, double, Mat_<_Tp>, MatOp_Scale_<Mat> >, Mat_<_Tp> >
- operator / (const Mat_<_Tp>& a, double alpha)
- { return a*(1./alpha); }
- // -A
- static inline
- MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_Scale_<Mat> >, Mat>
- operator - (const Mat& a)
- { return a*(-1); }
- // -A
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op2_<Mat_<_Tp>, double, Mat_<_Tp>, MatOp_Scale_<Mat> >, Mat_<_Tp> >
- operator - (const Mat_<_Tp>& a)
- { return a*(-1); }
- // E*alpha
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<M, double, M, MatOp_Scale_<Mat> >, M>
- operator * (const MatExpr_<A, M>& a, double alpha)
- {
- typedef MatExpr_Op2_<M, double, M, MatOp_Scale_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a, alpha));
- }
- // alpha*E
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<M, double, M, MatOp_Scale_<Mat> >, M>
- operator * (double alpha, const MatExpr_<A, M>& a)
- { return a*alpha; }
- // E/alpha
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<M, double, M, MatOp_Scale_<Mat> >, M>
- operator / (const MatExpr_<A, M>& a, double alpha)
- { return a*(1./alpha); }
- // (E*alpha)*beta ~ E*(alpha*beta)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>
- operator * (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- double beta)
- { return a.e.a1*(a.e.a2*beta); }
- // beta*(E*alpha) ~ E*(alpha*beta)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>
- operator * (double beta,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a)
- { return a.e.a1*(a.e.a2*beta); }
- // (E*alpha)/beta ~ E*(alpha/beta)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>
- operator / (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- double beta)
- { return a.e.a1*(a.e.a2/beta); }
- // -E ~ E*(-1)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<MatExpr_<A, M>, double, M, MatOp_Scale_<Mat> >, M>
- operator - (const MatExpr_<A, M>& a)
- { return a*(-1); }
- // -(E*alpha) ~ E*(-alpha)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a)
- { return a.e.a1*(-a.e.a2); }
- // A + alpha
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, double, double, Mat_<_Tp>, MatOp_ScaleAddS_<Mat> >, Mat_<_Tp> >
- operator + (const Mat_<_Tp>& a, double alpha)
- {
- typedef MatExpr_Op3_<Mat_<_Tp>, double, double, Mat_<_Tp>,
- MatOp_ScaleAddS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(a, 1, alpha));
- }
- // A + alpha
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op2_<Mat_<_Tp>, Scalar, Mat_<_Tp>, MatOp_AddS_<Mat> >, Mat_<_Tp> >
- operator + (const Mat_<_Tp>& a, const Scalar& alpha)
- {
- typedef MatExpr_Op2_<Mat_<_Tp>, Scalar, Mat_<_Tp>,
- MatOp_AddS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(a, alpha));
- }
- // alpha + A
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, double, double, Mat_<_Tp>, MatOp_ScaleAddS_<Mat> >, Mat_<_Tp> >
- operator + (double alpha, const Mat_<_Tp>& a)
- { return a + alpha; }
- // alpha + A
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op2_<Mat_<_Tp>, Scalar, Mat_<_Tp>, MatOp_AddS_<Mat> >, Mat_<_Tp> >
- operator + (const Scalar& alpha, const Mat_<_Tp>& a)
- { return a + alpha; }
- // A - alpha
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, double, double, Mat_<_Tp>, MatOp_ScaleAddS_<Mat> >, Mat_<_Tp> >
- operator - (const Mat_<_Tp>& a, double alpha)
- { return a + (-alpha); }
- // A - alpha
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op2_<Mat_<_Tp>, Scalar, Mat_<_Tp>, MatOp_AddS_<Mat> >, Mat_<_Tp> >
- operator - (const Mat_<_Tp>& a, const Scalar& alpha)
- { return a + (-alpha); }
- // alpha - A
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, double, double, Mat_<_Tp>, MatOp_ScaleAddS_<Mat> >, Mat_<_Tp> >
- operator - (double alpha, const Mat_<_Tp>& a)
- {
- typedef MatExpr_Op3_<Mat_<_Tp>, double, double, Mat_<_Tp>,
- MatOp_ScaleAddS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(a, -1, alpha));
- }
- // E + alpha
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator + (const MatExpr_<A, M>& a, double alpha)
- {
- typedef MatExpr_Op3_<M, double, double, M, MatOp_ScaleAddS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a, 1, alpha));
- }
- // E + alpha
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<M, Scalar, M, MatOp_AddS_<Mat> >, M>
- operator + (const MatExpr_<A, M>& a, const Scalar& alpha)
- {
- typedef MatExpr_Op2_<M, Scalar, M, MatOp_AddS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a, alpha));
- }
- // alpha + E
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator + (double alpha, const MatExpr_<A, M>& a)
- { return a + alpha; }
- // alpha + E
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<M, Scalar, M, MatOp_AddS_<Mat> >, M>
- operator + (const Scalar& alpha, const MatExpr_<A, M>& a)
- { return a + alpha; }
- // E - alpha
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator - (const MatExpr_<A, M>& a, double alpha)
- { return a + (-alpha); }
- // E - alpha
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<M, Scalar, M, MatOp_AddS_<Mat> >, M>
- operator - (const MatExpr_<A, M>& a, const Scalar& alpha)
- { return a + (-alpha); }
- // alpha - E
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator - (double alpha, const MatExpr_<A, M>& a)
- {
- typedef MatExpr_Op3_<M, double, double, M, MatOp_ScaleAddS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a, -1, alpha));
- }
- // E*alpha + beta
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator + (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- double beta)
- {
- typedef MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, beta));
- }
- // beta + E*alpha
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator + (double beta,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a)
- { return a + beta; }
- // E*alpha - beta
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- double beta)
- { return a + (-beta); }
- // beta - E*alpha
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator - (double beta,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a)
- { return (a.e.a1*(-a.e.a2)) + beta; }
- // (E*alpha + gamma) + beta ~ E*alpha + (gamma + beta)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator + (const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a,
- double beta)
- { return a.e.a1*a.e.a2 + (a.e.a3 + beta); }
- // beta + (E*alpha + gamma)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator + (double beta, const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a)
- { return a + beta; }
- // (E*alpha + gamma) - beta
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a,
- double beta)
- { return a + (-beta); }
- // beta - (E*alpha + gamma)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator - (double beta, const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a)
- { return a.e.a1*(-a.e.a2) + (beta - a.e.a3); }
- // (E*alpha + gamma)*beta
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator * (const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a,
- double beta)
- { return a.e.a1*(a.e.a2*beta) + (a.e.a3*beta); }
- // beta*(E*alpha + gamma)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator * (double beta, const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a)
- { return a*beta; }
- // -(E*alpha + beta)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a)
- { return a*(-1); }
- // (A*u + B*v + w) + beta
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>& a,
- double beta )
- {
- typedef MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, a.e.a3, a.e.a4, a.e.a5 + beta));
- }
- // beta + (A*u + B*v + w)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (double beta,
- const MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>& a)
- { return a + beta; }
- // (A*u + B*v + w) - beta
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>& a,
- double beta)
- { return a + (-beta); }
- // beta - (A*u + B*v + w)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (double beta,
- const MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>& a)
- {
- typedef MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, -a.e.a2, a.e.a3, -a.e.a4, -a.e.a5 + beta));
- }
- // (A*u + B*v + w)*beta
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator * (const MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>& a,
- double beta )
- {
- typedef MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1,
- a.e.a2*beta, a.e.a3, a.e.a4*beta, a.e.a5*beta));
- }
- // beta*(A*u + B*v + w)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator * (double beta,
- const MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>& a)
- { return a * beta; }
- // -(A*u + B*v + w)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>& a)
- { return a*(-1); }
- // A*alpha + B
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- const M& b )
- {
- typedef MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, b, 1, 0));
- }
- // B + A*alpha
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const M& b,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a)
- { return a + b; }
- // (A*alpha + beta) + B
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a,
- const M& b )
- {
- typedef MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, b, 1, a.e.a3));
- }
- // B + (A*alpha + beta)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const M& b,
- const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a)
- { return a + b; }
- // A*alpha + E
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- const MatExpr_<B, M>& b )
- { return a + (M)b; }
- // E + A*alpha
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const MatExpr_<B, M>& b,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a)
- { return a + (M)b; }
- // (A*alpha + beta) + E
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a,
- const MatExpr_<B, M>& b )
- { return a + (M)b; }
- // E + (A*alpha + beta)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const MatExpr_<B, M>& b,
- const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a)
- { return a + b; }
- // A*alpha + B*beta
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_Scale_<Mat> >, M>& b )
- {
- typedef MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, b.e.a1, b.e.a2, 0));
- }
- // (A*alpha + beta) + B*gamma
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_Scale_<Mat> >, M>& b )
- {
- typedef MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, b.e.a1, b.e.a2, a.e.a3));
- }
- // B*gamma + (A*alpha + beta)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& b,
- const MatExpr_<MatExpr_Op3_<B, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a )
- { return a + b; }
- // (A*alpha + beta) + (B*gamma + theta)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator + (const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op3_<B, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& b )
- {
- typedef MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, b.e.a1, b.e.a2, a.e.a3 + b.e.a3));
- }
- // A*alpha - B
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- const M& b )
- {
- typedef MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, b, -1, 0));
- }
- // B - A*alpha
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const M& b,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a)
- {
- typedef MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, -a.e.a2, b, 1, 0));
- }
- // (A*alpha + beta) - B
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a,
- const M& b )
- {
- typedef MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, b, -1, a.e.a3));
- }
- // B - (A*alpha + beta)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const M& b,
- const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a)
- {
- typedef MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, b, -1, a.e.a3));
- }
- // A*alpha - E
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- const MatExpr_<B, M>& b )
- { return a - (M)b; }
- // E - A*alpha
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const MatExpr_<B, M>& b,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a)
- { return (M)b - a; }
- // (A*alpha + beta) - E
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a,
- const MatExpr_<B, M>& b )
- { return a - (M)b; }
- // E - (A*alpha + beta)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, M, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const MatExpr_<B, M>& b,
- const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a)
- { return (M)b - a; }
- // A*alpha - B*beta
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_Scale_<Mat> >, M>& b )
- {
- typedef MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, b.e.a1, -b.e.a2, 0));
- }
- // (A*alpha + beta) - B*gamma
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_Scale_<Mat> >, M>& b )
- {
- typedef MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, b.e.a1, -b.e.a2, a.e.a3));
- }
- // B*gamma - (A*alpha + beta)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& b,
- const MatExpr_<MatExpr_Op3_<B, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a )
- {
- typedef MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, -a.e.a2, b.e.a1, b.e.a2, -a.e.a3));
- }
- // (A*alpha + beta) - (B*gamma + theta)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> >, M>
- operator - (const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op3_<B, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& b )
- {
- typedef MatExpr_Op5_<A, double, B, double, double, M, MatOp_AddEx_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, b.e.a1, -b.e.a2, a.e.a3 - b.e.a3));
- }
- /////////////////////////////// Mat Multiplication ///////////////////////////////////
- // A^t
- inline MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_T_<Mat> >, Mat>
- Mat::t() const
- {
- typedef MatExpr_Op2_<Mat, double, Mat, MatOp_T_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(*this, 1));
- }
- template<typename _Tp> inline
- MatExpr_<MatExpr_Op2_<Mat_<_Tp>, double, Mat_<_Tp>, MatOp_T_<Mat> >, Mat_<_Tp> >
- Mat_<_Tp>::t() const
- {
- typedef MatExpr_Op2_<Mat_<_Tp>, double, Mat_<_Tp>, MatOp_T_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(*this, 1));
- }
- // A*B
- static inline
- MatExpr_<MatExpr_Op4_<Mat, Mat, double, int, Mat, MatOp_MatMul_<Mat> >, Mat>
- operator * ( const Mat& a, const Mat& b )
- {
- typedef MatExpr_Op4_<Mat, Mat, double, int, Mat, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, b, 1, 0));
- }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op4_<Mat_<_Tp>, Mat_<_Tp>, double, int, Mat_<_Tp>,
- MatOp_MatMul_<Mat> >, Mat_<_Tp> >
- operator * ( const Mat_<_Tp>& a, const Mat_<_Tp>& b )
- {
- typedef MatExpr_Op4_<Mat_<_Tp>, Mat_<_Tp>, double, int, Mat_<_Tp>,
- MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(a, b, 1, 0));
- }
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> >, M>
- operator * ( const MatExpr_<A, M>& a, const MatExpr_<B, M>& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a, (M)b, 1, 0));
- }
- // (A*alpha)*B
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> >, M>
- operator * ( const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a, const M& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1, b, a.e.a2, 0));
- }
- // A*(B*alpha)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> >, M>
- operator * ( const M& b, const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(b, (M)a.e.a1, a.e.a2, 0));
- }
- // A^t*B
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> >, M>
- operator * ( const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_T_<Mat> >, M>& a, const M& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1, b, a.e.a2, GEMM_1_T));
- }
- // A*B^t
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> >, M>
- operator * ( const M& a, const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_T_<Mat> >, M>& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a, (M)b.e.a1, b.e.a2, GEMM_2_T));
- }
- // (A*alpha)*(B*beta)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> >, M>
- operator * ( const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_Scale_<Mat> >, M>& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1, (M)b.e.a1, a.e.a2*b.e.a2, 0));
- }
- // A^t*(B*alpha)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> >, M>
- operator * ( const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_T_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_Scale_<Mat> >, M>& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1, (M)b.e.a1, a.e.a2*b.e.a2, GEMM_1_T));
- }
- // (A*alpha)*B^t
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> >, M>
- operator * ( const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_T_<Mat> >, M>& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1, (M)b.e.a1, a.e.a2*b.e.a2, GEMM_2_T));
- }
- // A^t*B^t
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> >, M>
- operator * ( const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_T_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_T_<Mat> >, M>& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1,
- (M)b.e.a1, a.e.a2*b.e.a2, GEMM_1_T+GEMM_2_T));
- }
- // (A*B)*alpha
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>
- operator * ( const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a,
- double alpha )
- {
- typedef MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2, a.e.a3*alpha, a.e.a4));
- }
- // alpha*(A*B)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> >, M>
- operator * ( double alpha,
- const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a )
- {
- return a*alpha;
- }
- // -(A*B)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>
- operator - ( const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a )
- {
- return a*(-1);
- }
- // (A*alpha + beta)*B
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator * ( const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_ScaleAddS_<Mat> >, M>& a, const M& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1, b, a.e.a2, b, a.e.a3, 0));
- }
- // A*(B*alpha + beta)
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator * ( const M& a, const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_ScaleAddS_<Mat> >, M>& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a, (M)b.e.a1, b.e.a2, a, b.e.a3, 0));
- }
- // (A*alpha + beta)*(B*gamma)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator * ( const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_ScaleAddS_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_Scale_<Mat> >, M>& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1, (M)b.e.a1,
- a.e.a2*b.e.a2, (M)b.e.a1, a.e.a3*b.e.a2, 0));
- }
- // (A*gamma)*(B*alpha + beta)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator * ( const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_Scale_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_ScaleAddS_<Mat> >, M>& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1, (M)b.e.a1,
- a.e.a2*b.e.a2, (M)a.e.a1, a.e.a2*b.e.a3, 0));
- }
- // (A*alpha + beta)*B^t
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator * ( const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_ScaleAddS_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_T_<Mat> >, M>& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1, (M)b.e.a1,
- a.e.a2*b.e.a2, (M)b.e.a1, a.e.a3*b.e.a2, GEMM_2_T));
- }
- // A^t*(B*alpha + beta)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator * ( const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_T_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_ScaleAddS_<Mat> >, M>& b )
- {
- typedef MatExpr_Op4_<M, M, double, int, M, MatOp_MatMul_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1, (M)b.e.a1,
- a.e.a2*b.e.a2, (M)a.e.a1, a.e.a2*b.e.a3, GEMM_1_T));
- }
- // (A*B + C)*alpha
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<A, B, double, C, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator * ( const MatExpr_<MatExpr_Op6_<A, B, double, C,
- double, int, M, MatOp_MatMulAdd_<Mat> >, M>& a, double alpha )
- {
- typedef MatExpr_Op6_<A, B, double, C, double, int, M, MatOp_MatMulAdd_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(a.e.a1, a.e.a2,
- a.e.a3*alpha, a.e.a4, a.e.a5*alpha, a.e.a6));
- }
- // alpha*(A*B + C)
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<A, B, double, C, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator * ( double alpha, const MatExpr_<MatExpr_Op6_<A, B, double, C,
- double, int, M, MatOp_MatMulAdd_<Mat> >, M>& a )
- { return a*alpha; }
- // -(A*B + C)
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<A, B, double, C, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator - ( const MatExpr_<MatExpr_Op6_<A, B, double, C,
- double, int, M, MatOp_MatMulAdd_<Mat> >, M>& a )
- { return a*(-1); }
- // (A*B) + C
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator + ( const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a,
- const M& b )
- {
- typedef MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(
- (M)a.e.a1, (M)a.e.a2, a.e.a3, b, 1, a.e.a4));
- }
- // C + (A*B)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator + ( const M& b,
- const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a )
- { return a + b; }
- // (A*B) - C
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator - ( const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a,
- const M& b )
- {
- typedef MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(
- (M)a.e.a1, (M)a.e.a2, a.e.a3, b, -1, a.e.a4));
- }
- // C - (A*B)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator - ( const M& b,
- const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a )
- {
- typedef MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(
- (M)a.e.a1, (M)a.e.a2, -a.e.a3, b, 1, a.e.a4));
- }
- // (A*B) + C
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator + ( const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a,
- const MatExpr_<C, M>& b )
- {
- typedef MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(
- (M)a.e.a1, (M)a.e.a2, a.e.a3, (M)b, 1, a.e.a4));
- }
- // C + (A*B)
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator + ( const MatExpr_<C, M>& b,
- const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a )
- { return a + b; }
- // (A*B) - C
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator - ( const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a,
- const MatExpr_<C, M>& b )
- {
- typedef MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(
- (M)a.e.a1, (M)a.e.a2, a.e.a3, (M)b, -1, a.e.a4));
- }
- // C - (A*B)
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator - ( const MatExpr_<C, M>& b,
- const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a )
- {
- typedef MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(
- (M)a.e.a1, (M)a.e.a2, -a.e.a3, (M)b, 1, a.e.a4));
- }
- // (A*B) + C*alpha
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator + ( const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<C, double, M, MatOp_Scale_<Mat> >, M>& b )
- {
- typedef MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(
- (M)a.e.a1, (M)a.e.a2, a.e.a3, (M)b.e.a1, b.e.a2, a.e.a4));
- }
- // C*alpha + (A*B)
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator + ( const MatExpr_<MatExpr_Op2_<C, double, M, MatOp_Scale_<Mat> >, M>& b,
- const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a )
- { return a + b; }
- // (A*B) - (C*alpha)
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator - ( const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<C, double, M, MatOp_Scale_<Mat> >, M>& b )
- {
- typedef MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(
- (M)a.e.a1, (M)a.e.a2, a.e.a3, (M)b.e.a1, -b.e.a2, a.e.a4));
- }
- // (C*alpha) - (A*B)
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator - ( const MatExpr_<MatExpr_Op2_<C, double, M, MatOp_Scale_<Mat> >, M>& b,
- const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a )
- {
- typedef MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(
- (M)a.e.a1, (M)a.e.a2, -a.e.a3, (M)b.e.a1, b.e.a2, a.e.a4));
- }
- // (A*B) + C^t
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator + ( const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<C, double, M, MatOp_T_<Mat> >, M>& b )
- {
- typedef MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(
- (M)a.e.a1, (M)a.e.a2, a.e.a3, (M)b.e.a1, b.e.a2, a.e.a4 + GEMM_3_T));
- }
- // C^t + (A*B)
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator + ( const MatExpr_<MatExpr_Op2_<C, double, M, MatOp_T_<Mat> >, M>& b,
- const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a )
- { return a + b; }
- // (A*B) - C^t
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator - ( const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<C, double, M, MatOp_T_<Mat> >, M>& b )
- {
- typedef MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(
- (M)a.e.a1, (M)a.e.a2, a.e.a3, (M)b.e.a1, -b.e.a2, a.e.a4+GEMM_3_T));
- }
- // C^t - (A*B)
- template<typename A, typename B, typename C, typename M> static inline
- MatExpr_<MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> >, M>
- operator - ( const MatExpr_<MatExpr_Op2_<C, double, M, MatOp_T_<Mat> >, M>& b,
- const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& a )
- {
- typedef MatExpr_Op6_<M, M, double, M, double, int, M, MatOp_MatMulAdd_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp(
- (M)a.e.a1, (M)a.e.a2, -a.e.a3, (M)b.e.a1, b.e.a2, a.e.a4+GEMM_3_T));
- }
- ////////////////////////////// Augmenting algebraic operations //////////////////////////////////
- static inline Mat& operator += (const Mat& a, const Mat& b)
- {
- add(a, b, (Mat&)a);
- return (Mat&)a;
- }
- static inline Mat& operator -= (const Mat& a, const Mat& b)
- {
- subtract(a, b, (Mat&)a);
- return (Mat&)a;
- }
- static inline Mat& operator *= (const Mat& a, const Mat& b)
- {
- gemm(a, b, 1, Mat(), 0, (Mat&)a, 0);
- return (Mat&)a;