Skip to content

Commit 7504e7c

Browse files
committed
refactor:Easier to use &categorize-to-intervals.
1 parent 0dbcfde commit 7504e7c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/ML/SparseMatrixRecommender/Utilities.rakumod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,17 @@ our sub convert-to-wide-form(
5656
our sub categorize-to-intervals(
5757
@vec,
5858
:$breaks is copy = Whatever,
59-
:$probs is copy = Whatever,
60-
Bool :$interval-names = False) returns List {
59+
:probabilities(:$probs) is copy = Whatever,
60+
Bool :$interval-names = False,
61+
Bool:D :p(:$pairs) = False) {
6162
# Validate input vector
6263
die "The first argument is expected to be an array of numeric values."
6364
unless @vec.all ~~ Numeric:D;
6465

6566
# Handle probabilities
6667
my @mprobs = do if $probs.isa(Whatever) {
6768
(^11) >>/>> 10;
68-
} elsif $probs ~~ (Array:D | List:D | Seq:D) && $probs.all ~~ Numeric:D {
69+
} elsif $probs ~~ (Array:D | List:D | Seq:D) && $probs.all ~~ Numeric:D && ([&&] |$probs.map(0*≤1)) {
6970
$probs.unique.sort
7071
} else {
7172
die 'The $probs argument is expected to be a list of probabilities or Whatever.'
@@ -97,5 +98,5 @@ our sub categorize-to-intervals(
9798
}
9899
}
99100

100-
return @res;
101+
return $pairs ?? (@vec Z=> @res) !! @res;
101102
}

0 commit comments

Comments
 (0)