📄 math_09.cc
字号:
// file: $isip/class/algo/Math/math_09.cc// version: $Id: math_09.cc,v 1.2 2002/04/01 20:04:14 gao Exp $//// isip include files//#include "Math.h"// method: computeFuncCalcEnumerateCFloat//// arguments:// AlgorithmData& output: (output) output data// const Vector<AlgorithmData>& input: (input) input data//// return: a boolean value indicating status//// this method implements following function:// Y = operation(0) {a(0)*function(0)(X(0))} operation(1)// {a(1)*function(1)(X(1))} operation(2) {a(2)*function(2)(X(2))}...// ... + const,// where X(0), X(1), ... are the parts of input VectorComplexFloat splitted// by number of operands. These can be VectorComplexFloat. If// user wants to implement this for scalar or single vector, then// number of operands will be 1. For scalar input the length of the// input vector will be 1.//boolean Math::computeFuncCalcEnumerateCFloat(AlgorithmData& output_a, const Vector<AlgorithmData>& input_a) { // check algorithm and implementation names // if ((algorithm_d != FUNCTION_CALCULATOR) || (implementation_d != ENUMERATE)) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", Error::ARG, __FILE__, __LINE__); } // compute the number of combinations // if (num_operands_d != input_a.length()) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", Error::ARG, __FILE__, __LINE__); } // input should be either vector or matrix // for (long j = 0; j < num_operands_d; j++) { if ((input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) && (input_a(j).getDataType() != AlgorithmData::MATRIX_COMPLEX_FLOAT)) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", Error::ARG, __FILE__, __LINE__); } } // special case for one complex operation such as mag, real and imag // if (num_operands_d == (long)1) { if (function_d(0) == (long)MAG) { input_a(0).getVectorComplexFloat().mag(output_a.makeVectorFloat()); output_a.getVectorFloat().add((float)const_d); return true; } else if (function_d(0) == (long)REAL) { input_a(0).getVectorComplexFloat().real(output_a.makeVectorFloat()); output_a.getVectorFloat().add((float)const_d); return true; } else if (function_d(0) == (long)IMAG) { input_a(0).getVectorComplexFloat().imag(output_a.makeVectorFloat()); output_a.getVectorFloat().add((float)const_d); return true; } } // set the mode of output // if (input_a(0).getDataType() == AlgorithmData::VECTOR_COMPLEX_FLOAT) { output_a.makeVectorComplexFloat(); } else { output_a.makeMatrixComplexFloat(); } // loop over the number of input operands // for (long j = 0; j < num_operands_d; j++) { // declare temporary input variable // AlgorithmData tmp_input; // set the type to either matrix or vector, depending upon the // type of the input // if (input_a(j).getDataType() == AlgorithmData::VECTOR_COMPLEX_FLOAT) { tmp_input.makeVectorComplexFloat().assign(input_a(j).getVectorComplexFloat()); } else { tmp_input.makeMatrixComplexFloat().assign(input_a(j).getMatrixComplexFloat()); } // branch on function: // apply function and corresponding weight // if (function_d(j) == (long)IDENTITY) { // do nothing // } // function: EXP // else if (function_d(j) == (long)EXP) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().exp(); } // function: EXP2 // else if (function_d(j) == (long)EXP2) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().exp2(); } // function: EXP10 // else if (function_d(j) == (long)EXP10) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().exp10(); } // function: FACTORIAL // else if (function_d(j) == (long)FACTORIAL) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().factorial(); } // function: LOG // else if (function_d(j) == (long)LOG) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } // check vector elements // for (long index = tmp_input.getVectorComplexFloat().length() - 1; index >= 0; index--) { if (tmp_input.getVectorComplexFloat()(index) <= (float)0.0 ) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", Error::ARG, __FILE__, __LINE__); } } tmp_input.getVectorComplexFloat().log(); } // function: LOG2 // else if (function_d(j) == (long)LOG2) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } // check vector elements // for (long index = tmp_input.getVectorComplexFloat().length() - 1; index >= 0; index--) { if (tmp_input.getVectorComplexFloat()(index) <= (float)0.0 ) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", Error::ARG, __FILE__, __LINE__); } } tmp_input.getVectorComplexFloat().log2(); } // function: LOG10 // else if (function_d(j) == (long)LOG10) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } // check vector elements // for (long index = tmp_input.getVectorComplexFloat().length() - 1; index >= 0; index--) { if (tmp_input.getVectorComplexFloat()(index) <= (float)0.0 ) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", Error::ARG, __FILE__, __LINE__); } } tmp_input.getVectorComplexFloat().log10(); } // function: LOG1P // else if (function_d(j) == (long)LOG1P) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } // check vector elements // for (long index = tmp_input.getVectorComplexFloat().length() - 1; index >= 0; index--) { if (tmp_input.getVectorComplexFloat()(index) <= (float)0.0 ) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", Error::ARG, __FILE__, __LINE__); } } tmp_input.getVectorComplexFloat().log1p(); } // function: ABS // else if (function_d(j) == (long)ABS) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_UNKFUN, __FILE__, __LINE__); } // function: NEG // else if (function_d(j) == (long)NEG) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { tmp_input.getVectorComplexFloat().neg(); } else if (input_a(j).getDataType() != AlgorithmData::MATRIX_COMPLEX_FLOAT) { tmp_input.getMatrixComplexFloat().neg(); } else { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", Error::ARG, __FILE__, __LINE__); } } // function: ROUND // else if (function_d(j) == (long)ROUND) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().round(); } // function: CEIL // else if (function_d(j) == (long)CEIL) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().ceil(); } // function: FLOOR // else if (function_d(j) == (long)FLOOR) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().floor(); } // function: RFLOOR // else if (function_d(j) == (long)RFLOOR) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().rfloor(); } // function: SIN // else if (function_d(j) == (long)SIN) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().sin(); } // function: COS // else if (function_d(j) == (long)COS) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().cos(); } // function: TAN // else if (function_d(j) == (long)TAN) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().tan(); } // function: ASIN // else if (function_d(j) == (long)ASIN) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().asin(); } // function: ACOS // else if (function_d(j) == (long)ACOS) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().acos(); } // function: ATAN // else if (function_d(j) == (long)ATAN) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().atan(); } // function: SQUARE // else if (function_d(j) == (long)SQUARE) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().square(); } // function: SQRT // else if (function_d(j) == (long)SQRT) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorComplexFloat().sqrt(); } // function: INVERSE // else if (function_d(j) == (long)INVERSE) { if (input_a(j).getDataType() != AlgorithmData::MATRIX_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getMatrixComplexFloat().inverse(); } // function: TRANSPOSE // else if (function_d(j) == (long)TRANSPOSE) { if (input_a(j).getDataType() != AlgorithmData::MATRIX_COMPLEX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getMatrixComplexFloat().transpose(); } // invalid function // else { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_UNKFUN, __FILE__, __LINE__); } // apply weight // if (input_a(j).getDataType() == AlgorithmData::VECTOR_COMPLEX_FLOAT) { tmp_input.getVectorComplexFloat().mult(complexfloat(weight_d(j))); } else if (input_a(j).getDataType() == AlgorithmData::MATRIX_COMPLEX_FLOAT) { tmp_input.getMatrixComplexFloat().mult(complexfloat(weight_d(j))); } else { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", Error::ARG, __FILE__, __LINE__); } // branch on operation: // Operation: ASSIGN // if (operation_d(j) == (long)ASSIGN) { // this operation is possible between same data types // if (output_a.getDataType() != input_a(j).getDataType()) { return Error::handle(name(), L"computeFuncCalcEnumerateCFloat", ERR_MATCH, __FILE__, __LINE__);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -