Control: tags -1 + patch

Hi Maintainer

The attached patch fixes the test failures for me.

I noticed in this package's changelog that its only purpose is to work
with cnvkit.  I have not tested whether cnvkit still functions with
this patch in place.

Regards
Graham
Description: Only compare init as a string after determining its type
 Avoids the following with error NumPy 1.26:
 ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Bug-Debian: https://bugs.debian.org/1067233
Author: Graham Inggs <gin...@debian.org>
Last-Update: 2024-04-06

--- a/pomegranate/kmeans.pyx
+++ b/pomegranate/kmeans.pyx
@@ -229,10 +229,6 @@
 
 	def __init__(self, k, init='kmeans++', n_init=10):
 		self.k = k
-		if init != 'first-k':
-			self.n_init = n_init
-		else:
-			self.n_init = 1
 		self.centroid_norms = <double*> calloc(self.k, sizeof(double))
 
 		if isinstance(init, (list, numpy.ndarray)):
@@ -246,8 +242,14 @@
 				self.centroid_norms[i] = self.centroids[i].dot(self.centroids[i])
 
 			self.init = 'fixed'
+			self.n_init = n_init
 		elif isinstance(init, str):
 			self.init = init
+			if init != 'first-k':
+				self.n_init = n_init
+			else:
+				self.n_init = 1
+
 
 	def __dealloc__(self):
 		free(self.centroid_norms)

Reply via email to