亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? matrix.cpp

?? 用于聲音圖像的FFC變換源碼
?? CPP
?? 第 1 頁 / 共 3 頁
字號:
// Matrix.cpp: implementation of the CMatrix class.
//
//
//
// Coding and Memory analysis by Aris
// Please do not remove this header
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Matrix.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction CMatrix
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SERIAL(CMatrix, CObject, 1) ;

#ifdef _DEBUG
int CMatrix::m_NextObjectNumber = 1 ;
#endif

CMatrix::CMatrix()
{
#ifdef _DEBUG
	// so we can regonise each individual object
	m_ObjectNumber = m_NextObjectNumber++ ;
	TRACE("Creating CMatrix object %1d - default constructor\n", m_ObjectNumber) ;
#endif
	// default constructor, create a 1 * 1 array
	m_NumColumns = 1 ;
	m_NumRows = 1 ;
	m_pData = NULL ;
	m_pData = AllocateMemory(m_NumColumns, m_NumRows) ;
	IncrementReferenceCount() ;			// count the reference to this memory
}

CMatrix::CMatrix(const CMatrix &other)
{
#ifdef _DEBUG
	// so we can regonise each individual object
	m_ObjectNumber = m_NextObjectNumber++ ;
	TRACE("Creating CMatrix object %1d - copy constructor other = %1d\n", m_ObjectNumber, other.m_ObjectNumber) ;
#endif
	// copy constructor
	m_pData = NULL ;
	// use the other objects data pointer
	m_NumColumns = other.m_NumColumns ;
	m_NumRows = other.m_NumRows ;
	m_pData = other.m_pData ;				// copy the pointer
	IncrementReferenceCount() ;				// this thread can get the mutex multiple times without blocking
}

CMatrix::CMatrix(int nCols, int nRows)
{
#ifdef _DEBUG
	// so we can regonise each individual object
	m_ObjectNumber = m_NextObjectNumber++ ;
	TRACE("Creating CMatrix object %1d - size constructor\n", m_ObjectNumber) ;
#endif
	// size constructor
	ASSERT(nCols > 0) ;					// matrix size error
	ASSERT(nRows > 0) ;					// matrix size error
	m_pData = NULL ;
	m_NumColumns = nCols ;
	m_NumRows = nRows ;
	m_pData = AllocateMemory(m_NumColumns, m_NumRows) ;
	IncrementReferenceCount() ;				// count the reference to this memory
}

CMatrix::CMatrix(int size, bool set_diagonal)
{
	// construct a square matrix with 1.0's on the diagonal if required
#ifdef _DEBUG
	// so we can regonise each individual object
	m_ObjectNumber = m_NextObjectNumber++ ;
	TRACE("Creating CMatrix object %1d - square size constructor\n", m_ObjectNumber) ;
#endif
	// size constructor
	ASSERT(size > 0) ;						// matrix size error
	m_pData = NULL ;
	m_NumColumns = size ;
	m_NumRows = size ;
	m_pData = AllocateMemory(m_NumColumns, m_NumRows) ;
	IncrementReferenceCount() ;				// count the reference to this memory
	// set the dialognal if required
	if (set_diagonal)
		{
		for (int i = 0 ; i < size ; ++i)
			SetElement(i, i, 1.0) ;
		}
}

// creates a CMatrix object from a SafeArray that contains a 2D matrix
// Note that you will probably have to call "VariantClear" to correctly de-allocate
// the safe array you have once you have finished with it.
CMatrix::CMatrix(VARIANT& var)
{
	if ((var.vt & VT_ARRAY) == 0)
		throw "Not a SafeArray" ;
	if ((var.vt & VT_R8) == 0)
		throw "Not a double SafeArray" ;

	SAFEARRAY*		psa = var.parray ;	// get a pointer to the safe array
	if (psa->cDims != 2)
		throw "SafeArray, incorrect number of dimensions" ;

	long			lBound1, lBound2 ;
	long			uBound1, uBound2 ;
	HRESULT			hr ;

	// get the bounds of the matrix in the safe array
	hr = SafeArrayGetLBound(psa, 1, &lBound1);
	if (FAILED(hr))
		throw "SafeArray access error" ;
	hr = SafeArrayGetUBound(psa, 1, &uBound1);
	if (FAILED(hr))
		throw "SafeArray access error" ;

	hr = SafeArrayGetLBound(psa, 2, &lBound2);
	if (FAILED(hr))
		throw "SafeArray access error" ;
	hr = SafeArrayGetUBound(psa, 2, &uBound2);
	if (FAILED(hr))
		throw "SafeArray access error" ;

	double*		dummy = NULL ;						// for access to the data
	m_NumColumns = uBound1 - lBound1 + 1 ;
	m_NumRows = uBound2 - lBound2 + 1 ;
	m_pData = AllocateMemory(m_NumColumns, m_NumRows) ;
	IncrementReferenceCount() ;			// count the reference to this memory

	SafeArrayAccessData(psa, (void**)(&dummy)) ;	// dummy now points to the data
	
	// copy each element across into the matrix to return
	for (int i = 0; i < m_NumColumns ; ++i)
		{
		for (int j = 0; j < m_NumRows ; ++j)
			SetElement(i, j, dummy[(i - lBound1) * m_NumRows + j - lBound2]) ;
		}
	dummy = NULL ;									// no longer valid
	SafeArrayUnaccessData(psa) ;					// release the safe array data pointer
}

CMatrix::~CMatrix()
{
#ifdef _DEBUG
	TRACE("Destroying CMatrix object %1d\n", m_ObjectNumber) ;
#endif
	DecrementAndRelease() ;			// free's m_pData if no other references
}

#ifdef _DEBUG
void CMatrix::Dump(CDumpContext& dc) const
{
	UNUSED_PARAMETER(dc) ;
	TRACE("CMatrix object    #%1d\n", m_ObjectNumber) ;
	TRACE("Num columns     : %1d\n", m_NumColumns) ;
	TRACE("Num rows        : %1d\n", m_NumRows) ;
	TRACE("Data pointer    : %lx\n", m_pData) ;
	TRACE("Reference count : %1d\n", GetReferenceCount()) ;
	for (int i = 0 ; i < m_NumRows ; ++i)
		{
		TRACE("Row %2d,", i) ;
		for (int j = 0 ; j < m_NumColumns ; ++j)
			{
			TRACE("%e,", GetElement(j, i)) ;
			}
		TRACE("\n") ;
		Sleep(m_NumColumns *2) ;		// this is to allow all element data to be traced for very large matrices!
		}
}

void CMatrix::AssertValid() const
{
	ASSERT(m_NumColumns > 0) ;							// matrix size error
	ASSERT(m_NumRows > 0) ;							// matrix size error
	ASSERT(m_pData) ;								// bad pointer error
	ASSERT(FALSE == IsBadReadPtr(m_pData, sizeof(double) * (m_NumColumns * m_NumRows + 1))) ;
}
#endif

void CMatrix::Serialize(CArchive& archive)
{
	CObject::Serialize(archive) ;
	if (archive.IsStoring())
		{
		// writing the matrix
		// write the object header first so we can correctly recognise the object type "CMatrixC"
		long	header1 = 0x434d6174 ;
		long	header2 = 0x72697843 ;
		int		version = 1 ;						// serialization version format number

		archive << header1 ;
		archive << header2 ;
		archive << version ;						// version number of object type

		// now write out the actual matrix
		archive << m_NumColumns ;
		archive << m_NumRows ;
		// this could be done with a archive.Write(m_pData, sizeof(double) * m_NumColumns * m_NumRows)
		// for efficiency (dont forget its a flat array). Not done here for clarity
		for (int i = 0 ; i < m_NumColumns ; ++i)
			{
			for (int j = 0 ; j < m_NumRows ; ++j)
				{
				archive << GetElement(i, j) ;		
				}
			}
		// done!
		}
	else
		{
		// reading the matrix
		// read the object header first so we can correctly recognise the object type "CMatrixC"
		long	header1 = 0 ;
		long	header2 = 0 ;
		int		version = 0 ;				// serialization version format

		archive >> header1 ;
		archive >> header2 ;
		if (header1 != 0x434d6174 || header2 != 0x72697843)
			{
			// incorrect header, cannot load it
			AfxThrowArchiveException(CArchiveException::badClass, NULL) ;
			}
		archive >> version ;				// version number of object type
		ASSERT(version == 1) ;				// only file format number so far

		// now write out the actual matrix
		int		nCols ;
		int		nRows ;
		double	value ;
		archive >> nCols ;
		archive >> nRows ;
		CMatrix loading(nCols, nRows) ;
		for (int i = 0 ; i < nCols ; ++i)
			{
			for (int j = 0 ; j < nRows ; ++j)
				{
				archive >> value ;
				loading.SetElement(i, j, value) ;
				}
			}
		*this = loading ;					// copy the data into ourselves
		// done!
		}
}

double* CMatrix::AllocateMemory(int nCols, int nRows)
{
	ASSERT(nCols > 0) ;							// size error
	ASSERT(nRows > 0) ;							// size error
	// allocates heap memory for an array
	double	*pData = NULL ;

	pData = new double[nCols * nRows + 1] ;			// all in one allocation (+1 for reference count)
	ASSERT(pData != NULL) ;					// allocation error
	ASSERT(FALSE == IsBadReadPtr(pData, sizeof(double) * (nCols * nRows + 1))) ;
	// empty the memory
	memset(pData, 0, sizeof(double) * (nCols * nRows + 1)) ;		// starts with a 0 reference count
	return pData ;
}

CMatrix& CMatrix::operator=(const CMatrix &other)
{
	if (&other == this)
		return *this ;
	// this does the same job as a copy constructor except we have to de-allocate any
	// memory we may have already allocated
	DecrementAndRelease() ;			// free's m_pData if no other references
	// now copy the other matrix into ourselves
	// use the other objects data pointer
	m_NumColumns = other.m_NumColumns ;
	m_NumRows = other.m_NumRows ;
	m_pData = other.m_pData ;				// copy the pointer
	IncrementReferenceCount() ;				// this thread can get the mutex multiple times without blocking
	// finally return a reference to ourselves
	return *this ;
}

bool CMatrix::operator==(const CMatrix &other) const
{
	// only return true if the matrices are exactly the same
	if (&other == this)
		return true ;		// comparing to ourselves
	if (m_pData == other.m_pData)
		return true ;		// both pointing to same data, must be same
	if (m_NumColumns != other.m_NumColumns || m_NumRows != other.m_NumRows)
		return false ;		// different dimensions
	if (memcmp(m_pData, other.m_pData, sizeof(double) * m_NumColumns * m_NumRows) == 0)
		return true ;		// buffers are the same
	return false ;			// must be different
}

CMatrix CMatrix::operator+(const CMatrix &other) const
{
	// first check for a valid addition operation
	if (m_NumColumns != other.m_NumColumns)
		throw "Invalid operation" ;
	if (m_NumRows != other.m_NumRows)
		throw "Invalid operation" ;
	// now that we know that the operation is possible
	ASSERT(FALSE == IsBadReadPtr(other.m_pData, sizeof(double) * other.m_NumColumns * other.m_NumRows)) ;
	// construct the object we are going to return
	CMatrix		result(*this) ;		// copy ourselves
	// now add in the other matrix
	for (int i = 0 ; i < m_NumColumns ; ++i)
		{
		for (int j = 0 ; j < m_NumRows ; ++j)
			result.SetElement(i, j, result.GetElement(i, j) + other.GetElement(i, j)) ;
		}
	return result ;
}

CMatrix CMatrix::operator-(const CMatrix &other) const
{
	// first check for a valid subtraction operation
	if (m_NumColumns != other.m_NumColumns)
		throw "Invalid operation" ;
	if (m_NumRows != other.m_NumRows)
		throw "Invalid operation" ;
	// now that we know that the operation is possible
	ASSERT(FALSE == IsBadReadPtr(other.m_pData, sizeof(double) * other.m_NumColumns * other.m_NumRows)) ;
	// construct the object we are going to return
	CMatrix		result(*this) ;		// copy ourselves
	// now subtract the other matrix
	for (int i = 0 ; i < m_NumColumns ; ++i)
		{
		for (int j = 0 ; j < m_NumRows ; ++j)
			result.SetElement(i, j, result.GetElement(i, j) - other.GetElement(i, j)) ;
		}
	return result ;
}

CMatrix CMatrix::operator*(const CMatrix &other) const
{
	// first check for a valid multiplication operation
	if (m_NumRows != other.m_NumColumns)
		throw "Matrices do not have common size" ;
	// now that we know that the operation is possible
	ASSERT(FALSE == IsBadReadPtr(other.m_pData, sizeof(double) * other.m_NumColumns * other.m_NumRows)) ;
	// construct the object we are going to return
	CMatrix		result(m_NumColumns, other.m_NumRows) ;

	// e.g.
	// [A][B][C]   [G][H]     [A*G + B*I + C*K][A*H + B*J + C*L]
	// [D][E][F] * [I][J] =   [D*G + E*I + F*K][D*H + E*J + F*L]
	//             [K][L]
	//
	double	 value ;
	for (int i = 0 ; i < result.m_NumColumns ; ++i)
		{
		for (int j = 0 ; j < result.m_NumRows ; ++j)
			{
			value = 0.0 ;
			for (int k = 0 ; k < m_NumRows ; ++k)
				{
				value += GetElement(i, k) * other.GetElement(k, j) ;
				}
			result.SetElement(i, j, value) ;
			}
		}
	return result ;
}

void CMatrix::operator+=(const CMatrix &other)
{
	// first check for a valid addition operation
	if (m_NumColumns != other.m_NumColumns)
		throw "Invalid operation" ;
	if (m_NumRows != other.m_NumRows)
		throw "Invalid operation" ;
	// now that we know that the operation is possible
	ASSERT(FALSE == IsBadReadPtr(other.m_pData, sizeof(double) * other.m_NumColumns * other.m_NumRows)) ;
	// now add in the other matrix
	for (int i = 0 ; i < m_NumColumns ; ++i)
		{
		for (int j = 0 ; j < m_NumRows ; ++j)
			SetElement(i, j, GetElement(i, j) + other.GetElement(i, j)) ;
		}
}

void CMatrix::operator-=(const CMatrix &other)
{
	// first check for a valid subtraction operation
	if (m_NumColumns != other.m_NumColumns)
		throw "Invalid operation" ;
	if (m_NumRows != other.m_NumRows)
		throw "Invalid operation" ;
	// now that we know that the operation is possible
	ASSERT(FALSE == IsBadReadPtr(other.m_pData, sizeof(double) * other.m_NumColumns * other.m_NumRows)) ;
	// now subtract the other matrix
	for (int i = 0 ; i < m_NumColumns ; ++i)
		{
		for (int j = 0 ; j < m_NumRows ; ++j)
			SetElement(i, j, GetElement(i, j) - other.GetElement(i, j)) ;
		}
}

void CMatrix::operator*=(const CMatrix &other)
{
	// first check for a valid multiplication operation
	if (m_NumRows != other.m_NumColumns)
		throw "Matrices do not have common size" ;

	*this = *this * other ;
}

void CMatrix::operator*=(double value)
{
	// just multiply the elements by the value
	for (int i = 0 ; i < m_NumColumns ; ++i)
		{
		for (int j = 0 ; j < m_NumRows ; ++j)
			{

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲成人av免费| 蜜臀久久久99精品久久久久久| 欧美videos大乳护士334| 欧美男同性恋视频网站| 欧美日韩免费观看一区三区| 欧美天堂一区二区三区| 欧美日韩在线直播| 91麻豆精品国产综合久久久久久 | 亚洲精品国产一区二区精华液 | 91.com在线观看| 日韩三区在线观看| 26uuu精品一区二区三区四区在线| 欧美一区二区三区免费在线看| 欧美一级在线免费| 久久久美女毛片| 亚洲日本电影在线| 首页国产丝袜综合| 麻豆精品视频在线观看视频| 国产69精品久久99不卡| 91久久精品网| 日韩欧美亚洲国产精品字幕久久久| 久久久亚洲国产美女国产盗摄| 欧美国产精品久久| 亚洲猫色日本管| 男人的j进女人的j一区| 成人免费视频视频| 欧美高清激情brazzers| 欧美不卡一区二区| 亚洲欧洲av在线| 日韩精品高清不卡| 成人午夜电影网站| 91精品国产日韩91久久久久久| 久久蜜桃av一区精品变态类天堂| 亚洲天堂免费看| 日本成人在线电影网| 成人激情免费网站| 在线成人免费观看| 一区视频在线播放| 久久99久久99小草精品免视看| 成人免费三级在线| 欧美成人精品福利| 一区二区日韩av| 成人一区二区在线观看| 欧美一区二区免费观在线| 国产精品国产三级国产普通话蜜臀 | 8v天堂国产在线一区二区| 国产精品久久久久影院| 免费av成人在线| 欧洲精品一区二区三区在线观看| 精品久久久久久久人人人人传媒| 亚洲黄色免费电影| 国产精品99久久久久久似苏梦涵| 欧美精品久久天天躁| 综合欧美一区二区三区| 国产盗摄精品一区二区三区在线 | 九九国产精品视频| 欧美性三三影院| 中文字幕日韩欧美一区二区三区| 精品亚洲porn| 日韩欧美一级在线播放| 亚洲电影第三页| 欧美系列日韩一区| 一区二区欧美精品| 在线观看视频一区二区欧美日韩| 中文字幕制服丝袜成人av| 丁香六月久久综合狠狠色| 久久久777精品电影网影网| 久久国产麻豆精品| 精品成人a区在线观看| 久久草av在线| 久久综合中文字幕| 国产黑丝在线一区二区三区| 国产亚洲一区二区三区在线观看| 精品一区二区在线看| 精品粉嫩超白一线天av| 韩日精品视频一区| 久久久国际精品| 国产999精品久久久久久绿帽| 国产精品国产三级国产aⅴ入口 | 欧美丰满少妇xxxxx高潮对白| 一卡二卡三卡日韩欧美| 在线一区二区三区| 午夜精品视频一区| 欧美一卡在线观看| 久久99久久精品欧美| 精品动漫一区二区三区在线观看| 国产乱码精品一区二区三| 国产欧美精品一区二区三区四区| 高清在线成人网| 亚洲激情中文1区| 91精品国产全国免费观看| 免费成人你懂的| 亚洲国产精品黑人久久久| 91免费观看在线| 日韩高清一区在线| 久久久久亚洲蜜桃| 97精品久久久午夜一区二区三区| 亚洲美女区一区| 日韩欧美成人一区| 不卡的av网站| 偷拍自拍另类欧美| 国产日韩av一区二区| 欧美亚洲综合一区| 国产一区二区导航在线播放| 亚洲天堂成人在线观看| 欧美一级xxx| 91视频xxxx| 久久99国产精品免费| 亚洲欧美日韩中文字幕一区二区三区| 欧美日韩不卡视频| 高清不卡在线观看| 日韩精品每日更新| 国产精品午夜春色av| 欧美高清你懂得| 91免费观看视频| 精品一区二区三区视频在线观看| 日韩理论电影院| 久久久久久电影| 欧美巨大另类极品videosbest| 成人av在线网站| 狠狠色狠狠色合久久伊人| 亚洲一区在线观看视频| 亚洲国产高清在线观看视频| 欧美一级久久久| 一本到三区不卡视频| 国产成人自拍网| 九色综合狠狠综合久久| 亚洲午夜三级在线| 中文字幕一区二区三区蜜月| 久久嫩草精品久久久久| 欧美一区二区三区影视| 91原创在线视频| 国产精品1024久久| 另类专区欧美蜜桃臀第一页| 一区二区三区在线免费视频| 综合色中文字幕| 亚洲少妇30p| 久久精品日产第一区二区三区高清版| 欧美精品视频www在线观看| 91精品办公室少妇高潮对白| 成人av在线资源网站| 国产精品影视天天线| 狠狠色丁香久久婷婷综合丁香| 琪琪一区二区三区| 日韩成人免费电影| 丝袜诱惑制服诱惑色一区在线观看 | 欧美日韩中文字幕一区二区| www.爱久久.com| 97久久久精品综合88久久| 成人av资源下载| 99精品黄色片免费大全| 一本大道久久a久久精二百| 91一区一区三区| 色呦呦一区二区三区| 欧洲一区二区三区在线| 欧美日韩一区高清| 欧美喷潮久久久xxxxx| 日韩情涩欧美日韩视频| 2021国产精品久久精品| 亚洲国产精品黑人久久久| 亚洲国产成人自拍| 亚洲女同女同女同女同女同69| 国产精品美日韩| 一区二区三区不卡视频| 日韩福利电影在线观看| 黄色日韩三级电影| 国产.精品.日韩.另类.中文.在线.播放 | 婷婷成人综合网| 美女尤物国产一区| 精品影视av免费| 波多野结衣欧美| 欧美午夜精品免费| 日韩欧美国产小视频| 久久日韩精品一区二区五区| 国产精品久线在线观看| 亚洲一区二区三区中文字幕| 秋霞av亚洲一区二区三| 高清久久久久久| 欧美日韩午夜在线| 26uuu欧美| 亚洲九九爱视频| 美女视频网站黄色亚洲| 成人免费三级在线| 717成人午夜免费福利电影| 欧美sm极限捆绑bd| 亚洲精选免费视频| 久久福利资源站| 欧美在线制服丝袜| 国产欧美精品国产国产专区| 亚洲夂夂婷婷色拍ww47| 国产精品456| 欧美一区二区三区在线观看视频| 国产精品热久久久久夜色精品三区 | 欧美日韩在线免费视频| 国产亚洲欧美中文| 午夜影院在线观看欧美| 国产91丝袜在线观看| 91精品蜜臀在线一区尤物| 专区另类欧美日韩| 国产精品一区二区黑丝|