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

📄 math_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 5 页
字号:
  input(2).makeVectorComplexFloat().assign(L"1.0 + 1.0j, 1.0 + 1.0j");  input(3).makeVectorComplexFloat().assign(L"2.0 + 2.0j, 2.0 - 2.0j");  math6.compute(output, input);  VectorComplexFloat result_cf;  result_cf.assign(L"6.82836 - 3.40425j, 11.3284 + 14.5335j");  if (!result_cf.almostEqual(output.getVectorComplexFloat())) {    output.debug(L"output");    return Error::handle(name(), L"compute", Error::TEST,                         __FILE__, __LINE__);  }  /*    	// test Y = X1 + 2 * X2 - log(X3) - exp(X4)	//  test wrong input "if ASSIGN appears middle of computation	//  everything before it will clear.	//	if (level_a > Integral::BRIEF) {	Console::put(L"\n\ttesting for Y = [X1 + 2.0 * X2 - log(X3) - exp(X4)]:\n");	}  	values(0).assign((long)IDENTITY);	values(1).assign((long)IDENTITY);	values(2).assign((long)LOG);	values(3).assign((long)EXP);	values_op(0).assign((long)ASSIGN);	values_op(1).assign((long)ADD);	values_op(2).assign((long)ASSIGN);	values_op(3).assign((long)SUBTRACT);	math6.setNumOperands(4);	math6.setWeight(L"1.0, 2.0, 1.0, 1.0");	math6.setOperation(values_op);	math6.setFunction(values);	math6.setConstant(0.0);  	input.setLength(4);	input(0).makeVectorComplexFloat().assign(L"1.1 + 1.1j, 4.0 + 4.0j");	input(1).makeVectorComplexFloat().assign(L"1.5 + 1.5j, 2.3 + 2.3j");	input(2).makeVectorComplexFloat().assign(L"1.0 + 1.0j, 1.0 + 1.0j");	input(3).makeVectorComplexFloat().assign(L"2.0 + 2.0j, 2.0 - 2.0j");	math6.compute(output, input);	result_cf.assign(L"3.4215 - 5.9334j, 3.42151 + 7.5042j");	if (!result_cf.almostEqual(output.getVectorComplexFloat())) {	output.debug(L"output");	return Error::handle(name(), L"compute", Error::TEST,	__FILE__, __LINE__);	}  	// test Y = X1 + 2 * X2 - log(X3) - exp(X4) (all zero and constant)	//	if (level_a > Integral::BRIEF) {	Console::put(L"\n\ttesting for Y = [X1 + 2.0 * X2 - log(X3) - exp(X4)] for all zero values:\n");	}	input.setLength(4);	input(0).makeVectorComplexFloat().assign(L"0.0, 0.0");	input(1).makeVectorComplexFloat().assign(L"0.0, 0.0");	input(2).makeVectorComplexFloat().assign(L"1.0, 1.0");	input(3).makeVectorComplexFloat().assign(L"0.0, 0.0");	math6.compute(output, input);	result_cf.assign(L"-1.0, -1.0");	if (!result_cf.almostEqual(output.getVectorComplexFloat())) {	output.debug(L"output");	return Error::handle(name(), L"compute", Error::TEST,	__FILE__, __LINE__);	}  	// test Y = [ {X1* X2 + log(X3)} / exp(X4)]	//	if (level_a > Integral::BRIEF) {	Console::put(L"\n\ttesting for Y = [ {X1* X2 + log(X3)} / exp(X4)]:\n");	}	math6.setWeight(L"1.0, 1.0, 1.0, 1.0");	values_op(0).assign((long)ASSIGN);	values_op(1).assign((long)MULTIPLY);	values_op(2).assign((long)ADD);	values_op(3).assign((long)DIVIDE);	math6.setOperation(values_op);	input.setLength(4);	input(0).makeVectorComplexFloat().assign(L"1.1 + 1.1j, 4.0 + 4.0j");	input(1).makeVectorComplexFloat().assign(L"1.5 + 1.5j, 2.3 + 2.3j");	input(2).makeVectorComplexFloat().assign(L"1.0 + 1.0j, 1.0 + 1.0j");	input(3).makeVectorComplexFloat().assign(L"2.0 + 2.0j, 2.0 - 2.0j");	math6.compute(output, input);	result_cf.assign(L"0.4832 - 0.2727j, -2.3804 - 1.0378j");	if (!result_cf.almostEqual(output.getVectorComplexFloat())) {	output.debug(L"output");	return Error::handle(name(), L"compute", Error::TEST,	__FILE__, __LINE__);	}	// test Y = square(X1) + 2.0 * sqrt(X2) + 3.0	//	if (level_a > Integral::BRIEF) {	Console::put(L"\n\ttesting for Y = [square(X1) + 2.0 * sqrt(X2) + 3.0]:\n");	}	values.setLength(2);	values(0).assign((long)SQUARE);	values(1).assign((long)SQRT);	math6.setNumOperands(2);	math6.setWeight(L"1.0, 2.0");	str.assign(L"ASSIGN, ADD");	math6.setOperation(str);	math6.setFunction(values);	math6.setConstant(3.0);	input.setLength(2);	input(0).makeVectorComplexFloat().assign(L"1.0 + 1.0j, 2.0 + 2.0j");	input(1).makeVectorComplexFloat().assign(L"4.0 + 4.0j, 9.0 + 9.0j");	math6.compute(output, input);	result_cf.assign(L"7.3947 + 3.8203j, 9.5921 + 10.7305j");	if (!result_cf.almostEqual(output.getVectorComplexFloat())) {	output.debug(L"output");	return Error::handle(name(), L"compute", Error::TEST,	__FILE__, __LINE__);	}	// test Y = 2.0 * X1^2 + 3.0 * X2 + 3.0	//	if (level_a > Integral::BRIEF) {	Console::put(L"\n\ttesting for Y = [2.0 * X1^2 + 3.0 * X2 + 3.0]:\n");	}	values.setLength(2);	values(0).assign((long)SQUARE);	values(1).assign((long)IDENTITY);	math6.setNumOperands(2);	math6.setWeight(L"2.0, 3.0");	str.assign(L"ASSIGN, ADD");	math6.setOperation(str);	math6.setFunction(values);	input(0).makeVectorComplexFloat().assign(L"1.0 + 1.0j, 2.0 + 2.0j");	input(1).makeVectorComplexFloat().assign(L"4.0 + 4.0j, 9.0 + 9.0j"); 	math6.compute(output, input);	result_cf.assign(L"15.0 + 16.0j, 30 + 43j");	if (!result_cf.almostEqual(output.getVectorComplexFloat())) {	output.debug(L"output");	return Error::handle(name(), L"compute", Error::TEST,	__FILE__, __LINE__);	}	// test Y = X1 * X2 (vector * matrix)	//	if (level_a > Integral::BRIEF) {	Console::put(L"\n\ttesting for Y = [X1 * X2 (vector * matrix)]:\n");	}  	input(0).makeVectorComplexFloat().assign(L"1.0 + 1.0j, 2.0 + 3.0j");	input(1).makeMatrixComplexFloat().assign(2, 2, L"3.0 + 3.0j, 4.0 + 4.0j, 5.0 + 5.0j, 6.0 + 6.0j");	values(0).assign((long)IDENTITY);	values(1).assign((long)IDENTITY);	values_op.setLength(2);	values_op(0).assign((long)ASSIGN);	values_op(1).assign((long)MULTIPLY);	math6.setOperation(values_op);	math6.setFunction(values);	math6.setWeight(L"1.0, 1.0");	math6.setConstant(0.0);	math6.compute(output, input);  	result_cf.assign(L"-5.0 + 31j, -6 + 38j");  	if (!(result_cf).almostEqual(output.getVectorComplexFloat())) {	output.debug(L"output");	return Error::handle(name(), L"apply", Error::TEST,	__FILE__, __LINE__);	}	// test Y = X1 * X2 (vector * inv(matrix))	//  	values(0).assign((long)IDENTITY);	values(1).assign((long)INVERSE);	values_op.setLength(2);	values_op(0).assign((long)ASSIGN);	values_op(1).assign((long)MULTIPLY);	math6.setOperation(values_op);	math6.setFunction(values);	math6.setWeight(L"1.0, 1.0");	math6.setConstant(0.0);	math6.compute(output, input);  	result_cf.assign(L"3.25 + 1.25j, -1.75 - 0.75j");  	if (!(result_cf).almostEqual(output.getVectorComplexFloat())) {	output.debug(L"output");	return Error::handle(name(), L"apply", Error::TEST,	__FILE__, __LINE__);	}	// test Y = X1 * X2 (vector * matrix) with vector of  zeros and constants	//	if (level_a > Integral::BRIEF) {	Console::put(L"\n\ttesting for Y = [X1 * X2 (vector * matrix)] with vector of zeros and constants:\n");	}	//test vector of zeros	//	input(0).makeVectorComplexFloat().assign(L"0.0, 0.0, 0.0");	input(1).makeMatrixComplexFloat().assign(3, 3, L"1.0 + 1.0j, 0.0, 5.0 + 5.0j, 1.2 + 1.2j, 2.4 + 2.4j, 3.6 + 3.6j, 1.8 + 1.8j, 2.1 + 2.1j, 9.8 + 9.8j");	values(0).assign((long)IDENTITY);	values(1).assign((long)IDENTITY);	values_op.setLength(2);	values_op(0).assign((long)ASSIGN);	values_op(1).assign((long)MULTIPLY);	math6.setOperation(values_op);	math6.setFunction(values);	math6.setWeight(L"1.0, 1.0");	math6.setConstant(0.0);	math6.compute(output, input);  	result_cf.assign(L"0.0, 0.0, 0.0");  	if (!(result_cf).almostEqual(output.getVectorComplexFloat())) {	output.debug(L"output");	return Error::handle(name(), L"apply", Error::TEST,	__FILE__, __LINE__);	}	//test matrix of zeros	//	input(0).makeVectorComplexFloat().assign(L"1.0 + 2.0j, 1.0 - 2.0j, 1.0 + 3.0j");	input(1).makeMatrixComplexFloat().assign(3, 3, L"0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0");	values(0).assign((long)IDENTITY);	values(1).assign((long)IDENTITY);	values_op.setLength(2);	values_op(0).assign((long)ASSIGN);	values_op(1).assign((long)MULTIPLY);	math6.setOperation(values_op);	math6.setFunction(values);	math6.setWeight(L"1.0, 1.0");	math6.setConstant(0.0);	math6.compute(output, input);  	result_cf.assign(L"0.0, 0.0, 0.0");  	if (!(result_cf).almostEqual(output.getVectorComplexFloat())) {	output.debug(L"output");	return Error::handle(name(), L"apply", Error::TEST,	__FILE__, __LINE__);	}  */    // test Y = X1 + X2 * X3' + inv(x4)  //  (matrix + matrix * trans(matrix) + inv(matrix))  //  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting for Y = [X1 + X2 * X3' + inv(x4)] (matrix + matrix * trans(matrix) + inv(matrix)):\n");  }  values.setLength(4);  values_op.setLength(4);  values(0).assign((long)IDENTITY);  values(1).assign((long)IDENTITY);  values(2).assign((long)TRANSPOSE);  values(3).assign((long)INVERSE);    values_op(0).assign((long)ASSIGN);  values_op(1).assign((long)ADD);  values_op(2).assign((long)MULTIPLY);  values_op(3).assign((long)ADD);  math6.setNumOperands(4);  math6.setOperation(values_op);  math6.setFunction(values);  math6.setWeight(L"1.0, 1.0, 1.0, 1.0");  math6.setConstant(0.0);  input.setLength(4);  input(0).makeMatrixComplexFloat().assign(2, 2, L"1.0 + 1.0j, 2.0 + 2.0j, 3.0 + 3.0j, 4.0 + 4.0j");  input(1).makeMatrixComplexFloat().assign(2, 2, L"1.0 + 1.0j, 3.0 - 3.0j, 5.0 + 5.0j, 7.0 - 7.0j");  input(2).makeMatrixComplexFloat().assign(2, 2, L"2.0 + 2.0j, 4.0 + 4.0j, 6.0 + 6.0j, 8.0 + 8.0j");  input(3).makeMatrixComplexFloat().assign(2, 2, L"3.0 + 3.0j, 4.0 + 4.0j, 5.0 + 5.0j, 6.0 + 6.0j");  MatrixComplexFloat result_mat_cf;  math6.compute(output, input);    result_mat_cf.assign(2, 2, L"22.5 + 25.5j, 49 + 55j, 57.25 + 62.75j, 111.25 + 160.75j");    if (!(result_mat_cf).almostEqual(output.getMatrixComplexFloat())) {    output.debug(L"output");    result_mat_cf.debug(L"result");    return Error::handle(name(), L"apply", Error::TEST,                         __FILE__, __LINE__);  }   // test scalar addition  //  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar addition (1):\n");  }  input.setLength(2);  input(0).makeVectorComplexFloat().assign(L"4.0 + 4.0j");  input(1).makeVectorComplexFloat().assign(L"1.0 + 1.0j, 2.0 + 2.0j, 3.0 - 3.0j, 4.0 - 4.0j");  values.setLength(2);  values(0).assign((long)IDENTITY);  values(1).assign((long)IDENTITY);  values_op.setLength(2);  values_op(0).assign((long)ASSIGN);  values_op(1).assign((long)ADD);  math7.setFunction(values);  math7.setOperation(values_op);  math7.compute(output, input);  VectorComplexFloat expected_cf(L"5.0 + 5.0j, 6.0 + 6.0j, 7.0 + 1.0j, 8.0");  if (!output.getVectorComplexFloat().almostEqual(expected_cf)) {    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  /*    if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar addition (2):\n");    }    input(0).makeVectorComplexFloat().assign(L"1.0 + 1.0j, 2.0 + 2.0j, 3.0 - 3.0j, 4.0 - 4.0j");    input(1).makeVectorComplexFloat().assign(L"4.0 + 4.0j");     math7.compute(output, input);    if (!output.getVectorComplexFloat().almostEqual(expected_cf)) {    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);    }    if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar addition (3):\n");    }      MatrixComplexFloat a(3, 3);    a.setDiagonal(complexfloat(4.0, 4.0));    MatrixComplexFloat b(3, 3);    b.assign(complexfloat(7.0, 7.0));    b.setDiagonal(complexfloat(11.0, 11.0));    input(0).makeVectorComplexFloat().assign(L"7.0+7.0j");    input(1).makeMatrixComplexFloat().assign(a);      math7.compute(output, input);    if (!output.getMatrixComplexFloat().almostEqual(b)) {    output.debug(L"output");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);    }      if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar addition (4):\n");    }        input(0).makeMatrixComplexFloat().assign(a);    input(1).makeVectorComplexFloat().assign(L"7.0+7.0j");        math7.compute(output, input);    if (!output.getMatrixComplexFloat().almostEqual(b)) {    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);    }  */    // test scalar subtraction  //  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar subtraction (1):\n");  }    input.setLength(2);  input(0).makeVectorComplexFloat().assign(L"4.0 + 4.0j");  input(1).makeVectorComplexFloat().assign(L"1.0 + 1.0j, 2.0 + 2.0j, 3.0 - 3.0j, 4.0 - 4.0j");  values.setLength(2);  values(0).assign((long)IDENTITY);  values(1).assign((long)IDENTITY);  math7.setFunction(values);    values_op.setLength(2);  values_op(0).assign((long)ASSIGN);  values_op(1).assign((long)SUBTRACT);  math7.setOperation(values_op);    math7.compute(output, input);  expected_cf.assign(L"3.0 + 3.0j, 2.0 + 2.0j, 1.0 + 7.0j, 8.0j");  if (!output.getVectorComplexFloat().almostEqual(expected_cf)) {    output.debug(L"output");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  input(0).makeVectorComplexFloat().assign(L"1.0 + 1.0j, 2.0 + 2.0j, 3.0 - 3.0j, 4.0 - 4.0j");  input(1).makeVectorComplexFloat().assign(L"4.0 + 4.0j");    math7.compute(output, input);  expected_cf.assign(L"-3.0 -3.0j, -2.0 - 2.0j, -1.0 - 7.0j, -8.0j");  if (!output.getVectorComplexFloat().almostEqual(expected_cf)) {    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  /*    if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar subtraction (2):\n");    }      a.clear(Integral::RETAIN);    a.setDiagonal(complexfloat(4.0, 4.0));    b.clear(Integral::RETAIN);    b.assign(complexfloat(7.0, 7.0));    b.setDiagonal(complexfloat(11.0, 11.0));    input(0).makeVectorComplexFloat().assign(L"7.0+7.0j");    input(1).makeMatrixComplexFloat().assign(a);    math7.compute(output, input);    b.assign(complexfloat(7.0, 7.0));    b.setDiagonal(complexfloat(3.0, 3.0));      if (!output.getMatrixComplexFloat().almostEqual(b)) {    output.debug(L"output");    b.debug(L"b");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);    }    if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar subtraction (3):\n");    }      input(0).makeMatrixComplexFloat().assign(a);    input(1).makeVectorComplexFloat().assign(L"7.0+7.0j");    b.assign(complexfloat(-7.0, -7.0));    b.setDiagonal(complexfl

⌨️ 快捷键说明

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