sc/source/core/opencl/formulagroupcl.cxx | 38 +++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
New commits: commit 0563f5f43bf244732ef2da32b30470fa2549c072 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Mon Jul 15 11:30:40 2013 -0400 Example code on how to handle input and output for matrix inversion. Right now this code simply puts the original matrix values back. Re-write this code to perform inversion for real. Change-Id: I0330db77b000ed14cc810cc3ddf616e56d036c1b diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index 5f343d9..8de7713 100755 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -57,9 +57,43 @@ public: const ScFormulaCellGroupRef& xGroup, ScTokenArray& rCode); }; -ScMatrixRef FormulaGroupInterpreterOpenCL::inverseMatrix(const ScMatrix& /* rMat */) +ScMatrixRef FormulaGroupInterpreterOpenCL::inverseMatrix(const ScMatrix& rMat) { - return ScMatrixRef(); + SCSIZE nC, nR; + rMat.GetDimensions(nC, nR); + if (nC != nR || nC == 0) + // Input matrix must be square. Return an empty matrix on failure and + // the caller will calculate it via CPU. + return ScMatrixRef(); + + // This vector will contain a series of doubles from the first column to + // the last, chained together in a single array. + std::vector<double> aDoubles; + rMat.GetDoubleArray(aDoubles); + + // TODO: Inverse this matrix and put the result back into xInv. Right now, + // I'll just put the original, non-inversed matrix values back, just to + // demonstrate how to put the values back after inversion. There are two + // ways to put the values back (depending on what the GPU output is). + ScMatrixRef xInv(new ScMatrix(nR, nR, 0.0)); + +#if 0 + // One way is to put the whole value as one array. This method assumes + // that the array size equals column x row, and is oriented column-wise. + // This method is slightly more efficient than the second, but I wouldn't + // expect too much of a difference. + xInv->PutDouble(&aDoubles[0], aDoubles.size(), 0, 0); +#else + // Another way is to put the values one column at a time. + const double* p = &aDoubles[0]; + for (SCSIZE i = 0; i < nC; ++i) + { + xInv->PutDouble(p, nR, i, 0); + p += nR; + } +#endif + + return xInv; } bool FormulaGroupInterpreterOpenCL::interpret(ScDocument& rDoc, const ScAddress& rTopPos, _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits