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

📄 mmat_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 5 页
字号:
	}		// test max	//	val = arg_mat1.max(row_pos, col_pos);#ifndef ISIP_TEMPLATE_complex	val_res.assign((TIntegral)MMAT_MAX_RES[mat1][MMAT_DATA_LOC]);#else	complexdouble tmp_complex1(MMAT_MAX_RES[mat1][MMAT_DATA_LOC],				  MMAT_MAX_RES[mat1][MMAT_DATA_LOC + 1]);	val_res.assign((TIntegral)tmp_complex1);#endif		if ((!val_res.almostEqual(val)) || 	    (row_pos != (long)MMAT_MAX_RES[mat1][MMAT_NROW_LOC]) ||	    (col_pos != (long)MMAT_MAX_RES[mat1][MMAT_NCOL_LOC])) {	  Console::put(arg1_str);	  Error::handle(name(), L"max", Error::TEST, __FILE__, __LINE__);	}		// test minMag and maxMag methods	//	double val_mag;	double val_mag_res;		// test minMag	//	val_mag = arg_mat1.minMag(row_pos, col_pos);	val_mag_res = MMAT_MINMAG_RES[mat1][MMAT_DATA_LOC];	if ((!Integral::almostEqual(val_mag_res, val_mag)) ||	    (row_pos != (long)MMAT_MINMAG_RES[mat1][MMAT_NROW_LOC]) ||	    (col_pos != (long)MMAT_MINMAG_RES[mat1][MMAT_NCOL_LOC])) {	  Console::put(arg1_str);	  Error::handle(name(), L"minMag", Error::TEST, __FILE__, __LINE__);	}		// test maxMag	//	val_mag = arg_mat1.maxMag(row_pos, col_pos);	val_mag_res = MMAT_MAXMAG_RES[mat1][MMAT_DATA_LOC];	if ((!Integral::almostEqual(val_mag_res, val_mag)) ||	    (row_pos != (long)MMAT_MAXMAG_RES[mat1][MMAT_NROW_LOC]) ||	    (col_pos != (long)MMAT_MAXMAG_RES[mat1][MMAT_NCOL_LOC])) {	  Console::put(arg1_str);	  Error::handle(name(), L"maxMag", Error::TEST, __FILE__, __LINE__);	}		// declare local variables	//	TScalar dval;	// test determinant if matrix is square - as we test 8	// matrices of different types (square, non-square, singular,	// non-singular), we don't want the diagnose method to return	// test error for obvious cases. note that the determinant is	// only tested for signed data types.	//	if (typeid(TIntegral) == typeid(float) ||	    typeid(TIntegral) == typeid(double) ||	    typeid(TIntegral) == typeid(llong) ||	    typeid(TIntegral) == typeid(long) ||	    typeid(TIntegral) == typeid(short)) {	  if (arg_mat1.isSquare()) {	    dval = arg_mat1.determinant();	    TScalar det_res((TIntegral)MMAT_DET_RES[mat1]);	    if (!det_res.almostEqual(dval)) {	      Console::put(arg1_str);	      dval.debug(L"output");	      det_res.debug(L"expected result");	      Error::handle(name(), L"determinant", Error::TEST, 			    __FILE__, __LINE__);	    }	  }	}	// test sum	//	dval = arg_mat1.sum();#ifndef ISIP_TEMPLATE_complex	val_res.assign((TIntegral)MMAT_SUM_RES[mat1]);#else	complexdouble tmp_complex3(MMAT_SUM_RES[mat1],				  MMAT_SUM_RES[mat1 + MMAT_NUM_MATS_TOTAL]);	val_res.assign((TIntegral)tmp_complex3);#endif		if (!val_res.almostEqual(dval)) {	  Console::put(arg1_str);	  dval.debug(L"output");	  val_res.debug(L"expected result");		  Error::handle(name(), L"sum", Error::TEST, __FILE__, __LINE__);	}		// test sumSquare	//	dval = arg_mat1.sumSquare();#ifndef ISIP_TEMPLATE_complex	val_res.assign((TIntegral)MMAT_SUM_SQUARE_RES[mat1]);#else	complexdouble tmp_complex4(MMAT_SUM_SQUARE_RES[mat1],				  MMAT_SUM_SQUARE_RES[mat1 + MMAT_NUM_MATS_TOTAL]);	val_res.assign((TIntegral)tmp_complex4);#endif	if (!val_res.almostEqual(dval)) {	  Console::put(arg1_str);	  dval.debug(L"sumSq");	  Error::handle(name(), L"sumSquare", Error::TEST, __FILE__, __LINE__);	}	// test mean	//	dval = arg_mat1.mean();#ifndef ISIP_TEMPLATE_complex	val_res.assign((TIntegral)MMAT_MEAN_RES[mat1]);#else	complexdouble tmp_complex5(MMAT_MEAN_RES[mat1],				  MMAT_MEAN_RES[mat1 + MMAT_NUM_MATS_TOTAL]);	val_res.assign((TIntegral)tmp_complex5);#endif		if (!val_res.almostEqual(dval)) {	  Console::put(arg1_str);	  dval.debug(L"mean");	  Error::handle(name(), L"mean", Error::TEST, __FILE__, __LINE__);	}		// test rms	//	if (typeid(TIntegral) == typeid(float) ||	    typeid(TIntegral) == typeid(double)) {	  dval = arg_mat1.rms();#ifndef ISIP_TEMPLATE_complex	  val_res.assign((TIntegral)MMAT_RMS_RES[mat1]);#else	  complexdouble tmp_complex(MMAT_RMS_RES[mat1],				    MMAT_RMS_RES[mat1 + MMAT_NUM_MATS_TOTAL]);	  val_res.assign((TIntegral)tmp_complex);#endif	  if (typeid(TIntegral) != typeid(float)) {	    if (!val_res.almostEqual(dval, (long)42)) {	      Console::put(arg1_str);	      dval.debug(L"ou rms");	      val_res.debug(L"res rms");	      Error::handle(name(), L"rms", Error::TEST, __FILE__, __LINE__);	    }	  }	  else {	    if (!val_res.almostEqual(dval)) {	      Console::put(arg1_str);	      dval.debug(L"out rms");	      val_res.debug(L"res rms");	      Error::handle(name(), L"rms", Error::TEST, __FILE__, __LINE__);	    }	  }	}	// test var	//	if (typeid(TIntegral) == typeid(float) ||	    typeid(TIntegral) == typeid(double)) {		  dval = arg_mat1.var();#ifndef ISIP_TEMPLATE_complex	  val_res.assign((TIntegral)MMAT_VAR_RES[mat1]);#else	  complexdouble tmp_complex(MMAT_VAR_RES[mat1],				    MMAT_VAR_RES[mat1 + MMAT_NUM_MATS_TOTAL]);	  val_res.assign((TIntegral)tmp_complex);#endif	  	  if (typeid(TIntegral) != typeid(float)) {	    if (!val_res.almostEqual(dval)) {	      Console::put(arg1_str);	      dval.debug(L"out var");	      val_res.debug(L"res var");	      Error::handle(name(), L"var", Error::TEST, __FILE__, __LINE__);	    }	  }	  else {	    if (!val_res.almostEqual(dval)) {	      Console::put(arg1_str);	      dval.debug(L"out var");	      val_res.debug(L"res var");	      Error::handle(name(), L"var", Error::TEST, __FILE__, __LINE__);	    }	  }	}	// test trace	//	if (arg_mat1.isSquare()) {	  dval = arg_mat1.trace();#ifndef ISIP_TEMPLATE_complex	  val_res.assign((TIntegral)MMAT_TRACE_RES[mat1]);#else	  complexdouble tmp_complex(MMAT_TRACE_RES[mat1],				    MMAT_TRACE_RES[mat1 + MMAT_NUM_MATS_TOTAL]);	  val_res.assign((TIntegral)tmp_complex);#endif	  	  if (!val_res.almostEqual(dval)) {	    Console::put(arg1_str);	    dval.debug(L"out var");	    val_res.debug(L"res trace");	    Error::handle(name(), L"trace", Error::TEST, __FILE__, __LINE__);	  }	}  	// test sumColumn	//	for (long col = 0; col < arg_mat1.getNumColumns(); col++) {	  TScalar res_scal(arg_mat1.sumColumn(col));#ifndef ISIP_TEMPLATE_complex	  if (!res_scal.almostEqual((TIntegral)MMAT_SUM_COLUMN_RES[mat1][col]))#else	    	    complexdouble tmp_complex(MMAT_SUM_COLUMN_RES[mat1][col],				      MMAT_SUM_COLUMN_RES[mat1][col + MMAT_NUM_COLS]);	  if (!res_scal.almostEqual((TIntegral)tmp_complex))#endif	    {  	      Console::put(arg1_str);	      res_scal.debug(L"res");	  	      Error::handle(name(), L"sumColumn", Error::TEST, 			  __FILE__, __LINE__);	    }	}		// test sumRow	//	for (long row = 0; row < arg_mat1.getNumRows(); row++) {	  TScalar res_scal(arg_mat1.sumRow(row));#ifndef ISIP_TEMPLATE_complex	  if (!res_scal.almostEqual((TIntegral)MMAT_SUM_ROW_RES[mat1][row]))#else	    complexdouble tmp_complex(MMAT_SUM_ROW_RES[mat1][row],				      MMAT_SUM_ROW_RES[mat1][row + MMAT_NUM_ROWS]);	  if (!res_scal.almostEqual((TIntegral)tmp_complex))#endif	    {	      Console::put(arg1_str);	      res_scal.debug(L"res");	  	      Error::handle(name(), L"sumRow", Error::TEST, __FILE__, __LINE__);	    }	}		// test operator() and getValue methods	//	tmp_mat.assign(arg_mat1);	val_res.assign((TIntegral)3);		// set a specific value 3 at (row, col) = (1, 1)	//	tmp_mat.setValue(1, 1, (TIntegral)3);		if (!val_res.almostEqual(tmp_mat(1, 1))) {	  String out(L"(1,1)");	  out.concat(tmp_mat(1, 1));	  Console::put(out);	  Console::put(arg1_str);	  Error::handle(name(), L"setValue", Error::TEST, 			__FILE__, __LINE__);	}		if (!val_res.almostEqual(tmp_mat.getValue(1, 1))) {	  String out(L"gv(1,1)");	  out.concat(tmp_mat.getValue(1, 1));	  Console::put(out);	  Console::put(arg1_str);	  Error::handle(name(), L"getValue", Error::TEST, 			__FILE__, __LINE__);	}      }    }    if (level_a > Integral::BRIEF) {	Console::decreaseIndention();    }  }  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }    // exit gracefully  //  return true;}// method: diagnose2//// arguments://  Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//// this method tests single matrix to vector methods for 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::diagnose2(Integral::DEBUG level_a) {    // define TVector  //  typedef MVector<TScalar, TIntegral> TVector;    // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific public methods: single matrix --> vector...\n");    Console::increaseIndention();  }    // declare an array of matrix to hold all the 8 matrices used for testing  //    MMatrix<TScalar, TIntegral> arg_mats[MMAT_NUM_MATS_TEST];    // 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      }    // define temporary matrices to be used for testing  //  MMatrix<TScalar, TIntegral> tmp_mat;  MMatrix<TScalar, TIntegral> arg_mat1;    // loop over different matrices  //  for (long mat1 = 0; mat1 < MMAT_NUM_MATS_TEST; mat1++) {        // declare local variables    //    Char mat1c;    mat1c.assign((byte)((int)'A' + mat1));        // loop over the different types of matrices    //    for (long type1 = Integral::FULL; type1 <= Integral::SPARSE; type1++)            // test if the type conversion is possible      //      if (arg_mats[mat1].isTypePossible((Integral::MTYPE)type1)) {		// create a diagnostic string to indicate the matrix and its type	//	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);	// assign the input matrix 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 vector multiplication        //         TVector in_vec;        TVector out_vec;        TVector vec_res;        	// test vmult        //        in_vec.assign((long)MMAT_NUM_COLS, (double*)MMAT_VMULT_ARG_REAL);        vec_res.assign((long)MMAT_VMULT_RES_REAL[mat1][0],                        (double*)&MMAT_VMULT_RES_REAL[mat1][1]);#ifdef ISIP_TEMPLATE_complex	TVector tmp;	tmp.assign((long)MMAT_VMULT_RES_REAL[mat1][0], 		   (double*)&MMAT_VMULT_RES_REAL[mat1][1 + MMAT_NUM_COLS]);	tmp.mult(TIntegral(0, 1));	vec_res.add(tmp);#endif        // test only if the dimensions match - as we test 8 matrices	// of different dimensions, we don't want the diagnose method to	// return test error for obvious cases	//        if (arg_mat1.getNumRows() == in_vec.length()) {          arg_mat1.vmult(out_vec, in_vec);          if (!out_vec.almostEqual(vec_res)) {	    out_vec.debug(L"out value");	    vec_res.debug(L"res value");            Console::put(arg1_str);            Error::handle(name(), L"vmult", Error::TEST, __FILE__, __LINE__);          }        }	// additional test for input vector with non-zero imaginary part	//#ifdef ISIP_TEMPLATE_complex        in_vec.assign((long)MMAT_NUM_COLS, (double*)MMAT_VMULT_ARG_COMPLEX);	tmp.assign((long)MMAT_NUM_COLS,		   (double*)&MMAT_QUADRATIC_VEC_COMPLEX[MMAT_NUM_COLS]);	tmp.mult(TScalar(0, 1)); 	in_vec.add(tmp);	        vec_res.assign((long)MMAT_VMULT_RES_COMPLEX[mat1][0],                        (double*)&MMAT_VMULT_RES_COMPLEX[mat1][1]);	tmp.assign((long)MMAT_VMULT_RES_COMPLEX[mat1][0],		   (double*)&MMAT_VMULT_RES_COMPLEX[mat1][1 + MMAT_NUM_COLS]);	tmp.mult(TIntegral(0, 1)); 	vec_res.add(tmp);        // test only if the dimensions match - as we test 8 matrices	// of different dimensions, we don't want the diagnose method to	// return test error for obvious cases	//        if (arg_mat1.getNumRows() == in_vec.length()) {          arg_mat1.vmult(out_vec, in_vec);	          if (!out_vec.almostEqual(vec_res)) {	    out_vec.debug(L"out value");	    vec_res.debug(L"res value");            Console::put(arg1_str);            Error::handle(name(), L"vmult complex", Error::TEST, __FILE__, __LINE__);          }

⌨️ 快捷键说明

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