[Libreoffice-commits] .: Branch 'feature/matrix-new-backend' - 2 commits - sc/inc sc/qa sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Tue Jul 17 12:02:43 PDT 2012


 sc/inc/scmatrix.hxx              |    2 ++
 sc/qa/unit/ucalc.cxx             |    2 +-
 sc/source/core/tool/scmatrix.cxx |   22 ++++++++++++++++++++--
 3 files changed, 23 insertions(+), 3 deletions(-)

New commits:
commit 55c3f3567be46155781d3cebfe3dc0a56182d067
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Jul 17 15:02:05 2012 -0400

    Support resizing matrix with a default value.
    
    Change-Id: Ibb5cf4d09b67426021f6d158878afd8386f22555

diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index d6d3e15..984561e 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -238,6 +238,8 @@ public:
      */
     void Resize( SCSIZE nC, SCSIZE nR);
 
+    void Resize(SCSIZE nC, SCSIZE nR, double fVal);
+
     /** Clone the matrix and extend it to the new size. nNewCols and nNewRows
         MUST be at least of the size of the original matrix. */
     ScMatrix* CloneAndExtend(SCSIZE nNewCols, SCSIZE nNewRows) const;
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 2c1006c..ef7c916 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -1233,7 +1233,7 @@ void Test::testMatrix()
     SCSIZE nC, nR;
     pMat->GetDimensions(nC, nR);
     CPPUNIT_ASSERT_MESSAGE("matrix is not empty", nC == 0 && nR == 0);
-    pMat->Resize(4, 10);
+    pMat->Resize(4, 10, 0.0);
     pMat->GetDimensions(nC, nR);
     CPPUNIT_ASSERT_MESSAGE("matrix size is not as expected", nC == 4 && nR == 10);
     CPPUNIT_ASSERT_MESSAGE("both 'and' and 'or' should evaluate to false",
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 9e35843..3b1aecb 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -388,6 +388,7 @@ public:
     void SetImmutable(bool bVal);
     bool IsImmutable() const;
     void Resize(SCSIZE nC, SCSIZE nR);
+    void Resize(SCSIZE nC, SCSIZE nR, double fVal);
     void SetErrorInterpreter( ScInterpreter* p);
     ScInterpreter* GetErrorInterpreter() const { return pErrorInterpreter; }
 
@@ -475,6 +476,11 @@ void ScMatrixImpl::Resize(SCSIZE nC, SCSIZE nR)
     maMat.resize(nR, nC);
 }
 
+void ScMatrixImpl::Resize(SCSIZE nC, SCSIZE nR, double fVal)
+{
+    maMat.resize(nR, nC, fVal);
+}
+
 void ScMatrixImpl::SetErrorInterpreter( ScInterpreter* p)
 {
     pErrorInterpreter = p;
@@ -1154,6 +1160,11 @@ void ScMatrix::Resize( SCSIZE nC, SCSIZE nR)
     pImpl->Resize(nC, nR);
 }
 
+void ScMatrix::Resize(SCSIZE nC, SCSIZE nR, double fVal)
+{
+    pImpl->Resize(nC, nR, fVal);
+}
+
 ScMatrix* ScMatrix::CloneAndExtend(SCSIZE nNewCols, SCSIZE nNewRows) const
 {
     ScMatrix* pScMat = new ScMatrix(nNewCols, nNewRows);
commit 0c881781d30055c588b21bb87b4491be5c3e1172
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Jul 17 13:57:43 2012 -0400

    For sum product, the initial accumulator value should be 1, not 0.
    
    Change-Id: I16ce22150627f75eab08cc4d58fc63a76572c010

diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 67f2ffb..9e35843 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -960,6 +960,8 @@ namespace {
 
 struct SumOp
 {
+    static const double initVal = 0.0;
+
     void operator() (double& rAccum, double fVal)
     {
         rAccum += fVal;
@@ -968,6 +970,8 @@ struct SumOp
 
 struct SumSquareOp
 {
+    static const double initVal = 0.0;
+
     void operator() (double& rAccum, double fVal)
     {
         rAccum += fVal*fVal;
@@ -976,6 +980,8 @@ struct SumSquareOp
 
 struct ProductOp
 {
+    static const double initVal = 1.0;
+
     void operator() (double& rAccum, double fVal)
     {
         rAccum *= fVal;
@@ -991,7 +997,7 @@ class WalkElementBlocks : std::unary_function<MatrixImplType::element_block_node
     bool mbFirst:1;
     bool mbTextAsZero:1;
 public:
-    WalkElementBlocks(bool bTextAsZero) : maRes(0.0, 0.0, 0), mbFirst(true), mbTextAsZero(bTextAsZero) {}
+    WalkElementBlocks(bool bTextAsZero) : maRes(0.0, _Op::initVal, 0), mbFirst(true), mbTextAsZero(bTextAsZero) {}
 
     const ScMatrix::IterateResult& getResult() const { return maRes; }
 
@@ -1092,7 +1098,8 @@ ScMatrix::IterateResult ScMatrixImpl::Product(bool bTextAsZero) const
 {
     WalkElementBlocks<ProductOp> aFunc(bTextAsZero);
     maMat.walk(aFunc);
-    return aFunc.getResult();
+    ScMatrix::IterateResult aRes = aFunc.getResult();
+    return aRes;
 }
 
 size_t ScMatrixImpl::Count(bool bCountStrings) const


More information about the Libreoffice-commits mailing list