[Libreoffice-commits] core.git: sc/inc sc/source
dante (via logerrit)
logerrit at kemper.freedesktop.org
Thu May 13 16:37:49 UTC 2021
sc/inc/matrixoperators.hxx | 2 -
sc/inc/scmatrix.hxx | 21 ++++++++++---------
sc/source/core/tool/interpr5.cxx | 2 -
sc/source/core/tool/interpr6.cxx | 4 +--
sc/source/core/tool/matrixoperators.cxx | 2 -
sc/source/core/tool/scmatrix.cxx | 34 ++++++++++++++++----------------
6 files changed, 33 insertions(+), 32 deletions(-)
New commits:
commit c9de441f84ad4641662f2ce510868f3e3164a22f
Author: dante <dante19031999 at gmail.com>
AuthorDate: Wed May 12 11:17:57 2021 +0200
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Thu May 13 18:37:03 2021 +0200
Use double to iterate products in scmatrix.
Change-Id: If094c33d396dc5aba31b37a3042add72076f344f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115468
Reviewed-by: Eike Rathke <erack at redhat.com>
Tested-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/sc/inc/matrixoperators.hxx b/sc/inc/matrixoperators.hxx
index 36fa1cabe3d6..813813626350 100644
--- a/sc/inc/matrixoperators.hxx
+++ b/sc/inc/matrixoperators.hxx
@@ -48,7 +48,7 @@ struct SumSquare
struct Product
{
static const double InitVal;
- void operator()(KahanSum& rAccum, double fVal) const;
+ void operator()(double& rAccum, double fVal) const;
};
}
diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index 463b15e17b42..c91253811398 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -140,29 +140,30 @@ public:
* summation algorithm,
* https://en.wikipedia.org/wiki/Kahan_summation_algorithm
*/
- struct IterateResult
+ struct IterateResultMultiple
{
double mfFirst;
double mfRest;
size_t mnCount;
- IterateResult(double fFirst, double fRest, size_t nCount) :
+ IterateResultMultiple(double fFirst, double fRest, size_t nCount) :
mfFirst(fFirst), mfRest(fRest), mnCount(nCount) {}
};
/**
- * Version of IterateResult for using Kahan sum.
+ * Iterator for executing one operation with the matrix data.
*/
- struct KahanIterateResult
+ template<typename tRes>
+ struct IterateResult
{
- KahanSum maAccumulator;
+ tRes maAccumulator;
size_t mnCount;
- KahanIterateResult(double fAccumulator, size_t nCount)
+ IterateResult(tRes fAccumulator, size_t nCount)
: maAccumulator(fAccumulator), mnCount(nCount) {}
-
- double get() const { return maAccumulator.get(); }
};
+ typedef IterateResult<KahanSum> KahanIterateResult;
+ typedef IterateResult<double> DoubleIterateResult;
/** Checks nC or nR for zero and uses GetElementsMax() whether a matrix of
@@ -378,7 +379,7 @@ public:
KahanIterateResult Sum( bool bTextAsZero, bool bIgnoreErrorValues = false ) const ;
KahanIterateResult SumSquare( bool bTextAsZero, bool bIgnoreErrorValues = false ) const ;
- KahanIterateResult Product( bool bTextAsZero, bool bIgnoreErrorValues = false ) const ;
+ DoubleIterateResult Product( bool bTextAsZero, bool bIgnoreErrorValues = false ) const ;
size_t Count(bool bCountStrings, bool bCountErrors, bool bIgnoreEmptyStrings = false) const ;
size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const ;
size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const ;
@@ -410,7 +411,7 @@ public:
void DivOp(bool bFlag, double fVal, const ScMatrix& rMat) ;
void PowOp(bool bFlag, double fVal, const ScMatrix& rMat) ;
- std::vector<ScMatrix::IterateResult> Collect(const std::vector<sc::op::Op>& aOp) ;
+ std::vector<ScMatrix::IterateResultMultiple> Collect(const std::vector<sc::op::Op>& aOp) ;
void ExecuteOperation(const std::pair<size_t, size_t>& rStartPos, const std::pair<size_t, size_t>& rEndPos,
DoubleOpFunction aDoubleFunc, BoolOpFunction aBoolFunc, StringOpFunction aStringFunc,
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index 613c467cbdc2..1e16518ae8da 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -1853,7 +1853,7 @@ void ScInterpreter::ScSumXMY2()
}
else
{
- PushDouble(pResMat->SumSquare(false).get());
+ PushDouble(pResMat->SumSquare(false).maAccumulator.get());
}
}
diff --git a/sc/source/core/tool/interpr6.cxx b/sc/source/core/tool/interpr6.cxx
index 0e2824ef1f2e..1c7ed73d5c93 100644
--- a/sc/source/core/tool/interpr6.cxx
+++ b/sc/source/core/tool/interpr6.cxx
@@ -403,8 +403,8 @@ static void IterateMatrix(
break;
case ifPRODUCT:
{
- ScMatrix::KahanIterateResult aRes = pMat->Product(bTextAsZero, bIgnoreErrVal);
- fRes *= aRes.get();
+ ScMatrix::DoubleIterateResult aRes = pMat->Product(bTextAsZero, bIgnoreErrVal);
+ fRes *= aRes.maAccumulator;
rCount += aRes.mnCount;
}
break;
diff --git a/sc/source/core/tool/matrixoperators.cxx b/sc/source/core/tool/matrixoperators.cxx
index e65d4d7c0dc2..780f789ed94f 100644
--- a/sc/source/core/tool/matrixoperators.cxx
+++ b/sc/source/core/tool/matrixoperators.cxx
@@ -19,7 +19,7 @@ void SumSquare::operator()(KahanSum& rAccum, double fVal) const { rAccum += fVal
const double SumSquare::InitVal = 0.0;
-void Product::operator()(KahanSum& rAccum, double fVal) const { rAccum *= fVal; }
+void Product::operator()(double& rAccum, double fVal) const { rAccum *= fVal; }
const double Product::InitVal = 1.0;
}
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index a10863ea3a53..d3c8667c66c1 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -304,7 +304,7 @@ public:
ScMatrix::KahanIterateResult Sum( bool bTextAsZero, bool bIgnoreErrorValues ) const;
ScMatrix::KahanIterateResult SumSquare( bool bTextAsZero, bool bIgnoreErrorValues ) const;
- ScMatrix::KahanIterateResult Product( bool bTextAsZero, bool bIgnoreErrorValues ) const;
+ ScMatrix::DoubleIterateResult Product( bool bTextAsZero, bool bIgnoreErrorValues ) const;
size_t Count(bool bCountStrings, bool bCountErrors, bool bIgnoreEmptyStrings) const;
size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const;
size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const;
@@ -328,7 +328,7 @@ public:
const ScMatrix::EmptyOpFunction& aEmptyFunc) const;
template<typename T>
- std::vector<ScMatrix::IterateResult> ApplyCollectOperation(const std::vector<T>& aOp);
+ std::vector<ScMatrix::IterateResultMultiple> ApplyCollectOperation(const std::vector<T>& aOp);
void MatConcat(SCSIZE nMaxCol, SCSIZE nMaxRow, const ScMatrixRef& xMat1, const ScMatrixRef& xMat2,
SvNumberFormatter& rFormatter, svl::SharedStringPool& rPool);
@@ -1107,11 +1107,11 @@ double ScMatrixImpl::Xor() const
namespace {
-template<typename Op>
+template<typename Op, typename tRes>
class WalkElementBlocks
{
Op maOp;
- ScMatrix::KahanIterateResult maRes;
+ ScMatrix::IterateResult<tRes> maRes;
bool mbTextAsZero:1;
bool mbIgnoreErrorValues:1;
public:
@@ -1120,7 +1120,7 @@ public:
mbTextAsZero(bTextAsZero), mbIgnoreErrorValues(bIgnoreErrorValues)
{}
- const ScMatrix::KahanIterateResult& getResult() const { return maRes; }
+ const ScMatrix::IterateResult<tRes>& getResult() const { return maRes; }
void operator() (const MatrixImplType::element_block_node_type& node)
{
@@ -1173,7 +1173,7 @@ template<typename Op>
class WalkElementBlocksMultipleValues
{
const std::vector<Op>* mpOp;
- std::vector<ScMatrix::IterateResult> maRes;
+ std::vector<ScMatrix::IterateResultMultiple> maRes;
bool mbFirst:1;
public:
WalkElementBlocksMultipleValues(const std::vector<Op>& aOp) :
@@ -1200,7 +1200,7 @@ public:
return *this;
}
- const std::vector<ScMatrix::IterateResult>& getResult() const { return maRes; }
+ const std::vector<ScMatrix::IterateResultMultiple>& getResult() const { return maRes; }
void operator() (const MatrixImplType::element_block_node_type& node)
{
@@ -2080,10 +2080,10 @@ public:
namespace {
-template<typename TOp>
-ScMatrix::KahanIterateResult GetValueWithCount(bool bTextAsZero, bool bIgnoreErrorValues, const MatrixImplType& maMat)
+template<typename TOp, typename tRes>
+ScMatrix::IterateResult<tRes> GetValueWithCount(bool bTextAsZero, bool bIgnoreErrorValues, const MatrixImplType& maMat)
{
- WalkElementBlocks<TOp> aFunc(bTextAsZero, bIgnoreErrorValues);
+ WalkElementBlocks<TOp, tRes> aFunc(bTextAsZero, bIgnoreErrorValues);
aFunc = maMat.walk(aFunc);
return aFunc.getResult();
}
@@ -2092,17 +2092,17 @@ ScMatrix::KahanIterateResult GetValueWithCount(bool bTextAsZero, bool bIgnoreErr
ScMatrix::KahanIterateResult ScMatrixImpl::Sum(bool bTextAsZero, bool bIgnoreErrorValues) const
{
- return GetValueWithCount<sc::op::Sum>(bTextAsZero, bIgnoreErrorValues, maMat);
+ return GetValueWithCount<sc::op::Sum, KahanSum>(bTextAsZero, bIgnoreErrorValues, maMat);
}
ScMatrix::KahanIterateResult ScMatrixImpl::SumSquare(bool bTextAsZero, bool bIgnoreErrorValues) const
{
- return GetValueWithCount<sc::op::SumSquare>(bTextAsZero, bIgnoreErrorValues, maMat);
+ return GetValueWithCount<sc::op::SumSquare, KahanSum>(bTextAsZero, bIgnoreErrorValues, maMat);
}
-ScMatrix::KahanIterateResult ScMatrixImpl::Product(bool bTextAsZero, bool bIgnoreErrorValues) const
+ScMatrix::DoubleIterateResult ScMatrixImpl::Product(bool bTextAsZero, bool bIgnoreErrorValues) const
{
- return GetValueWithCount<sc::op::Product>(bTextAsZero, bIgnoreErrorValues, maMat);
+ return GetValueWithCount<sc::op::Product, double>(bTextAsZero, bIgnoreErrorValues, maMat);
}
size_t ScMatrixImpl::Count(bool bCountStrings, bool bCountErrors, bool bIgnoreEmptyStrings) const
@@ -2423,7 +2423,7 @@ void ScMatrixImpl::ApplyOperation(T aOp, ScMatrixImpl& rMat)
}
template<typename T>
-std::vector<ScMatrix::IterateResult> ScMatrixImpl::ApplyCollectOperation(const std::vector<T>& aOp)
+std::vector<ScMatrix::IterateResultMultiple> ScMatrixImpl::ApplyCollectOperation(const std::vector<T>& aOp)
{
WalkElementBlocksMultipleValues<T> aFunc(aOp);
aFunc = maMat.walk(std::move(aFunc));
@@ -3218,7 +3218,7 @@ ScMatrix::KahanIterateResult ScMatrix::SumSquare(bool bTextAsZero, bool bIgnoreE
return pImpl->SumSquare(bTextAsZero, bIgnoreErrorValues);
}
-ScMatrix::KahanIterateResult ScMatrix::Product(bool bTextAsZero, bool bIgnoreErrorValues) const
+ScMatrix::DoubleIterateResult ScMatrix::Product(bool bTextAsZero, bool bIgnoreErrorValues) const
{
return pImpl->Product(bTextAsZero, bIgnoreErrorValues);
}
@@ -3425,7 +3425,7 @@ void ScMatrix::ExecuteOperation(const std::pair<size_t, size_t>& rStartPos,
pImpl->ExecuteOperation(rStartPos, rEndPos, aDoubleFunc, aBoolFunc, aStringFunc, aEmptyFunc);
}
-std::vector<ScMatrix::IterateResult> ScMatrix::Collect(const std::vector<sc::op::Op>& aOp)
+std::vector<ScMatrix::IterateResultMultiple> ScMatrix::Collect(const std::vector<sc::op::Op>& aOp)
{
return pImpl->ApplyCollectOperation(aOp);
}
More information about the Libreoffice-commits
mailing list