Skip to content

Commit 9201d20

Browse files
committed
Merge branch 'release/1.2.1'
2 parents 6ca13f3 + 63b3e36 commit 9201d20

File tree

6 files changed

+95
-10
lines changed

6 files changed

+95
-10
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
1.2.1
2+
- Fixed an issue in multiprocessing code.
3+
14
1.2.0
25
- Multiprocessing (by loisaidasam)
36
- Python 3 support

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Untar the archive::
1818
tar xf <filename.tar.gz>
1919

2020
Next, go to the folder just created. It will have the same name as the package
21-
(for example "cluster-1.2.0") and run::
21+
(for example "cluster-1.2.1") and run::
2222

2323
python setup.py install
2424

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
DESCRIPTION
22
===========
33

4+
.. image:: https://readthedocs.org/projects/python-cluster/badge/?version=latest
5+
:target: http://python-cluster.readthedocs.org
6+
:alt: Documentation Status
7+
48
python-cluster is a "simple" package that allows to create several groups
59
(clusters) of objects from a list. It's meant to be flexible and able to
610
cluster any object. To ensure this kind of flexibility, you need not only to
@@ -44,3 +48,8 @@ For K-Means clustering it would look like this::
4448
>>> clusters = cl.getclusters(2)
4549

4650
The parameter passed to getclusters is the count of clusters generated.
51+
52+
53+
.. image:: https://readthedocs.org/projects/python-cluster/badge/?version=latest
54+
:target: http://python-cluster.readthedocs.org
55+
:alt: Documentation Status

cluster/matrix.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ def worker(self):
5858
for task in iter(self.task_queue.get, 'STOP'):
5959
col_index, item, item2 = task
6060
result = (col_index, self.combinfunc(item, item2))
61-
self.task_queue.task_done()
6261
self.done_queue.put(result)
6362
tasks_completed += 1
64-
self.task_queue.task_done()
6563
logger.info("Worker %s performed %s tasks",
6664
current_process().name,
6765
tasks_completed)
@@ -117,7 +115,6 @@ def genmatrix(self, num_processes=1):
117115
# blocking operation)
118116
if num_tasks_queued > num_processes:
119117
col_index, result = self.done_queue.get()
120-
self.done_queue.task_done()
121118
row[col_index] = result
122119
num_tasks_completed += 1
123120
else:
@@ -136,7 +133,6 @@ def genmatrix(self, num_processes=1):
136133
# Grab the remaining worker task results
137134
while num_tasks_completed < num_tasks_queued:
138135
col_index, result = self.done_queue.get()
139-
self.done_queue.task_done()
140136
row[col_index] = result
141137
num_tasks_completed += 1
142138

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='cluster',
13-
version='1.2.0',
13+
version='1.2.1',
1414
author='Michel Albert',
1515
author_email='[email protected]',
1616
url='https://github.com/exhuma/python-cluster',

test.py

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,104 @@ def setUp(self):
7373
self.__data = [791, 956, 676, 124, 564, 84, 24, 365, 594, 940, 398,
7474
971, 131, 365, 542, 336, 518, 835, 134, 391]
7575

76-
def testCluster(self):
76+
def testSingleLinkage(self):
7777
"Basic Hierarchical Clustering test with integers"
7878
cl = HierarchicalClustering(self.__data, lambda x, y: abs(x - y))
79-
cl.cluster()
79+
result = cl.getlevel(40)
80+
81+
# sort the values to make the tests less prone to algorithm changes
82+
result = sorted([sorted(_) for _ in result])
8083
self.assertEqual([
8184
[24],
8285
[84, 124, 131, 134],
8386
[336, 365, 365, 391, 398],
87+
[518, 542, 564, 594],
8488
[676],
85-
[594, 518, 542, 564],
89+
[791],
90+
[835],
8691
[940, 956, 971],
92+
], result)
93+
94+
def testCompleteLinkage(self):
95+
"Basic Hierarchical Clustering test with integers"
96+
cl = HierarchicalClustering(self.__data,
97+
lambda x, y: abs(x - y),
98+
linkage='complete')
99+
result = cl.getlevel(40)
100+
101+
# sort the values to make the tests less prone to algorithm changes
102+
result = sorted([sorted(_) for _ in result])
103+
104+
expected = [
105+
[24],
106+
[84],
107+
[124, 131, 134],
108+
[336, 365, 365],
109+
[391, 398],
110+
[518],
111+
[542, 564],
112+
[594],
113+
[676],
87114
[791],
88115
[835],
89-
], cl.getlevel(40))
116+
[940, 956, 971],
117+
]
118+
self.assertEqual(result, expected)
119+
120+
def testUCLUS(self):
121+
"Basic Hierarchical Clustering test with integers"
122+
cl = HierarchicalClustering(self.__data,
123+
lambda x, y: abs(x - y),
124+
linkage='uclus')
125+
expected = [
126+
[24],
127+
[84],
128+
[124, 131, 134],
129+
[336, 365, 365, 391, 398],
130+
[518, 542, 564],
131+
[594],
132+
[676],
133+
[791],
134+
[835],
135+
[940, 956, 971],
136+
]
137+
result = sorted([sorted(_) for _ in cl.getlevel(40)])
138+
self.assertEqual(result, expected)
139+
140+
def testAverageLinkage(self):
141+
cl = HierarchicalClustering(self.__data,
142+
lambda x, y: abs(x - y),
143+
linkage='average')
144+
# TODO: The current test-data does not really trigger a difference
145+
# between UCLUS and "average" linkage.
146+
expected = [
147+
[24],
148+
[84],
149+
[124, 131, 134],
150+
[336, 365, 365, 391, 398],
151+
[518, 542, 564],
152+
[594],
153+
[676],
154+
[791],
155+
[835],
156+
[940, 956, 971],
157+
]
158+
result = sorted([sorted(_) for _ in cl.getlevel(40)])
159+
self.assertEqual(result, expected)
90160

91161
def testUnmodifiedData(self):
92162
cl = HierarchicalClustering(self.__data, lambda x, y: abs(x - y))
93163
new_data = []
94164
[new_data.extend(_) for _ in cl.getlevel(40)]
95165
self.assertEqual(sorted(new_data), sorted(self.__data))
96166

167+
def testMultiprocessing(self):
168+
cl = HierarchicalClustering(self.__data, lambda x, y: abs(x - y),
169+
num_processes=4)
170+
new_data = []
171+
[new_data.extend(_) for _ in cl.getlevel(40)]
172+
self.assertEqual(sorted(new_data), sorted(self.__data))
173+
97174

98175
class HClusterStringTestCase(unittest.TestCase):
99176

0 commit comments

Comments
 (0)