Skip to content

Commit

Permalink
Improve memory operation (#78)
Browse files Browse the repository at this point in the history
* edit: getter return const reference

* edit: make clone as const
  • Loading branch information
HPDell authored Nov 17, 2023
1 parent 56d5e4e commit dafda54
Show file tree
Hide file tree
Showing 24 changed files with 120 additions and 89 deletions.
8 changes: 4 additions & 4 deletions include/gwmodelpp/GTWR.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class GTWR : public GWRBase, public IBandwidthSelectable, public IParallelizabl
*
* @return arma::mat 回归系数估计值的标准差。
*/
arma::mat betasSE() { return mBetasSE; }
const arma::mat& betasSE() { return mBetasSE; }

/**
* \~english
Expand All @@ -302,7 +302,7 @@ class GTWR : public GWRBase, public IBandwidthSelectable, public IParallelizabl
*
* @return arma::vec 由 \f$tr(S)\f$ 和 \f$tr(SS^T)\f$ 组成的向量。
*/
arma::vec sHat() { return mSHat; }
const arma::vec& sHat() { return mSHat; }

/**
* \~english
Expand All @@ -315,7 +315,7 @@ class GTWR : public GWRBase, public IBandwidthSelectable, public IParallelizabl
*
* @return arma::vec 矩阵 \f$Q\f$ 的对角线元素。
*/
arma::vec qDiag() { return mQDiag; }
const arma::vec& qDiag() { return mQDiag; }

/**
* \~english
Expand All @@ -328,7 +328,7 @@ class GTWR : public GWRBase, public IBandwidthSelectable, public IParallelizabl
*
* @return arma::mat 帽子矩阵 \f$S\f$。
*/
arma::mat s() { return mS; }
const arma::mat& s() { return mS; }

public: // Implement Algorithm
bool isValid() override;
Expand Down
12 changes: 6 additions & 6 deletions include/gwmodelpp/GWDA.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,35 +173,35 @@ namespace gwm
*
* @return arma::mat \~english The result matrix of geographical weighted discriminant analysis \~chinese 地理加权判别分析结果矩阵
*/
arma::mat res() const { return mRes; }
const arma::mat& res() const { return mRes; }

/**
* @brief \~english Get classification results \~chinese 获取分类结果
*
* @return std::vector<std::string> \~english Classification results \~chinese 分类结果
*/
std::vector<std::string> group() const { return mGroup; }
const std::vector<std::string>& group() const { return mGroup; }

/**
* @brief \~english Get location-wise probabilities \~chinese 获取位置概率
*
* @return arma::mat \~english Location-wise probabilities \~chinese 位置概率
*/
arma::mat probs() const { return mProbs; }
const arma::mat& probs() const { return mProbs; }

/**
* @brief \~english Get max location-wise probabilities \~chinese 获取位置概率最大值
*
* @return arma::mat \~english max location-wise probabilities \~chinese 位置概率最大值
*/
arma::mat pmax() const { return mPmax; }
const arma::mat& pmax() const { return mPmax; }

/**
* @brief \~english Get associated entropy \~chinese 获取相关熵
*
* @return arma::mat \~english Associated entropy \~chinese 相关熵
*/
arma::mat entropy() const { return mEntropy; }
const arma::mat& entropy() const { return mEntropy; }

/**
* \~english
Expand Down Expand Up @@ -344,7 +344,7 @@ namespace gwm
bool isValid() override;

public: // IMultivariableAnalysis
arma::mat variables() const override { return mX; }
const arma::mat& variables() const override { return mX; }
void setVariables(const arma::mat &x) override { mX = x; }
void setGroup(std::vector<std::string> &y) { mY = y; }
void run() override;
Expand Down
8 changes: 4 additions & 4 deletions include/gwmodelpp/GWDR.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class GWDR : public SpatialAlgorithm, public IRegressionAnalysis, public IVarial
*
* @return arma::mat \~english Coefficient estimates \~chinese 回归系数估计值
*/
arma::mat betas() const { return mBetas; }
const arma::mat& betas() const { return mBetas; }

/**
* @brief \~english Get whether has hat matrix. \~chinese 获取是否有帽子矩阵。
Expand Down Expand Up @@ -268,7 +268,7 @@ class GWDR : public SpatialAlgorithm, public IRegressionAnalysis, public IVarial
*
* @return VariablesCriterionList \~english List of criterion values for each variable combination in independent variable selection \~chinese 变量优选过程中每种变量组合对应的指标值列表
*/
VariablesCriterionList indepVarCriterionList() const { return mIndepVarCriterionList; }
const VariablesCriterionList& indepVarCriterionList() const { return mIndepVarCriterionList; }

/**
* @brief \~english Get selected independent variable \~chinese 获取选中的变量组合
Expand Down Expand Up @@ -309,10 +309,10 @@ class GWDR : public SpatialAlgorithm, public IRegressionAnalysis, public IVarial
bool isValid() override;

public: // IRegressionAnalysis
virtual arma::vec dependentVariable() const override { return mY; }
virtual const arma::vec& dependentVariable() const override { return mY; }
virtual void setDependentVariable(const arma::vec& y) override { mY = y; }

virtual arma::mat independentVariables() const override { return mX; }
virtual const arma::mat& independentVariables() const override { return mX; }
virtual void setIndependentVariables(const arma::mat& x) override { mX = x; }

virtual bool hasIntercept() const override { return mHasIntercept; }
Expand Down
10 changes: 5 additions & 5 deletions include/gwmodelpp/GWPCA.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,31 @@ class GWPCA: public SpatialMonoscaleAlgorithm, public IMultivariableAnalysis
*
* @return arma::mat \~english Local Principle Values matrix \~chinese 局部主成分值
*/
arma::mat localPV() { return mLocalPV; }
const arma::mat& localPV() { return mLocalPV; }

/**
* @brief \~english Get the Loadings matrix. \~chinese 获取局部载荷矩阵。
*
* @return arma::mat \~english Loadings matrix \~chinese 局部载荷矩阵
*/
arma::cube loadings() { return mLoadings; }
const arma::cube& loadings() { return mLoadings; }

/**
* @brief \~english Get the Standard deviation matrix. \~chinese 获取标准差矩阵。
*
* @return arma::mat \~english Standard deviation matrix \~chinese 标准差矩阵
*/
arma::mat sdev() { return mSDev; }
const arma::mat& sdev() { return mSDev; }

/**
* @brief \~english Get the Scores matrix. \~chinese 获取得分矩阵。
*
* @return arma::mat \~english Scores matrix \~chinese 得分矩阵
*/
arma::cube scores() { return mScores; }
const arma::cube& scores() { return mScores; }

public: // IMultivariableAnalysis
virtual arma::mat variables() const override { return mX; }
virtual const arma::mat& variables() const override { return mX; }
virtual void setVariables(const arma::mat& x) override { mX = x; }
virtual void run() override;

Expand Down
6 changes: 3 additions & 3 deletions include/gwmodelpp/GWRBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ class GWRBase : public SpatialMonoscaleAlgorithm, public IRegressionAnalysis
* @return arma::mat 回归系数估计值。
*
*/
arma::mat betas() const { return mBetas; }
const arma::mat& betas() const { return mBetas; }

public: // Implement IRegressionAnalysis
virtual arma::vec dependentVariable() const override { return mY; }
virtual const arma::vec& dependentVariable() const override { return mY; }
virtual void setDependentVariable(const arma::vec& y) override { mY = y; }

virtual arma::mat independentVariables() const override { return mX; }
virtual const arma::mat& independentVariables() const override { return mX; }
virtual void setIndependentVariables(const arma::mat& x) override { mX = x; }

virtual bool hasIntercept() const override { return mHasIntercept; }
Expand Down
12 changes: 6 additions & 6 deletions include/gwmodelpp/GWRBasic.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class GWRBasic : public GWRBase, public IBandwidthSelectable, public IVarialbeSe
*
* @return VariablesCriterionList 变量优选过程的指标值列表。
*/
VariablesCriterionList indepVarsSelectionCriterionList() const { return mIndepVarsSelectionCriterionList; }
const VariablesCriterionList& indepVarsSelectionCriterionList() const { return mIndepVarsSelectionCriterionList; }

/**
* \~english
Expand All @@ -279,7 +279,7 @@ class GWRBasic : public GWRBase, public IBandwidthSelectable, public IVarialbeSe
*
* @return BandwidthCriterionList 带宽优选过程的指标值列表。
*/
BandwidthCriterionList bandwidthSelectionCriterionList() const { return mBandwidthSelectionCriterionList; }
const BandwidthCriterionList& bandwidthSelectionCriterionList() const { return mBandwidthSelectionCriterionList; }

/**
* \~english
Expand Down Expand Up @@ -320,7 +320,7 @@ class GWRBasic : public GWRBase, public IBandwidthSelectable, public IVarialbeSe
*
* @return arma::mat 回归系数估计值的标准差。
*/
arma::mat betasSE() { return mBetasSE; }
const arma::mat& betasSE() { return mBetasSE; }

/**
* \~english
Expand All @@ -333,7 +333,7 @@ class GWRBasic : public GWRBase, public IBandwidthSelectable, public IVarialbeSe
*
* @return arma::vec 由 \f$tr(S)\f$ 和 \f$tr(SS^T)\f$ 组成的向量。
*/
arma::vec sHat() { return mSHat; }
const arma::vec& sHat() { return mSHat; }

/**
* \~english
Expand All @@ -346,7 +346,7 @@ class GWRBasic : public GWRBase, public IBandwidthSelectable, public IVarialbeSe
*
* @return arma::vec 矩阵 \f$Q\f$ 的对角线元素。
*/
arma::vec qDiag() { return mQDiag; }
const arma::vec& qDiag() { return mQDiag; }

/**
* \~english
Expand All @@ -359,7 +359,7 @@ class GWRBasic : public GWRBase, public IBandwidthSelectable, public IVarialbeSe
*
* @return arma::mat 帽子矩阵 \f$S\f$。
*/
arma::mat s() { return mS; }
const arma::mat& s() { return mS; }


public: // Implement Algorithm
Expand Down
8 changes: 4 additions & 4 deletions include/gwmodelpp/GWRGeneralized.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ class GWRGeneralized : public GWRBase, public IBandwidthSelectable, public IPara
*/
void setMaxiter(std::size_t maxiter);

arma::mat getWtMat1() const;
const arma::mat& getWtMat1() const;

arma::mat getWtMat2() const;
const arma::mat& getWtMat2() const;

/**
* @brief \~english Get the diagnostic information. \~chinese 获取诊断信息。
Expand Down Expand Up @@ -467,12 +467,12 @@ inline size_t GWRGeneralized::getMaxiter() const
return mMaxiter;
}

inline arma::mat GWRGeneralized::getWtMat1() const
inline const arma::mat& GWRGeneralized::getWtMat1() const
{
return mWtMat1;
}

inline arma::mat GWRGeneralized::getWtMat2() const
inline const arma::mat& GWRGeneralized::getWtMat2() const
{
return mWtMat2;
}
Expand Down
2 changes: 1 addition & 1 deletion include/gwmodelpp/GWRLocalCollinearity.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class GWRLocalCollinearity : public GWRBase, public IBandwidthSelectable, public
*
* @return BandwidthCriterionList \~english List of criterion values for each bandwidth value \~chinese 每种带宽对应的指标值列表
*/
BandwidthCriterionList bandwidthSelectionCriterionList() const
const BandwidthCriterionList& bandwidthSelectionCriterionList() const
{
return mBandwidthSelectionCriterionList;
}
Expand Down
14 changes: 7 additions & 7 deletions include/gwmodelpp/GWRMultiscale.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class GWRMultiscale : public SpatialMultiscaleAlgorithm, public IBandwidthSelect
*
* @return std::vector<BandwidthInitilizeType> 带宽初始化值类型。
*/
std::vector<BandwidthInitilizeType> bandwidthInitilize() const { return GWRMultiscale::mBandwidthInitilize; }
const std::vector<BandwidthInitilizeType>& bandwidthInitilize() const { return GWRMultiscale::mBandwidthInitilize; }

/**
* \~english
Expand All @@ -302,7 +302,7 @@ class GWRMultiscale : public SpatialMultiscaleAlgorithm, public IBandwidthSelect
*
* @return std::vector<BandwidthSelectionCriterionType> 带宽选择方法。
*/
std::vector<BandwidthSelectionCriterionType> bandwidthSelectionApproach() const { return GWRMultiscale::mBandwidthSelectionApproach; }
const std::vector<BandwidthSelectionCriterionType>& bandwidthSelectionApproach() const { return GWRMultiscale::mBandwidthSelectionApproach; }

/**
* \~english
Expand All @@ -328,7 +328,7 @@ class GWRMultiscale : public SpatialMultiscaleAlgorithm, public IBandwidthSelect
*
* @return std::vector<bool> 是否中心化变量。
*/
std::vector<bool> preditorCentered() const { return mPreditorCentered; }
const std::vector<bool>& preditorCentered() const { return mPreditorCentered; }

/**
* \~english
Expand All @@ -354,7 +354,7 @@ class GWRMultiscale : public SpatialMultiscaleAlgorithm, public IBandwidthSelect
*
* @return std::vector<double> 带宽选择阈值。
*/
std::vector<double> bandwidthSelectThreshold() const { return mBandwidthSelectThreshold; }
const std::vector<double>& bandwidthSelectThreshold() const { return mBandwidthSelectThreshold; }

/**
* \~english
Expand Down Expand Up @@ -538,7 +538,7 @@ class GWRMultiscale : public SpatialMultiscaleAlgorithm, public IBandwidthSelect
*
* @return arma::mat 回归系数估计值 \f$\beta\f$。
*/
arma::mat betas() const { return mBetas; }
const arma::mat& betas() const { return mBetas; }

/**
* \~english
Expand Down Expand Up @@ -587,10 +587,10 @@ class GWRMultiscale : public SpatialMultiscaleAlgorithm, public IBandwidthSelect


public: // IRegressionAnalysis interface
virtual arma::vec dependentVariable() const override { return mY; }
virtual const arma::vec& dependentVariable() const override { return mY; }
virtual void setDependentVariable(const arma::vec& y) override { mY = y; }

virtual arma::mat independentVariables() const override { return mX; }
virtual const arma::mat& independentVariables() const override { return mX; }
virtual void setIndependentVariables(const arma::mat& x) override { mX = x; }

virtual bool hasIntercept() const override { return mHasIntercept; }
Expand Down
Loading

0 comments on commit dafda54

Please sign in to comment.