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

📄 cdiag.cpp

📁 face recognition test source code
💻 CPP
字号:
#include "stdafx.h"

#include "utilcpp.h"

#include "CDiag.h"

CDiag::CDiag() : CVect()
	{
	}

CDiag::CDiag(long l) : CVect(l)
	{
	}

CDiag::~CDiag()
	{
	if (pMem != NULL)
		{
		delete pMem;
		pMem = NULL;
		}
	}

void CDiag::Inverse()
	{
	long i, r = GetLi();
	valtype val;
	
	Lock();
	
	for (i = 1; i <= r; i++)
		{
		val = GetAt(i);
		if (val != 0)
			{
			SetAt(i, 1/val);
			}
		}
	
	Unlock();
	}

void CDiag::Pow(float exp)
	{
	CVect::PowCmp(exp);
	}

/***********************************************************************
* Multiply pMat1 by pMat2, and put the result in this matrix. However the multiplication
* is not a normal one, the result is computed only on the diagonal, that's why it is
* stored in a diagonal matrix
*
* The dimension of the matrices must be the same
***********************************************************************/
void CDiag::Multiply(CMatrix *pMat1, CMatrix *pMat2)
	{
 	long l, r, llen, k;
 	valtype val;
 
 	if (li == 0)
 		{                                      				/*the matrix was not initialised*/
 		li = pMat1->GetLi();
 		Allocate();
 		}
 	else
 		{													/*Verify that the matrices have the right dimension*/
 		if (pMat2->GetCol() != li || pMat1->GetLi() != li)
 			Fail(NULL);
 		}
	
	if (pMat1->GetCol() != pMat2->GetLi())
		Fail(0);
	 
 	r = pMat2->GetLi();
 	llen = GetLi();
 		
 	Lock();
 	pMat2->Lock();
 	pMat1->Lock();
 
 	for (l = 1L; l <= llen; l++)
 		{
		val = (valtype)0;
 		for (k = 1L; k <= r; k++)
 			{
 			val += pMat1->GetAt(l, k)*pMat2->GetAt(k, l);
 			}
 		SetAt(l, val);
 		}
 	
 	Unlock();
 	pMat2->Unlock();
 	pMat1->Unlock();
 	}
 
long CDiag::GetCol()
	{
	return li;
	}

⌨️ 快捷键说明

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