@@ -1611,6 +1611,7 @@ def __init__(
1611
1611
transform_seed = 42 ,
1612
1612
transform_mode = "embedding" ,
1613
1613
force_approximation_algorithm = False ,
1614
+ force_exact_distances = False ,
1614
1615
verbose = False ,
1615
1616
unique = False ,
1616
1617
densmap = False ,
@@ -1648,6 +1649,7 @@ def __init__(
1648
1649
self .transform_seed = transform_seed
1649
1650
self .transform_mode = transform_mode
1650
1651
self .force_approximation_algorithm = force_approximation_algorithm
1652
+ self .force_exact_distances = force_exact_distances
1651
1653
self .verbose = verbose
1652
1654
self .unique = unique
1653
1655
@@ -1842,6 +1844,9 @@ def _dist_only(x, y, *kwds):
1842
1844
if self .n_jobs < - 1 or self .n_jobs == 0 :
1843
1845
raise ValueError ("n_jobs must be a postive integer, or -1 (for all cores)" )
1844
1846
1847
+ if self .force_approximation_algorithm and self .force_exact_distances :
1848
+ raise ValueError ("enforcing both exact distances and an approximation contradict each other" )
1849
+
1845
1850
if self .dens_lambda < 0.0 :
1846
1851
raise ValueError ("dens_lambda cannot be negative" )
1847
1852
if self .dens_frac < 0.0 or self .dens_frac > 1.0 :
@@ -1930,6 +1935,9 @@ def _populate_combined_params(self, *models):
1930
1935
self .force_approximation_algorithm = flattened (
1931
1936
[m .force_approximation_algorithm for m in models ]
1932
1937
)
1938
+ self .force_exact_distances = flattened (
1939
+ [m .force_exact_distances for m in models ]
1940
+ )
1933
1941
self .verbose = flattened ([m .verbose for m in models ])
1934
1942
self .unique = flattened ([m .unique for m in models ])
1935
1943
@@ -2332,7 +2340,8 @@ def fit(self, X, y=None):
2332
2340
verbose = self .verbose ,
2333
2341
)
2334
2342
# Handle small cases efficiently by computing all distances
2335
- elif X [index ].shape [0 ] < 4096 and not self .force_approximation_algorithm :
2343
+ elif self .force_exact_distances or (
2344
+ X [index ].shape [0 ] < 4096 and not self .force_approximation_algorithm ):
2336
2345
self ._small_data = True
2337
2346
try :
2338
2347
# sklearn pairwise_distances fails for callable metric on sparse data
0 commit comments