matrixfun.hpp

来自「简单的C++计算库.其中实现了矩阵运算,大数运算.矩阵处理中使用lazy cal」· HPP 代码 · 共 99 行

HPP
99
字号
#ifndef		_SDL_MATHS_MATRIX_MATRIX_FUN_HPP_
#define		_SDL_MATHS_MATRIX_MATRIX_FUN_HPP_

#ifndef		_SDL_MATHS_MATRIX_MATRIX_HPP_
#error		"must be included by Matrix.hpp"
#endif

SDL_MATHS_MATRIX_BEGIN

/*
*
*	Matrix	transpose
*
*/

template<typename _MatType>
inline
BasicMatrixExpr<TranMatrixExpr<_MatType> >
Tran(const _MatType& _l)
{
	typedef	TranMatrixExpr<_MatType> ContainedMatType;
	return BasicMatrixExpr<ContainedMatType>(ContainedMatType(_l));
}

/*
*
*	Matrix	abs
*
*/

template<typename _MatType>
inline
BasicMatrixExpr<AbsMatrixExpr<_MatType> >
Abs(const _MatType& _l)
{
	typedef	AbsMatrixExpr<_MatType> ContainedMatType;
	return BasicMatrixExpr<ContainedMatType>(ContainedMatType(_l));
}

/*
*
*	Maximum	element
*
*/

template<typename _MatType>
inline
typename _MatType::NumberType
Max(const _MatType& _Mat)
{
	typedef	typename _MatType::NumberType NumberType;

	NumberType	result = _Mat(MIDX(1), MIDX(1));

	for (int i = MIDX(1); i <= MIDX(_Mat.row()); ++i)
	for (int j = MIDX(1); j <= MIDX(_Mat.col()); ++j)
	{
		NumberType t = _Mat(i, j);
		if (t > result)
		{
			result = t;
		}
	}

	return result;
}

/*
*
*	Minimum	element
*
*/

template<typename _MatType>
inline
typename _MatType::NumberType
Min(const _MatType& _Mat)
{
	typedef	typename _MatType::NumberType NumberType;

	NumberType	result = _Mat(MIDX(1), MIDX(1));

	for (int i = MIDX(1); i <= MIDX(_Mat.row()); ++i)
	for (int j = MIDX(1); j <= MIDX(_Mat.col()); ++j)
	{
		NumberType t = _Mat(i, j);
		if (t < result)
		{
			result = t;
		}
	}

	return result;
}

SDL_MATHS_MATRIX_END

#endif

⌨️ 快捷键说明

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