quick start:g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_algo.a #include <Math.h> Math(); Math(const Math& arg); const String& className() const; boolean setNumOperands(long num); boolean setFunction(const String& functions); boolean setOperation(const String& operations); boolean compute(VectorFloat& output, const VectorFloat& input);
description:// compute Y = 2.0 * X1 + 3.0 * X2 + 2.0 // Math math; math.setConstant(2.0); math.setWeight(L"2.0, 3.0"); VectorFloat input; VectorFloat output; VectorFloat result; input.assign(L"1.1, 4.0, 1.5, 2.3, 1.0, 1.0, 0.0, 0.0"); math.compute(output, input);
static const String CLASS_NAME = L"LinearTransform";
enum ALGORITHM { FUNCTION_CALCULATOR = 0, DEF_ALGORITHM = FUNCTION_CALCULATOR };
enum IMPLEMENTATION { ENUMERATE = 0, DEF_IMPLEMENTATION = ENUMERATE };
enum OPERATION { ASSIGN = 0, ADD, SUBTRACT, MULTIPLY, DIVIDE, DEF_OPERATION = ASSIGN };
enum FUNCTION { IDENTITY = 0, ABS, ACOS, ASIN, ATAN, CEIL, COS, EXP, EXP2, EXP10, FACTORIAL, FLOOR, IMAG, INVERSE, LOG, LOG2, LOG10, LOG1P, MAG, NEG, REAL, RFLOOR, ROUND, SIN, SQRT, SQUARE, TAN, TRANSPOSE };
static const NameMap ALGO_MAP = L"FUNCTION_CALCULATOR";
static const NameMap IMPL_MAP = L"ENUMERATE";
static const NameMap OPERATION_MAP = L"ADD, SUBTRACT, MULTIPLY, DIVIDE, ASSIGN";
static const NameMap FUNCTION_MAP = L"IDENTITY, EXP, EXP2, EXP10, FACTORIAL, LOG,LOG2, LOG10, LOG1P, ABS, NEG, ROUND, CEIL, FLOOR, RFLOOR, SIN, COS, TAN, ASIN, ACOS, ATAN, SQRT, SQUARE, TRANSPOSE, INVERSE";
static const String PARAM_NUMBER = L"num_operands";
static const String PARAM_ALGORTITHM = L"algorithm";
static const String PARAM_IMPLEMENTATION = L"implementation";
static const String PARAM_CONST = L"constant";
static const String PARAM_FUNCTION = L"function";
static const String PARAM_OPERATION = L"operation";
static const String PARAM_WEIGHT = L"weight";
static const String DELIM = L",";
static const long DEF_NUM_OPERANDS = 2;
static const float DEF_CONST = 0.0;
static const AlgorithmData::COEF_TYPE DEF_COEF_TYPE = AlgorithmData::DEF_CTYPE;
static const long ERR = 71300;
static const long ERR_UNKFUN = 71301;
static const long ERR_UNKOPE = 71302;
static const long ERR_FNDTYP = 71303;
static const long ERR_MATCH = 71304;
ALGORITHM algorithm_d;
IMPLEMENTATION implementation_d;
Long num_operands_d;
VectorLong function_d;
VectorLong operation_d;
VectorFloat weight_d;
Float const_d;
static MemoryManager mgr_d;
static const String& name();
static boolean diagnose(Integral::DEBUG debug_level);
boolean debug(const unichar* message) const;
~Math();
Math((ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, long num_operands_d = DEF_NUM_OPERANDS);
Math(const Math& arg);
Math& operator= (const Math& arg);
long sofSize() const;
boolean read(Sof& sof, long tag);
boolean write(Sof& sof, long tag) const;
boolean readData(Sof& sof, String& pname,long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);
boolean writeData(Sof& sof, const String& pname) const;
boolean eq(const Math& arg) const;
static void* operator new(size_t size);
static void* operator new[](size_t size);
static void operator delete(void* ptr);
static void operator delete[](void* ptr);
static boolean setGrowSize(long grow_size);
boolean clear(Integral::CMODE ctype = Integral::DEF_CMODE);
boolean setAlgorithm(ALGORITHM algorithm);
boolean setImplementation(IMPLEMENTATION implementation);
boolean setNumOperands(long num);
boolean setOperation(const VectorLong& operation);
boolean setOperation(OPERATION operation, long index);
boolean setOperation(const String& operations);
boolean setFunction(const VectorLong& function);
boolean setFunction(FUNCTION function, long index);
boolean setFunction(const String& functions);
boolean setWeight(const VectorFloat& weight);
boolean setConstant(float constant);
boolean set(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, long num_operands = DEF_NUM_OPERANDS);
ALGORITHM getAlgorithm();
IMPLEMENTATION getImplementation();
long getNumOperands();
const VectorLong& getOperation() const;
boolean getOperation(String& operation) const;
const VectorLong& getFunction() const;
boolean getFunction(String& function) const;
const VectorFloat& getWeight() const;
float getConstant() const;
boolean get(ALGORITHM& algorithm, IMPLEMENTATION& implementation, long& num_operands) const;
boolean compute(AlgorithmData& output, const Vector<AlgorithmData>& input, AlgorithmData::COEF_TYPE input_coef_type = AlgorithmData::UNKNOWN, long index = DEF_CHANNEL_INDEX);
boolean assign(const AlgorithmBase& arg);
boolean eq(const AlgorithmBase& arg) const;
const String& className() const;
boolean apply(Vector<AlgorithmData>& output, const Vector<AlgorithmData>& input);
boolean setParser(SofParser* parser);
boolean readDataCommon(Sof& sof, const String& pname, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);
boolean writeDataCommon(Sof& sof, const String& pname);
boolean computeFuncCalcEnumerate(VectorFloat& output, const VectorFloat& input);
boolean computeFuncCalcEnumerateFloat(VectorFloat& output, const VectorFloat& input);
boolean computeFuncCalcEnumerateDouble(VectorFloat& output, const VectorFloat& input);
boolean computeFuncCalcEnumerateCFloat(VectorFloat& output, const VectorFloat& input);
boolean computeFuncCalcEnumerateCDouble(VectorFloat& output, const VectorFloat& input);
boolean computeAddFloat(AlgorithmData& output, const AlgorithmData& input);
boolean computeSubFloat(AlgorithmData& output, const AlgorithmData& input);
boolean computeMultFloat(AlgorithmData& output, const AlgorithmData& input);
boolean computeDivFloat(AlgorithmData& output, const AlgorithmData& input);
boolean computeAddCFloat(AlgorithmData& output, const AlgorithmData& input);
boolean computeSubCFloat(AlgorithmData& output, const AlgorithmData& input);
boolean computeMultCFloat(AlgorithmData& output, const AlgorithmData& input);
boolean computeDivCFloat(AlgorithmData& output, const AlgorithmData& input);
boolean computeAddDouble(AlgorithmData& output, const AlgorithmData& input);
boolean computeSubDouble(AlgorithmData& output, const AlgorithmData& input);
boolean computeMultDouble(AlgorithmData& output, const AlgorithmData& input);
boolean computeDivDouble(AlgorithmData& output, const AlgorithmData& input);
boolean computeAddCDouble(AlgorithmData& output, const AlgorithmData& input);
boolean computeSubCDouble(AlgorithmData& output, const AlgorithmData& input);
boolean computeMultCDouble(AlgorithmData& output, const AlgorithmData& input);
boolean computeDivCDouble(AlgorithmData& output, const AlgorithmData& input);
// isip include files // #include <Math.h> // main program starts here // compute Y = X1 + X2 - log(X3) - exp(X4) // int main(int argc, const char **argv) { // declare a Math object // Math math; // set the number of operands and weights for each operand // math.setNumOperands(4); math.setWeight(L"1.0, 2.0, 1.0, 1.0"); // declare and set the functions // VectorLong values(4); values(0).assign((long)Math::IDENTITY); values(1).assign((long)Math::IDENTITY); values(2).assign((long)Math::LOG); values(3).assign((long)Math::EXP); math.setFunction(values); // declare and set the operations // VectorLong values_op(4); values_op(0).assign((long)Math::ASSIGN); values_op(1).assign((long)Math::ADD); values_op(2).assign((long)Math::SUBTRACT); values_op(3).assign((long)Math::SUBTRACT); math.setOperation(values_op); // declare the input, output and the expected result // Vectorinput; AlgorithmData output; VectorFloat result; // set the input object // input.setLength(4); input(0).makeVectorFloat().assign(L"1.1, 4.0"); input(1).makeVectorFloat().assign(L"1.5, 2.3"); input(2).makeVectorFloat().assign(L"1.0, 1.0"); input(3).makeVectorFloat().assign(L"0.0, 0.0"); // compute the output object // math.compute(output, input); // error if the expected output is not equal to the actual output // result.assign(L"3.1, 7.6"); if (!result.almostEqual(output.getVectorFloat())) { input.debug(L"input:"); output.debug(L"actual output:"); result.debug(L"expected output:"); return Error::handle(math.name(), L"compute", Error::TEST, __FILE__, __LINE__); } // print the input and output to console // input.debug(L"input:"); output.debug(L"actual output:"); // exit gracefully // Integral::exit(); }
// isip include files // #include// main program starts here // compute Y = X0 + square(X1) + exp(X2) + 0.5 // int main(int argc, const char **argv) { // declare a Math object // Math math; // set the number of operands, weights for each operand and constant // value // math.setNumOperands(3); math.setWeight(L"1.0, 2.0, 1.0"); math.setConstant(0.5); // declare and set the functions // VectorLong values(3); values(0).assign((long)Math::IDENTITY); values(1).assign((long)Math::SQUARE); values(2).assign((long)Math::EXP); math.setFunction(values); // declare and set the operations // VectorLong values_op(3); values_op(0).assign((long)Math::ASSIGN); values_op(1).assign((long)Math::ADD); values_op(2).assign((long)Math::ADD); math.setOperation(values_op); // declare the input, output and the expected result // Vector input; AlgorithmData output; VectorComplexFloat result; // set the input object // input.setLength(3); 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"); // compute the output object // math.compute(output, input); // error if the expected output is not equal to the actual output // result.assign(L"2.56869+12.3874j, 5.46869+27.4474j"); if (!result.almostEqual(output.getVectorComplexFloat())) { input.debug(L"input:"); output.debug(L"actual output:"); result.debug(L"expected output:"); return Error::handle(math.name(), L"compute", Error::TEST, __FILE__, __LINE__); } // print the input and output to console // input.debug(L"input:"); output.debug(L"output:"); // exit gracefully // Integral::exit(); }