⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xxvector

📁 矩阵计算的c++代码
💻
字号:
// xxVector internal header
#pragma once
#ifndef _XXVECTOR_
#define _XXVECTOR_

//	additional friend operations of vector
//+++++++++++++++++++++++++++++++++++++++++++++++
const CVector operator+(const CVector& left, __VectorType__ right)
{
	CVector _result(left);
	_result += right;
	return _result;
}
const CVector operator+(__VectorType__ left, const CVector& right)
{	return right + left;	}
const CVector operator+(const CVector& left, const CVector& right)
{
	CVector _result(left);
	_result += right;
	return _result;
}

//-----------------------------------------------
const CVector operator-(const CVector& left, __VectorType__ right)
{
	CVector _result(left);
	_result -= right;
	return _result;
}
const CVector operator-(__VectorType__ left, const CVector& right)
{	return (-right) + left;	}
const CVector operator-(const CVector& left, const CVector& right)
{
	CVector _result(left);
	_result -= right;
	return _result;
}

//***********************************************
const CVector operator*(const CVector& left, __VectorType__ right)
{
	CVector _result(left);
	_result *= right;
	return _result;
}
const CVector operator*(__VectorType__ left, const CVector& right)
{	return right * left;	}
const CVector operator*(const CVector& left, const CVector& right)
{
	assert(left.size() == right.size());
	if(left.IsEmpty())	return CVector();

	CVector _result(left);

	for(int i=0; i<right.size(); ++i)
	{	_result[i] *= right[i];	}
	return _result;
}

/////////////////////////////////////////////////
const CVector operator/(const CVector& left, __VectorType__ right)
{
	CVector _result(left);
	_result /= right;
	return _result;
}
const CVector operator/(__VectorType__ left, const CVector& right)
{
	CVector _result(right.size());

	for(int i=0; i<right.size(); ++i)
	{
		assert( right[i]!=0.0 );
		_result[i] = left / right[i];
	}
	return _result;
}
const CVector operator/(const CVector& left, const CVector& right)
{
	assert(left.size() == right.size());
	if(left.IsEmpty())	return CVector();

	CVector _result(left);

	for(int i=0; i<right.size(); ++i)
	{
		assert( right[i] != 0.0 );
		_result[i] /= right[i];
	}
	return _result;
}

const CVector abs(const CVector& src)
{
	if(src.IsEmpty())
	{	return CVector();	}

	int i, _M = src.size();
	CVector _result(_M);

	for(i=0; i<_M; ++i)
	{	_result[i] = std::fabs(src.At(i));	}
	return _result;
}
const CVector sqrt(const CVector& src)
{
	if(src.IsEmpty())
	{	return CVector();	}

	int i, _M = src.size();
	CVector _result(_M);

	for(i=0; i<_M; ++i)
	{
		assert( !(src[i]<0.0) );
		_result[i] = std::sqrt(src.At(i));
	}
	return _result;
}

//	check whether the both matrices equal
bool operator == (const CVector& left, const CVector& right)
{
	int i, _M, _N;
	_M = left.size();	_N = left.size();

	if( _M != _N )		return false;
	if(left.IsEmpty())	return true;
	if(&left == &right)	return true;	// 检查是否是自己

	for(i=0; i<_M; ++i)
	{	if(left[i] != right[i])	return false;	}

	return true;
}
bool operator != (const CVector& left, const CVector& right)
{	return !(left == right);	}

#endif // _XXVECTOR_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -