about summary refs log tree commit diff
path: root/pkgs/applications/science/machine-learning
diff options
context:
space:
mode:
authorSebastián Mancilla <smancill@smancill.dev>2021-11-08 22:58:00 -0300
committerSebastián Mancilla <smancill@smancill.dev>2021-11-09 00:27:13 -0300
commit203db44ed420cb4032b1a8b57a70f5177255cc9e (patch)
tree77bde9ef2c0fff87430eb814f6cad11e37199f74 /pkgs/applications/science/machine-learning
parent82568e67187dcfbdd9536e4fb82cebac90c01ea3 (diff)
shogun: fix compile errors with Eigen 3.4
Fixes #142811.
Diffstat (limited to 'pkgs/applications/science/machine-learning')
-rw-r--r--pkgs/applications/science/machine-learning/shogun/default.nix3
-rw-r--r--pkgs/applications/science/machine-learning/shogun/eigen-3.4.patch74
2 files changed, 77 insertions, 0 deletions
diff --git a/pkgs/applications/science/machine-learning/shogun/default.nix b/pkgs/applications/science/machine-learning/shogun/default.nix
index 06a799b5182ec..911d0043ed267 100644
--- a/pkgs/applications/science/machine-learning/shogun/default.nix
+++ b/pkgs/applications/science/machine-learning/shogun/default.nix
@@ -95,6 +95,9 @@ stdenv.mkDerivation rec {
       sha256 = "sha256-AgJJKQA8vc5oKaTQDqMdwBR4hT4sn9+uW0jLe7GteJw=";
     })
 
+    # Fix compile errors with Eigen 3.4
+    ./eigen-3.4.patch
+
   ] ++ lib.optional (!withSvmLight) ./svmlight-scrubber.patch;
 
   nativeBuildInputs = [ cmake swig ctags ]
diff --git a/pkgs/applications/science/machine-learning/shogun/eigen-3.4.patch b/pkgs/applications/science/machine-learning/shogun/eigen-3.4.patch
new file mode 100644
index 0000000000000..863bd75918b0f
--- /dev/null
+++ b/pkgs/applications/science/machine-learning/shogun/eigen-3.4.patch
@@ -0,0 +1,74 @@
+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;