Skip to content

Commit

Permalink
Merge pull request #5 from pharo-ai/speed-up-clustering
Browse files Browse the repository at this point in the history
Speed up clustering
  • Loading branch information
jecisc committed Jan 11, 2024
2 parents ba29b69 + a9189cf commit 35e7355
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/AI-HierarchicalClustering/AIClusteringData.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ AIClusteringData >> findMinimum [
"This method is written such that it uses primitives only."

| columnVector |
value := AIUnlimited positive.
value := Float infinity.
2
to: indices size
do:
Expand Down
14 changes: 7 additions & 7 deletions src/AI-HierarchicalClustering/AIClusteringVector.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ AIClusteringVector >> min [

{ #category : #accessing }
AIClusteringVector >> unsetAt: index [
super at: index put: AIUnlimited positive.
super at: index put: Float infinity.
found = index ifTrue: [ found := nil ]
]

{ #category : #private }
AIClusteringVector >> update [
min := AIUnlimited positive.
self
doWithIndex: [ :each :ind |
each < min
ifTrue: [ min := each.
found := ind ] ]

min := Float infinity.
self doWithIndex: [ :each :ind | "This was originally `each < min` but a lot of time we compare a float to an integer and it is faster to ask a float to compare itself to an integer than the other way around because it tries to cast the float as a fraction."
min >= each ifTrue: [
min := each.
found := ind ] ]
]
2 changes: 1 addition & 1 deletion src/AI-HierarchicalClustering/AICorrelationVector.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ AICorrelationVector >> defaultElement [
AICorrelationVector >> min [

^(self reject: #isNil)
inject: AIUnlimited positive
inject: Float infinity
into: [:each :min | min min: each]
]

Expand Down

0 comments on commit 35e7355

Please sign in to comment.