Skip to content

Commit

Permalink
refactor!: Make HClust.cluster arguments clearer
Browse files Browse the repository at this point in the history
Reading `.cluster(elements, 5)` (5 clusters) is clearer than
`.cluster(elements, 2.134)`, so make cutoff a named argument:
`.cluster(element, cutoff: 2.134)`.

BREAKING CHANGE: Method signatures are changed.
  • Loading branch information
franciscoadasme committed Dec 12, 2023
1 parent 457c6bc commit e00db0b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions spec/cluster_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe HClust do
describe ".cluster" do
it "returns grouped values" do
positions = fake_positions
HClust.cluster(positions, 4) { |u, v| euclidean(u, v) }.should eq [
HClust.cluster(positions, cutoff: 4) { |u, v| euclidean(u, v) }.should eq [
[0, 3, 6, 7, 9].map { |i| positions[i] },
[1, 5, 8].map { |i| positions[i] },
[2, 4].map { |i| positions[i] },
Expand All @@ -41,7 +41,7 @@ describe HClust do
describe ".cluster" do
it "returns N grouped values" do
positions = fake_positions
HClust.cluster(positions, into: 2) { |u, v| euclidean(u, v) }.should eq [
HClust.cluster(positions, 2) { |u, v| euclidean(u, v) }.should eq [
[0, 1, 3, 5, 6, 7, 8, 9].map { |i| positions[i] },
[2, 4].map { |i| positions[i] },
]
Expand Down
4 changes: 2 additions & 2 deletions src/hclust/cluster.cr
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ end
# less than or equal to *cutoff*.
def HClust.cluster(
elements : Indexable(T),
*,
cutoff : Number,
rule : Rule = :single,
& : T, T -> Float64
Expand All @@ -68,8 +69,7 @@ end
# rule *rule* based on the distances computed by the given block.
def HClust.cluster(
elements : Indexable(T),
*,
into count : Int,
count : Int,
rule : Rule = :single,
& : T, T -> Float64
) : Array(Array(T)) forall T
Expand Down

0 comments on commit e00db0b

Please sign in to comment.