// Copyright (C) 1999 Jean-Marc Valin #include "BufferedNode.h" #include "Buffer.h" #include "Vector.h" #include "Matrix.h" #include "lapackflow.h" using namespace std; namespace FD { class SolveLS; DECLARE_NODE(SolveLS) /*Node * * @name SolveLS * @category Matrix * @require LapackFlow * @description Solves the min[(A*x-b)**2] least square system * * @input_name A * @input_description The A matrix (M x N) * @input_type Matrix * * @input_name B * @input_description The b vector (M) * @input_type Vector * * @output_name OUTPUT * @output_description Result X (N) * @output_type Vector * END*/ class SolveLS : public BufferedNode { int inputID; int matrixID; int outputID; public: SolveLS(string nodeName, ParameterSet params) : BufferedNode(nodeName, params) { inputID = addInput("B"); matrixID = addInput("A"); outputID = addOutput("OUTPUT"); } void calculate(int output_id, int count, Buffer &out) { ObjectRef inputValue = getInput(inputID, count); ObjectRef matrixValue = getInput(matrixID, count); Vector &in = object_cast > (inputValue); Matrix &mat = object_cast > (matrixValue); int inputLength = mat.nrows(); int outputLength = mat.ncols(); Vector &output = *Vector::alloc(outputLength); out[count] = &output; //if (mat.ncols() != inputLength) // throw new NodeException(this, "matrix columns doesn't match vector length", __FILE__, __LINE__); Matrix mat_copy(mat, 1); int tmp=1; float in_copy[in.size()]; for (int i=0;i