Skip to content

Commit 2342a84

Browse files
Fix remaining doctests for the f32 inspect change in Nx 0.13
Same formatting-only change as the previous commit, for doctests that diverged after the branch was rebased onto a main that had precision fixes landed since (#354). Values are unchanged, only the number of significant digits Nx prints for f32.
1 parent c43a656 commit 2342a84

12 files changed

Lines changed: 50 additions & 50 deletions

File tree

lib/scholar/covariance/ledoit_wolf.ex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ defmodule Scholar.Covariance.LedoitWolf do
5454
#Nx.Tensor<
5555
f32[2][2]
5656
[
57-
[0.3557686507701874, 0.17340737581253052],
58-
[0.17340737581253052, 1.0300586223602295]
57+
[0.35576865, 0.17340738],
58+
[0.17340738, 1.0300586]
5959
]
6060
>
6161
iex> model.shrinkage
@@ -76,9 +76,9 @@ defmodule Scholar.Covariance.LedoitWolf do
7676
#Nx.Tensor<
7777
f32[3][3]
7878
[
79-
[2.5945029258728027, 1.5078359842300415, 1.1623677015304565],
80-
[1.5078359842300415, 2.106797456741333, 1.1812156438827515],
81-
[1.1623677015304565, 1.1812156438827515, 1.4606266021728516]
79+
[2.594503, 1.507836, 1.1623677],
80+
[1.507836, 2.1067975, 1.1812156],
81+
[1.1623677, 1.1812156, 1.4606266]
8282
]
8383
>
8484
iex> model.shrinkage
@@ -99,9 +99,9 @@ defmodule Scholar.Covariance.LedoitWolf do
9999
#Nx.Tensor<
100100
f32[3][3]
101101
[
102-
[3.8574986457824707, 2.2048025131225586, 2.1504499912261963],
103-
[2.2048025131225586, 2.4572863578796387, 1.7215262651443481],
104-
[2.1504499912261963, 1.7215262651443481, 2.154898166656494]
102+
[3.8574986, 2.2048025, 2.15045],
103+
[2.2048025, 2.4572864, 1.7215263],
104+
[2.15045, 1.7215263, 2.1548982]
105105
]
106106
>
107107
"""

lib/scholar/covariance/shrunk_covariance.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ defmodule Scholar.Covariance.ShrunkCovariance do
5151
#Nx.Tensor<
5252
f32[2][2]
5353
[
54-
[0.7721845507621765, 0.19141492247581482],
55-
[0.19141492247581482, 0.33952537178993225]
54+
[0.77218455, 0.19141492],
55+
[0.19141492, 0.33952537]
5656
]
5757
>
5858
iex> model.location
5959
#Nx.Tensor<
6060
f32[2]
61-
[0.18202415108680725, -0.09216632694005966]
61+
[0.18202415, -0.09216633]
6262
>
6363
iex> key = Nx.Random.key(0)
6464
iex> {x, _new_key} = Nx.Random.multivariate_normal(key, Nx.tensor([0.0, 0.0]), Nx.tensor([[0.8, 0.3], [0.2, 0.4]]), shape: {10}, type: :f32)
@@ -67,8 +67,8 @@ defmodule Scholar.Covariance.ShrunkCovariance do
6767
#Nx.Tensor<
6868
f32[2][2]
6969
[
70-
[0.7000747323036194, 0.1276099532842636],
71-
[0.1276099532842636, 0.41163527965545654]
70+
[0.70007473, 0.12760995],
71+
[0.12760995, 0.41163528]
7272
]
7373
>
7474
iex> model.location

lib/scholar/cross_decomposition/pls_svd.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ defmodule Scholar.CrossDecomposition.PLSSVD do
9090
iex> model.y_std
9191
#Nx.Tensor<
9292
f32[2]
93-
[5.467098712921143, 5.661198616027832]
93+
[5.4670987, 5.6611986]
9494
>
9595
iex> model.x_weights
9696
#Nx.Tensor<

lib/scholar/linear/bayesian_ridge_regression.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ defmodule Scholar.Linear.BayesianRidgeRegression do
214214
iex> model.coefficients
215215
#Nx.Tensor<
216216
f32[1]
217-
[0.9999999403953552]
217+
[0.99999994]
218218
>
219219
iex> model.intercept
220220
#Nx.Tensor<
221221
f32
222-
4.76837158203125e-7
222+
4.7683716e-7
223223
>
224224
"""
225225
deftransform fit(x, y, opts \\ []) do

lib/scholar/metrics/classification.ex

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ defmodule Scholar.Metrics.Classification do
602602
iex> Scholar.Metrics.Classification.balanced_accuracy_score(y_true, y_pred, num_classes: 3)
603603
#Nx.Tensor<
604604
f32
605-
0.3333333432674408
605+
0.33333334
606606
>
607607
iex> y_true = Nx.tensor([0, 1, 2, 0, 1, 2], type: :u64)
608608
iex> y_pred = Nx.tensor([0, 2, 1, 0, 0, 1], type: :u64)
@@ -665,17 +665,17 @@ defmodule Scholar.Metrics.Classification do
665665
iex> Scholar.Metrics.Classification.fbeta_score(y_true, y_pred, Nx.u32(1), num_classes: 3)
666666
#Nx.Tensor<
667667
f32[3]
668-
[0.6666666865348816, 0.6666666865348816, 0.4000000059604645]
668+
[0.6666667, 0.6666667, 0.4]
669669
>
670670
iex> Scholar.Metrics.Classification.fbeta_score(y_true, y_pred, Nx.u32(2), num_classes: 3)
671671
#Nx.Tensor<
672672
f32[3]
673-
[0.6666666865348816, 0.5555555820465088, 0.625]
673+
[0.6666667, 0.5555556, 0.625]
674674
>
675675
iex> Scholar.Metrics.Classification.fbeta_score(y_true, y_pred, Nx.f32(0.5), num_classes: 3)
676676
#Nx.Tensor<
677677
f32[3]
678-
[0.6666666865348816, 0.8333333134651184, 0.29411765933036804]
678+
[0.6666667, 0.8333333, 0.29411766]
679679
>
680680
iex> Scholar.Metrics.Classification.fbeta_score(y_true, y_pred, Nx.u32(2), num_classes: 3, average: :macro)
681681
#Nx.Tensor<
@@ -758,7 +758,7 @@ defmodule Scholar.Metrics.Classification do
758758
iex> Scholar.Metrics.Classification.precision_recall_fscore_support(y_true, y_pred, num_classes: 3, average: :weighted)
759759
{Nx.f32([0.6666666865348816, 1.0, 0.25]),
760760
Nx.f32([0.6666666865348816, 0.5, 1.0]),
761-
Nx.f32(0.6399999856948853),
761+
Nx.f32(0.64),
762762
Nx.Constants.nan()}
763763
iex> Scholar.Metrics.Classification.precision_recall_fscore_support(y_true, y_pred, num_classes: 3, average: :micro)
764764
{Nx.f32(0.6000000238418579),
@@ -854,12 +854,12 @@ defmodule Scholar.Metrics.Classification do
854854
iex> Scholar.Metrics.Classification.f1_score(y_true, y_pred, num_classes: 3)
855855
#Nx.Tensor<
856856
f32[3]
857-
[0.6666666865348816, 0.6666666865348816, 0.4000000059604645]
857+
[0.6666667, 0.6666667, 0.4]
858858
>
859859
iex> Scholar.Metrics.Classification.f1_score(y_true, y_pred, num_classes: 3, average: :macro)
860860
#Nx.Tensor<
861861
f32
862-
0.5777778029441833
862+
0.5777778
863863
>
864864
iex> Scholar.Metrics.Classification.f1_score(y_true, y_pred, num_classes: 3, average: :weighted)
865865
#Nx.Tensor<
@@ -1183,7 +1183,7 @@ defmodule Scholar.Metrics.Classification do
11831183
iex> Scholar.Metrics.Classification.brier_score_loss(y_true, y_prob)
11841184
#Nx.Tensor<
11851185
f32
1186-
0.03750000149011612
1186+
0.0375
11871187
>
11881188
"""
11891189
deftransform brier_score_loss(y_true, y_prob, opts \\ []) do
@@ -1214,15 +1214,15 @@ defmodule Scholar.Metrics.Classification do
12141214
iex> Scholar.Metrics.Classification.cohen_kappa_score(y1, y2, num_classes: 3)
12151215
#Nx.Tensor<
12161216
f32
1217-
0.21739131212234497
1217+
0.21739131
12181218
>
12191219
12201220
iex> y1 = Nx.tensor([0, 1, 1, 0, 1, 2])
12211221
iex> y2 = Nx.tensor([0, 2, 1, 0, 0, 1])
12221222
iex> Scholar.Metrics.Classification.cohen_kappa_score(y1, y2, num_classes: 3, weighting_type: :linear)
12231223
#Nx.Tensor<
12241224
f32
1225-
0.3571428060531616
1225+
0.3571428
12261226
>
12271227
"""
12281228
deftransform cohen_kappa_score(y1, y2, opts \\ []) do
@@ -1278,18 +1278,18 @@ defmodule Scholar.Metrics.Classification do
12781278
iex> Scholar.Metrics.Classification.log_loss(y_true, y_prob, num_classes: 2)
12791279
#Nx.Tensor<
12801280
f32
1281-
0.17380733788013458
1281+
0.17380734
12821282
>
12831283
iex> Scholar.Metrics.Classification.log_loss(y_true, y_prob, num_classes: 2, normalize: false)
12841284
#Nx.Tensor<
12851285
f32
1286-
0.6952293515205383
1286+
0.69522935
12871287
>
12881288
iex> weights = Nx.tensor([0.7, 2.3, 1.3, 0.34])
12891289
iex(361)> Scholar.Metrics.Classification.log_loss(y_true, y_prob, num_classes: 2, sample_weights: weights)
12901290
#Nx.Tensor<
12911291
f32
1292-
0.22717177867889404
1292+
0.22717178
12931293
>
12941294
"""
12951295
deftransform log_loss(y_true, y_prob, opts \\ []) do
@@ -1363,7 +1363,7 @@ defmodule Scholar.Metrics.Classification do
13631363
iex> Scholar.Metrics.Classification.top_k_accuracy_score(y_true, y_score, k: 2, num_classes: 3)
13641364
#Nx.Tensor<
13651365
f32
1366-
0.800000011920929
1366+
0.8
13671367
>
13681368
13691369
iex> y_true = Nx.tensor([0, 1, 2, 2, 0])
@@ -1379,7 +1379,7 @@ defmodule Scholar.Metrics.Classification do
13791379
iex> Scholar.Metrics.Classification.top_k_accuracy_score(y_true, y_score, k: 1, num_classes: 2)
13801380
#Nx.Tensor<
13811381
f32
1382-
0.20000000298023224
1382+
0.2
13831383
>
13841384
"""
13851385
deftransform top_k_accuracy_score(y_true, y_prob, opts \\ []) do

lib/scholar/metrics/clustering.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ defmodule Scholar.Metrics.Clustering do
3939
iex> Scholar.Metrics.Clustering.silhouette_samples(x, labels, num_clusters: 2)
4040
#Nx.Tensor<
4141
f32[5]
42-
[0.7647753357887268, 0.7781199216842651, 0.6754303574562073, 0.4934419095516205, 0.6627992391586304]
42+
[0.76477534, 0.7781199, 0.67543036, 0.4934419, 0.66279924]
4343
>
4444
4545
iex> x = Nx.tensor([[0.1, 0], [0, 1], [22, 65], [42, 3], [4.2, 51]])
4646
iex> labels = Nx.tensor([0, 1, 2, 1, 1])
4747
iex> Scholar.Metrics.Clustering.silhouette_samples(x, labels, num_clusters: 3)
4848
#Nx.Tensor<
4949
f32[5]
50-
[0.0, -0.9782053232192993, 0.0, -0.18546827137470245, -0.592965841293335]
50+
[0.0, -0.9782053, 0.0, -0.18546827, -0.59296584]
5151
>
5252
"""
5353
deftransform silhouette_samples(x, labels, opts \\ []) do
@@ -83,7 +83,7 @@ defmodule Scholar.Metrics.Clustering do
8383
iex> Scholar.Metrics.Clustering.silhouette_score(x, labels, num_clusters: 3)
8484
#Nx.Tensor<
8585
f32
86-
-0.35132789611816406
86+
-0.3513279
8787
>
8888
"""
8989
deftransform silhouette_score(x, labels, opts \\ []) do

lib/scholar/metrics/distance.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,15 @@ defmodule Scholar.Metrics.Distance do
323323
iex> Scholar.Metrics.Distance.minkowski(x, y, p: 2.5, axes: [0])
324324
#Nx.Tensor<
325325
f32[3]
326-
[7.021548271179199, 1.3195079565048218, 4.049539089202881]
326+
[7.0215483, 1.319508, 4.049539]
327327
>
328328
329329
iex> x = Nx.tensor([[6, 2, 9], [2, 5, 3]])
330330
iex> y = Nx.tensor([[8, 3, 1]])
331331
iex> Scholar.Metrics.Distance.minkowski(x, y, p: 2.5)
332332
#Nx.Tensor<
333333
f32
334-
9.621805191040039
334+
9.621805
335335
>
336336
"""
337337
deftransform minkowski(x, y, opts \\ []) do

lib/scholar/metrics/regression.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,15 @@ defmodule Scholar.Metrics.Regression do
412412
iex> Scholar.Metrics.Regression.r2_score(y_true, y_pred)
413413
#Nx.Tensor<
414414
f32
415-
0.9486081600189209
415+
0.94860816
416416
>
417417
418418
iex> y_true = Nx.tensor([[3, -0.5], [2, 7]], type: {:f, 32})
419419
iex>y_pred = Nx.tensor([[2.5, 0.0], [2, 8]], type: {:f, 32})
420420
iex> Scholar.Metrics.Regression.r2_score(y_true, y_pred, axes: [0])
421421
#Nx.Tensor<
422422
f32[2]
423-
[0.6800000071525574, 0.9559956192970276]
423+
[0.68, 0.9559956]
424424
>
425425
426426
iex> y_true = Nx.tensor([-2.0, -2.0, -2.0], type: :f64)
@@ -485,7 +485,7 @@ defmodule Scholar.Metrics.Regression do
485485
iex> Scholar.Metrics.Regression.explained_variance_score(y_true, y_pred)
486486
#Nx.Tensor<
487487
f32
488-
0.9571734666824341
488+
0.95717347
489489
>
490490
491491
iex> y_true = Nx.tensor([-2.0, -2.0, -2.0], type: :f64)
@@ -525,7 +525,7 @@ defmodule Scholar.Metrics.Regression do
525525
iex> Scholar.Metrics.Regression.explained_variance_score(y_true, y_pred, axes: [0])
526526
#Nx.Tensor<
527527
f32[2]
528-
[0.75, 0.995555579662323]
528+
[0.75, 0.9955556]
529529
>
530530
"""
531531
deftransform explained_variance_score(y_true, y_pred, opts \\ []) do

lib/scholar/neighbors/radius_nn_classifier.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ defmodule Scholar.Neighbors.RadiusNNClassifier do
235235
#Nx.Tensor<
236236
f32[2][4]
237237
[
238-
[2.469818115234375, 0.3162280023097992, 1.5811389684677124, 0.7071064710617065],
239-
[0.10000114142894745, 2.193171262741089, 1.0049875974655151, 3.132091760635376]
238+
[2.469818, 0.316228, 1.581139, 0.7071065],
239+
[0.10000114, 2.1931713, 1.0049876, 3.1320918]
240240
]
241241
>
242242
iex> mask

lib/scholar/neighbors/radius_nn_regressor.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ defmodule Scholar.Neighbors.RadiusNNRegressor do
201201
#Nx.Tensor<
202202
f32[2][4]
203203
[
204-
[2.469818115234375, 0.3162280023097992, 1.5811389684677124, 0.7071064710617065],
205-
[0.10000114142894745, 2.193171262741089, 1.0049875974655151, 3.132091760635376]
204+
[2.469818, 0.316228, 1.581139, 0.7071065],
205+
[0.10000114, 2.1931713, 1.0049876, 3.1320918]
206206
]
207207
>
208208
iex> mask

0 commit comments

Comments
 (0)