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

📄 mmat_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 5 页
字号:
// file: $isip/class/math/matrix/MMatrix/mmat_02.cc// version: $Id: mmat_02.cc,v 1.45 2002/03/05 15:15:16 gao Exp $//// system include files//#include <typeinfo>// isip include files// #include "MMatrix.h"#include "MMatrixMethods.h"#include "MMatrixDiagnose.h"#include <SofParser.h>#include <Console.h>// method: diagnose//// arguments://  Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//// this method tests the methods of the matrix class. the test vectors// and matrices used in this code for testing purpose have been// pre-defined in a separate file. this is done so that the diagnose// code is simplified. the code is designed to test all the methods// for all combinations of types.//template<class TMatrix, class TScalar, class TIntegral>boolean MMatrixMethods::diagnose(Integral::DEBUG level_a) {  // define TVector  //  typedef MVector<TScalar, TIntegral> TVector;  //----------------------------------------------------------------------  //  // 0. preliminaries  //  //----------------------------------------------------------------------    // output the class name  //  if (level_a > Integral::NONE) {    SysString output(L"diagnosing class ");    output.concat(MMatrix<TScalar, TIntegral>::name());    output.concat(L": ");    Console::put(output);    Console::increaseIndention();  }    //--------------------------------------------------------------------  //  // 1. required public methods  //  //--------------------------------------------------------------------    diagnose0<TScalar, TIntegral>(level_a);  //---------------------------------------------------------------------  //  // 2. single matrix --> scalar methods  //  //---------------------------------------------------------------------    diagnose1<TScalar, TIntegral>(level_a);  //---------------------------------------------------------------------  //  // 3. single matrix --> vector methods  //  //---------------------------------------------------------------------    diagnose2<TScalar, TIntegral>(level_a);    //---------------------------------------------------------------------  //  // 4. single matrix --> matrix methods  //  //---------------------------------------------------------------------  diagnose3<TScalar, TIntegral>(level_a);    //---------------------------------------------------------------------  //  // 5. matrix, matrix --> matrix methods  //  //---------------------------------------------------------------------  diagnose4<TScalar, TIntegral>(level_a);  //---------------------------------------------------------------------  //  // 6. matrix, matrix --> matrix methods (complex)  //   //---------------------------------------------------------------------#ifdef ISIP_TEMPLATE_complex  diagnose5<TScalar, TIntegral>(level_a);#endif  //---------------------------------------------------------------------------  //  // 7. print completion message  //  //---------------------------------------------------------------------------  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }    if (level_a > Integral::NONE) {    SysString output(L"diagnostics passed for class ");    output.concat(MMatrix<TScalar, TIntegral>::name());    output.concat(L"\n");    Console::put(output);  }  // exit gracefully  //  return true;  }// method: diagnose0//// arguments://  Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//// this method tests required public methods of matrix - the diagnose// method is designed in such a way that it tests the methods for 8// different matrices and for every possible type//template<class TScalar, class TIntegral>boolean MMatrixMethods::diagnose0(Integral::DEBUG level_a) {  // define TVector  //  typedef MVector<TScalar, TIntegral> TVector;  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing required matrix methods...\n");        Console::increaseIndention();  }  // set up the matrix data  //  MMatrix<TScalar, TIntegral> arg_mats[MMAT_NUM_MATS_TEST];  MMatrix<TScalar, TIntegral> arg_mat2;    // define binary and text sof files for i/o methods  //  String tmp_filename0;  Integral::makeTemp(tmp_filename0);  String tmp_filename1;  Integral::makeTemp(tmp_filename1);    // load up the argument matrices  //  for (long i = 0; i < MMAT_NUM_MATS_TEST; i++) {        // assign the arguments    //#ifndef ISIP_TEMPLATE_complex    arg_mats[i].assign((long)MMAT_ARG_MATRICES[i][MMAT_NROW_LOC],                        (long)MMAT_ARG_MATRICES[i][MMAT_NCOL_LOC],                        (double*)&MMAT_ARG_MATRICES[i][MMAT_DATA_LOC]);#else    arg_mats[i].assignComplexDiagnose((long)MMAT_ARG_MATRICES[i][MMAT_NROW_LOC],                        (long)MMAT_ARG_MATRICES[i][MMAT_NCOL_LOC],                        (double*)&MMAT_ARG_MATRICES[i][MMAT_DATA_LOC]);#endif      }  // test the setDebug method  //  arg_mat2.setDebug(level_a);  // loop over the number of matrices  //  for (long mat1 = 0; mat1 < MMAT_NUM_MATS_TEST; mat1++) {    // declare local variables    //    Char mat1c;    mat1c.assign((byte)((int)'A' + mat1));    String out;    out.concat(mat1c);        // loop over 6 different types of the matrices    //    for (long type1 = Integral::FULL; type1 <= Integral::SPARSE; type1++) {      // check if the type conversion is possible      //      if (arg_mats[mat1].isTypePossible((Integral::MTYPE)type1)) {		// create a diagnostic string for each matrix and its type - if there	// is a test error, this will be used to find that for which matrix and	// which type, there is an error	//	String type1_str(MMatrix<TScalar, TIntegral>::TYPE_MAP(type1));	String arg1_str(L"testing mat1: ");	arg1_str.concat(mat1c);	arg1_str.concat(L", ");	arg1_str.concat(type1_str);		// define temporary matrices to be used for testing	//	MMatrix<TScalar, TIntegral> res_mat;	MMatrix<TScalar, TIntegral> tmp_mat;	MMatrix<TScalar, TIntegral> arg_mat1;		// assign input matrix to arg_mat1 and change the type - type is	// changed here so that this particular matrix can be tested for	// every type it can have	//	arg_mat1.assign(arg_mats[mat1]);	arg_mat1.changeType((Integral::MTYPE)type1);		// test copy constructor	//	MMatrix<TScalar, TIntegral> mat_cpy(arg_mat1); 		// test debug methods	//	if (level_a > Integral::BRIEF) {	  mat_cpy.debug(L"debug");	}		// test block assignment	//	TIntegral value = 5;#ifdef ISIP_TEMPLATE_complex	if (mat1 >= MMAT_NUM_MATS_REAL) {	  value = TIntegral(5, 3);	}#endif		long start_row, num_rows, start_col, num_cols;	// type: FULL, SPARSE	//  [ 3 4 7 2 ]    [ 5 5 7 2 ]	//  [ 3 5 6 1 ]    [ 5 5 6 1 ]    	//  [ 8 4 1 3 ] -> [ 8 4 1 3 ]	//  [ 4 5 7 2 ]    [ 4 5 7 2 ]    	//	if (MMAT_ARG_MAT_TYPES[mat1] == Integral::FULL) {	  start_row = 0;	  start_col = 0;	  num_rows = 2;	  num_cols = 2;#ifndef ISIP_TEMPLATE_complex	  res_mat.assign((long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NROW_LOC], 			 (long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NCOL_LOC], 			 (double*)&MMAT_BLOCKASSIGN_RES[mat1][MMAT_DATA_LOC]);#else	  res_mat.assignComplexDiagnose((long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NROW_LOC], 			 (long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NCOL_LOC], 			 (double*)&MMAT_BLOCKASSIGN_RES[mat1][MMAT_DATA_LOC]);#endif	  	  tmp_mat.assign(arg_mat1);	  tmp_mat.setBlock(start_row, start_col, num_rows, num_cols, value);	  	  if (!res_mat.almostEqual(tmp_mat)) {	    Console::put(arg1_str);	    arg_mat1.debug(L"source matrix");	    res_mat.debug(L"result matrix");	    tmp_mat.debug(L"assigned matrix");	    Error::handle(name(), L"block assign - full", Error::TEST, __FILE__, __LINE__);	  }		}	// type: DIAGONAL	//  this can be done only when the element is assigned to the main	//  diagonal of the matrix, else it will error	//  [ 5 0 0 0 ]    [ 5 0 0 0 ]	//  [ 0 2 0 0 ]    [ 0 2 0 0 ]	//  [ 0 0 3 0 ] -> [ 0 0 5 0 ]	//  [ 0 0 0 4 ]    [ 0 0 0 4 ]	//	if (type1 == Integral::DIAGONAL) {	  start_row = 2;	  start_col = 2;	  num_rows = 1;	  num_cols = 1;#ifndef ISIP_TEMPLATE_complex	  res_mat.assign((long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NROW_LOC], 			 (long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NCOL_LOC], 			 (double*)&MMAT_BLOCKASSIGN_RES[mat1][MMAT_DATA_LOC]);#else	  res_mat.assignComplexDiagnose((long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NROW_LOC], 			 (long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NCOL_LOC], 			 (double*)&MMAT_BLOCKASSIGN_RES[mat1][MMAT_DATA_LOC]);#endif	  	  	  tmp_mat.assign(arg_mat1);	  tmp_mat.setBlock(start_row, start_col, num_rows, num_cols, value);	  if (!res_mat.almostEqual(tmp_mat)) {	    Console::put(arg1_str);	    arg_mat1.debug(L"source matrix");	    res_mat.debug(L"result matrix");	    tmp_mat.debug(L"assigned matrix");	    Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);	  }		}		// type: LOWER_TRIANGULAR	//  this can be done only when the block falls in the lower triangular	//  part of the matrix	//  [ 5 0 0 0 ]    [ 5 0 0 0 ]	//  [ 3 2 0 0 ]    [ 3 2 0 0 ]	//  [ 2 4 3 0 ] -> [ 5 5 5 0 ]	//  [ 1 7 5 4 ]    [ 5 5 5 4 ]	//		if ((type1 == Integral::LOWER_TRIANGULAR)	    && (mat1 != 1) && (mat1 != 9)) {	  start_row = 2;	  start_col = 0;	  num_rows = 2;	  num_cols = 3;#ifndef ISIP_TEMPLATE_complex	  res_mat.assign((long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NROW_LOC], 			 (long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NCOL_LOC], 			 (double*)&MMAT_BLOCKASSIGN_RES[mat1][MMAT_DATA_LOC]);#else	  res_mat.assignComplexDiagnose((long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NROW_LOC], 			 (long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NCOL_LOC], 			 (double*)&MMAT_BLOCKASSIGN_RES[mat1][MMAT_DATA_LOC]);#endif	  	  tmp_mat.assign(arg_mat1);	  tmp_mat.setBlock(start_row, start_col, num_rows, num_cols, value);	  	  if (!res_mat.almostEqual(tmp_mat)) {	    Console::put(arg1_str);	    arg_mat1.debug(L"source matrix");	    res_mat.debug(L"result matrix");	    tmp_mat.debug(L"assigned matrix");	    Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);	  }		}      		// type: UPPER_TRIANGULAR	//  this can be done only when the block falls in the upper triangular	//  part of the matrix	//  [ 5 2 3 4 ]    [ 5 2 5 5 ]	//  [ 0 2 2 7 ]    [ 0 2 5 5 ]	//  [ 0 0 3 1 ] -> [ 0 0 5 5 ]	//  [ 0 0 0 4 ]    [ 0 0 0 4 ]	//	if ((type1 == Integral::UPPER_TRIANGULAR)	    && (mat1 != 1) && (mat1 != 9)) {	  start_row = 0;	  start_col = 2;	  num_rows = 3;	  num_cols = 2;#ifndef ISIP_TEMPLATE_complex	  res_mat.assign((long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NROW_LOC], 			 (long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NCOL_LOC], 			 (double*)&MMAT_BLOCKASSIGN_RES[mat1][MMAT_DATA_LOC]);#else	  res_mat.assignComplexDiagnose((long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NROW_LOC], 			 (long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NCOL_LOC], 			 (double*)&MMAT_BLOCKASSIGN_RES[mat1][MMAT_DATA_LOC]);#endif	  	  	  tmp_mat.assign(arg_mat1);	  tmp_mat.setBlock(start_row, start_col, num_rows, num_cols, value);	  	  if (!res_mat.almostEqual(tmp_mat)) {	    Console::put(arg1_str);	    arg_mat1.debug(L"source matrix");	    res_mat.debug(L"result matrix");	    tmp_mat.debug(L"assigned matrix");	    Error::handle(name(), L"block assign - upper triangular", Error::TEST, __FILE__, __LINE__);	  }		}		// type: SYMMETRIC	//  this can be done if the block is either in lower triangle or	//  in upper triangle or is symmetric across main diagonal	//  [ 5 2 3 4 ]    [ 5 2 3 4 ]	//  [ 2 2 2 7 ]    [ 2 2 2 7 ]	//  [ 3 2 3 1 ] -> [ 5 5 3 1 ]	//  [ 4 7 1 4 ]    [ 5 5 1 4 ]	//	if ((type1 == Integral::SYMMETRIC) && (mat1 != 1) && (mat1 != 9)) {	  start_row = 2;	  start_col = 0;	  num_rows = 2;	  num_cols = 2;#ifndef ISIP_TEMPLATE_complex	  	  res_mat.assign((long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NROW_LOC], 			 (long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NCOL_LOC], 			 (double*)&MMAT_BLOCKASSIGN_RES[mat1][MMAT_DATA_LOC]);#else	  res_mat.assignComplexDiagnose((long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NROW_LOC], 			 (long)MMAT_BLOCKASSIGN_RES[mat1][MMAT_NCOL_LOC], 			 (double*)&MMAT_BLOCKASSIGN_RES[mat1][MMAT_DATA_LOC]);#endif	  	  tmp_mat.assign(arg_mat1);	  tmp_mat.setBlock(start_row, start_col, num_rows, num_cols, value);	  	  if (!res_mat.almostEqual(tmp_mat)) {	    Console::put(arg1_str);	    arg_mat1.debug(L"source matrix");	    res_mat.debug(L"result matrix");	    tmp_mat.debug(L"assigned matrix");	    Error::handle(name(), L"block assign - symmetric", Error::TEST, __FILE__, __LINE__);	  }		}	// test assignment of a matrix from a TAIntegral array	//#ifndef ISIP_TEMPLATE_complex	tmp_mat.assign((long)MMAT_ASSIGN_ARG[mat1][MMAT_NROW_LOC], 		       (long)MMAT_ASSIGN_ARG[mat1][MMAT_NCOL_LOC], 		       (double*)&MMAT_ASSIGN_ARG[mat1][MMAT_DATA_LOC],		       MMAT_ARG_MAT_TYPES[mat1]);

⌨️ 快捷键说明

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