Skip to content

Commit e5d491e

Browse files
committed
Fix typos & remove commented-out code
1 parent 9d99a47 commit e5d491e

File tree

2 files changed

+12
-59
lines changed

2 files changed

+12
-59
lines changed

src/gleam_community/maths.gleam

+11-59
Original file line numberDiff line numberDiff line change
@@ -332,20 +332,6 @@ pub fn weighted_sum(arr: List(#(Float, Float))) -> Result(Float, Nil) {
332332
}
333333
}
334334

335-
// let weight_is_negative = list.any(arr, fn(tuple) { tuple.1 <. 0.0 })
336-
337-
// case weight_is_negative {
338-
// True -> Error(Nil)
339-
// False -> {
340-
// let weighted_sum =
341-
// list.fold(arr, 0.0, fn(acc, a) { a.0 *. a.1 +. acc })
342-
// Ok(weighted_sum)
343-
// }
344-
// }
345-
// }
346-
// }
347-
// }
348-
349335
/// <div style="text-align: right;">
350336
/// <a href="https://github.com/gleam-community/maths/issues">
351337
/// <small>Spot a typo? Open an issue!</small>
@@ -2170,7 +2156,7 @@ pub fn absolute_difference(a: Float, b: Float) -> Float {
21702156
/// \\]
21712157
///
21722158
/// The function takes two inputs \\(x\\) and \\(y\\) and returns a positive integer
2173-
/// value which is the the absolute difference of the inputs.
2159+
/// value which is the absolute difference of the inputs.
21742160
///
21752161
/// <details>
21762162
/// <summary>Example:</summary>
@@ -3363,7 +3349,7 @@ pub fn norm(arr: List(Float), p: Float) -> Result(Float, Nil) {
33633349
[] -> Ok(0.0)
33643350
_ -> {
33653351
case p {
3366-
// Handle the the special case when 'p' is equal to zero. In this case, we compute a
3352+
// Handle the special case when 'p' is equal to zero. In this case, we compute a
33673353
// pseudo-norm, which is the number of non-zero elements in the given list 'arr'
33683354
0.0 ->
33693355
Ok(
@@ -3473,7 +3459,7 @@ pub fn norm_with_weights(
34733459
False -> {
34743460
case p {
34753461
0.0 -> {
3476-
// Handle the the special case when 'p' is equal to zero. In this case, we compute
3462+
// Handle the special case when 'p' is equal to zero. In this case, we compute
34773463
// a pseudo-norm, which is the number of non-zero elements in the given list 'arr'
34783464
Ok(
34793465
list.fold(arr, 0.0, fn(acc, tuple) {
@@ -3931,7 +3917,7 @@ pub fn chebyshev_distance_with_weights(
39313917
/// </a>
39323918
/// </div>
39333919
///
3934-
/// Calculcate the n'th moment about the mean of a list of elements.
3920+
/// Calculate the n'th moment about the mean of a list of elements.
39353921
///
39363922
/// <details>
39373923
/// <summary>Example:</summary>
@@ -3968,40 +3954,6 @@ pub fn chebyshev_distance_with_weights(
39683954
/// </a>
39693955
/// </div>
39703956
///
3971-
// pub fn moment(arr: List(Float), n: Int) -> Result(Float, Nil) {
3972-
// case list.length(arr), n {
3973-
// 0, _ -> Error(Nil)
3974-
// // 0th moment is always 1.0
3975-
// __, 0 -> Ok(1.0)
3976-
// // 1st moment (about the mean) is 0.0 by definition
3977-
// _, 1 -> Ok(0.0)
3978-
// _, n if n >= 0 -> {
3979-
// // Check if the list has enough elements for the nth moment
3980-
// case list.length(arr) >= n {
3981-
// True -> {
3982-
// // Usage of let assert: The function 'mean' will only return an error if the given list
3983-
// // is emptry. No error will occur since we already checked that the list is non-empty.
3984-
// let assert Ok(m1) = mean(arr)
3985-
// let result =
3986-
// list.try_fold(arr, 0.0, fn(acc, a) {
3987-
// case float.power(a -. m1, int.to_float(n)) {
3988-
// Error(Nil) -> Error(Nil)
3989-
// Ok(value) -> Ok(value +. acc)
3990-
// }
3991-
// })
3992-
// case result {
3993-
// Error(Nil) -> Error(Nil)
3994-
// Ok(value) -> Ok(value /. int.to_float(list.length(arr)))
3995-
// }
3996-
// }
3997-
// // Not enough elements for meaningful computation
3998-
// False -> Error(Nil)
3999-
// }
4000-
// }
4001-
// _, _ -> Error(Nil)
4002-
// }
4003-
// }
4004-
40053957
pub fn moment(arr: List(Float), n: Int) -> Result(Float, Nil) {
40063958
case arr, n {
40073959
// Handle empty list: no moments can be calculated
@@ -4089,7 +4041,7 @@ pub fn mean(arr: List(Float)) -> Result(Float, Nil) {
40894041
/// </a>
40904042
/// </div>
40914043
///
4092-
/// Calculcate the harmonic mean \\(\bar{x}\\) of the elements in a list:
4044+
/// Calculate the harmonic mean \\(\bar{x}\\) of the elements in a list:
40934045
///
40944046
/// \\[
40954047
/// \bar{x} = \frac{n}{\sum_{i=1}^{n}\frac{1}{x_i}}
@@ -4158,7 +4110,7 @@ pub fn harmonic_mean(arr: List(Float)) -> Result(Float, Nil) {
41584110
/// </a>
41594111
/// </div>
41604112
///
4161-
/// Calculcate the geometric mean \\(\bar{x}\\) of the elements in a list:
4113+
/// Calculate the geometric mean \\(\bar{x}\\) of the elements in a list:
41624114
///
41634115
/// \\[
41644116
/// \bar{x} = \left(\prod^{n}_{i=1} x_i\right)^{\frac{1}{n}}
@@ -4414,7 +4366,7 @@ pub fn standard_deviation(arr: List(Float), ddof: Int) -> Result(Float, Nil) {
44144366
/// </a>
44154367
/// </div>
44164368
///
4417-
/// Calculcate the sample kurtosis of a list of elements using the
4369+
/// Calculate the sample kurtosis of a list of elements using the
44184370
/// definition of Fisher.
44194371
///
44204372
/// <details>
@@ -4469,7 +4421,7 @@ pub fn kurtosis(arr: List(Float)) -> Result(Float, Nil) {
44694421
/// </a>
44704422
/// </div>
44714423
///
4472-
/// Calculcate the sample skewness of a list of elements using the
4424+
/// Calculate the sample skewness of a list of elements using the
44734425
/// Fisher-Pearson coefficient of skewness.
44744426
///
44754427
/// <details>
@@ -5296,7 +5248,7 @@ pub fn canberra_distance(arr: List(#(Float, Float))) -> Result(Float, Nil) {
52965248
/// import gleam_community/maths
52975249
///
52985250
/// pub fn example() {
5299-
/// maths.canberra_distance([])
5251+
/// maths.canberra_distance_with_weights([])
53005252
/// |> should.be_error()
53015253
///
53025254
/// maths.canberra_distance_with_weights([#(1.0, -2.0, 0.5), #(2.0, -1.0, 1.0)])
@@ -5365,8 +5317,8 @@ pub fn canberra_distance_with_weights(
53655317
/// maths.canberra_distance([])
53665318
/// |> should.be_error()
53675319
///
5368-
/// maths.canberra_distance_with_weights([#(1.0, -2.0, 0.5), #(2.0, -1.0, 1.0)])
5369-
/// |> should.equal(Ok(1.5))
5320+
/// maths.braycurtis_distance([#(1.0, 3.0), #(2.0, 4.0)])
5321+
/// |> should.equal(Ok(0.4))
53705322
/// }
53715323
/// </details>
53725324
///

test/gleam_community/metrics_test.gleam

+1
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ pub fn braycurtis_distance_test() {
974974
// Try different types of valid input
975975
maths.braycurtis_distance([#(0.0, 0.0), #(0.0, 0.0)])
976976
|> should.equal(Ok(0.0))
977+
977978
maths.braycurtis_distance([#(1.0, -2.0), #(2.0, -1.0)])
978979
|> should.equal(Ok(3.0))
979980

0 commit comments

Comments
 (0)