3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/applications/science/machine-learning/shogun/eigen-3.4.patch
2021-11-09 00:27:13 -03:00

75 lines
3.4 KiB
Diff

From: Sebastián Mancilla <smancill@smancill.dev>
Subject: [PATCH] Fix compile errors when using Eigen 3.4
---
.../machine/gp/MultiLaplaceInferenceMethod.cpp | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/shogun/machine/gp/MultiLaplaceInferenceMethod.cpp b/src/shogun/machine/gp/MultiLaplaceInferenceMethod.cpp
index 2e27678d2..60050afea 100644
--- a/src/shogun/machine/gp/MultiLaplaceInferenceMethod.cpp
+++ b/src/shogun/machine/gp/MultiLaplaceInferenceMethod.cpp
@@ -84,9 +84,9 @@ class CMultiPsiLine : public func_base
float64_t result=0;
for(index_t bl=0; bl<C; bl++)
{
- eigen_f.block(bl*n,0,n,1)=K*alpha->block(bl*n,0,n,1)*CMath::exp(log_scale*2.0);
- result+=alpha->block(bl*n,0,n,1).dot(eigen_f.block(bl*n,0,n,1))/2.0;
- eigen_f.block(bl*n,0,n,1)+=eigen_m;
+ eigen_f.segment(bl*n,n)=K*alpha->segment(bl*n,n)*CMath::exp(log_scale*2.0);
+ result+=alpha->segment(bl*n,n).dot(eigen_f.segment(bl*n,n))/2.0;
+ eigen_f.segment(bl*n,n)+=eigen_m;
}
// get first and second derivatives of log likelihood
@@ -272,7 +272,7 @@ void CMultiLaplaceInferenceMethod::update_alpha()
{
Map<VectorXd> alpha(m_alpha.vector, m_alpha.vlen);
for(index_t bl=0; bl<C; bl++)
- eigen_mu.block(bl*n,0,n,1)=eigen_ktrtr*CMath::exp(m_log_scale*2.0)*alpha.block(bl*n,0,n,1);
+ eigen_mu.segment(bl*n,n)=eigen_ktrtr*CMath::exp(m_log_scale*2.0)*alpha.segment(bl*n,n);
//alpha'*(f-m)/2.0
Psi_New=alpha.dot(eigen_mu)/2.0;
@@ -316,7 +316,7 @@ void CMultiLaplaceInferenceMethod::update_alpha()
for(index_t bl=0; bl<C; bl++)
{
- VectorXd eigen_sD=eigen_dpi.block(bl*n,0,n,1).cwiseSqrt();
+ VectorXd eigen_sD=eigen_dpi.segment(bl*n,n).cwiseSqrt();
LLT<MatrixXd> chol_tmp((eigen_sD*eigen_sD.transpose()).cwiseProduct(eigen_ktrtr*CMath::exp(m_log_scale*2.0))+
MatrixXd::Identity(m_ktrtr.num_rows, m_ktrtr.num_cols));
MatrixXd eigen_L_tmp=chol_tmp.matrixU();
@@ -341,11 +341,11 @@ void CMultiLaplaceInferenceMethod::update_alpha()
VectorXd tmp2=m_tmp.array().rowwise().sum();
for(index_t bl=0; bl<C; bl++)
- eigen_b.block(bl*n,0,n,1)+=eigen_dpi.block(bl*n,0,n,1).cwiseProduct(eigen_mu.block(bl*n,0,n,1)-eigen_mean_bl-tmp2);
+ eigen_b.segment(bl*n,n)+=eigen_dpi.segment(bl*n,n).cwiseProduct(eigen_mu.segment(bl*n,n)-eigen_mean_bl-tmp2);
Map<VectorXd> &eigen_c=eigen_W;
for(index_t bl=0; bl<C; bl++)
- eigen_c.block(bl*n,0,n,1)=eigen_E.block(0,bl*n,n,n)*(eigen_ktrtr*CMath::exp(m_log_scale*2.0)*eigen_b.block(bl*n,0,n,1));
+ eigen_c.segment(bl*n,n)=eigen_E.block(0,bl*n,n,n)*(eigen_ktrtr*CMath::exp(m_log_scale*2.0)*eigen_b.segment(bl*n,n));
Map<MatrixXd> c_tmp(eigen_c.data(),n,C);
@@ -409,7 +409,7 @@ float64_t CMultiLaplaceInferenceMethod::get_derivative_helper(SGMatrix<float64_t
{
result+=((eigen_E.block(0,bl*n,n,n)-eigen_U.block(0,bl*n,n,n).transpose()*eigen_U.block(0,bl*n,n,n)).array()
*eigen_dK.array()).sum();
- result-=(eigen_dK*eigen_alpha.block(bl*n,0,n,1)).dot(eigen_alpha.block(bl*n,0,n,1));
+ result-=(eigen_dK*eigen_alpha.segment(bl*n,n)).dot(eigen_alpha.segment(bl*n,n));
}
return result/2.0;
@@ -489,7 +489,7 @@ SGVector<float64_t> CMultiLaplaceInferenceMethod::get_derivative_wrt_mean(
result[i]=0;
//currently only compute the explicit term
for(index_t bl=0; bl<C; bl++)
- result[i]-=eigen_alpha.block(bl*n,0,n,1).dot(eigen_dmu);
+ result[i]-=eigen_alpha.segment(bl*n,n).dot(eigen_dmu);
}
return result;