📄 math_07.cc
字号:
// file: $isip/class/algo/Math/math_07.cc// version: $Id: math_07.cc,v 1.2 2002/04/01 20:04:13 gao Exp $//// isip include files//#include "Math.h"// method: computeFuncCalcEnumerateFloat//// 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 VectorFloat splitted// by number of operands. These can be VectorFloat. 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::computeFuncCalcEnumerateFloat(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"computeFuncCalcEnumerateFloat", Error::ARG, __FILE__, __LINE__); } // compute the number of combinations // if (num_operands_d != input_a.length()) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", 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_FLOAT) && (input_a(j).getDataType() != AlgorithmData::MATRIX_FLOAT)) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", Error::ARG, __FILE__, __LINE__); } } // set the mode of output // if (input_a(0).getDataType() == AlgorithmData::VECTOR_FLOAT) { output_a.makeVectorFloat(); } else { output_a.makeMatrixFloat(); } // 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_FLOAT) { tmp_input.makeVectorFloat().assign(input_a(j).getVectorFloat()); } else { tmp_input.makeMatrixFloat().assign(input_a(j).getMatrixFloat()); } // 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_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().exp(); } // function: EXP2 // else if (function_d(j) == (long)EXP2) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().exp2(); } // function: EXP10 // else if (function_d(j) == (long)EXP10) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().exp10(); } // function: FACTORIAL // else if (function_d(j) == (long)FACTORIAL) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().factorial(); } // function: LOG // else if (function_d(j) == (long)LOG) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } // check vector elements // for (long index = tmp_input.getVectorFloat().length() - 1; index >= 0; index--) { if (tmp_input.getVectorFloat()(index) <= (float)0.0 ) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", Error::ARG, __FILE__, __LINE__); } } tmp_input.getVectorFloat().log(); } // function: LOG2 // else if (function_d(j) == (long)LOG2) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } // check vector elements // for (long index = tmp_input.getVectorFloat().length() - 1; index >= 0; index--) { if (tmp_input.getVectorFloat()(index) <= (float)0.0 ) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", Error::ARG, __FILE__, __LINE__); } } tmp_input.getVectorFloat().log2(); } // function: LOG10 // else if (function_d(j) == (long)LOG10) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } // check vector elements // for (long index = tmp_input.getVectorFloat().length() - 1; index >= 0; index--) { if (tmp_input.getVectorFloat()(index) <= (float)0.0 ) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", Error::ARG, __FILE__, __LINE__); } } tmp_input.getVectorFloat().log10(); } // function: LOG1P // else if (function_d(j) == (long)LOG1P) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } // check vector elements // for (long index = tmp_input.getVectorFloat().length() - 1; index >= 0; index--) { if (tmp_input.getVectorFloat()(index) <= (float)0.0 ) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", Error::ARG, __FILE__, __LINE__); } } tmp_input.getVectorFloat().log1p(); } // function: ABS // else if (function_d(j) == (long)ABS) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().abs(); } // function: NEG // else if (function_d(j) == (long)NEG) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { tmp_input.getVectorFloat().neg(); } else if (input_a(j).getDataType() != AlgorithmData::MATRIX_FLOAT) { tmp_input.getMatrixFloat().neg(); } else { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", Error::ARG, __FILE__, __LINE__); } } // function: ROUND // else if (function_d(j) == (long)ROUND) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().round(); } // function: CEIL // else if (function_d(j) == (long)CEIL) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().ceil(); } // function: FLOOR // else if (function_d(j) == (long)FLOOR) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().floor(); } // function: RFLOOR // else if (function_d(j) == (long)RFLOOR) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().rfloor(); } // function: SIN // else if (function_d(j) == (long)SIN) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().sin(); } // function: COS // else if (function_d(j) == (long)COS) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().cos(); } // function: TAN // else if (function_d(j) == (long)TAN) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().tan(); } // function: ASIN // else if (function_d(j) == (long)ASIN) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().asin(); } // function: ACOS // else if (function_d(j) == (long)ACOS) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().acos(); } // function: ATAN // else if (function_d(j) == (long)ATAN) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().atan(); } // function: SQUARE // else if (function_d(j) == (long)SQUARE) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().square(); } // function: SQRT // else if (function_d(j) == (long)SQRT) { if (input_a(j).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getVectorFloat().sqrt(); } // function: INVERSE // else if (function_d(j) == (long)INVERSE) { if (input_a(j).getDataType() != AlgorithmData::MATRIX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getMatrixFloat().inverse(); } // function: TRANSPOSE // else if (function_d(j) == (long)TRANSPOSE) { if (input_a(j).getDataType() != AlgorithmData::MATRIX_FLOAT) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_FNDTYP, __FILE__, __LINE__); } tmp_input.getMatrixFloat().transpose(); } // invalid function // else { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_UNKFUN, __FILE__, __LINE__); } // apply weight // if (input_a(j).getDataType() == AlgorithmData::VECTOR_FLOAT) { tmp_input.getVectorFloat().mult(weight_d(j)); } else if (input_a(j).getDataType() == AlgorithmData::MATRIX_FLOAT) { tmp_input.getMatrixFloat().mult(weight_d(j)); } else { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", Error::ARG, __FILE__, __LINE__); } // branch on operation: // Operation: ASSIGN // if (operation_d(j) == (long)ASSIGN) { // this operation is possible between same data types // // tmp_output.getVectorFloat().assign(tmp_input.getVectorFloat()); if (output_a.getDataType() != input_a(j).getDataType()) { return Error::handle(name(), L"computeFuncCalcEnumerateFloat", ERR_MATCH, __FILE__, __LINE__); } if (output_a.getDataType() == AlgorithmData::VECTOR_FLOAT) { output_a.makeVectorFloat().assign(tmp_input.getVectorFloat()); } else { output_a.makeMatrixFloat().assign(tmp_input.getMatrixFloat()); } } // Operation: ADD //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -