mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-15 11:25:53 +08:00
Add sanity checks for input parameters
This commit is contained in:
@@ -659,6 +659,15 @@ def ransac(data, model_class, min_samples, residual_threshold,
|
||||
best_inlier_residuals_sum = np.inf
|
||||
best_inliers = None
|
||||
|
||||
if min_samples < 0:
|
||||
raise ValueError("`min_samples` must be greater than zero")
|
||||
|
||||
if max_trials < 0:
|
||||
raise ValueError("`max_trials` must be greater than zero")
|
||||
|
||||
if stop_probability < 0 or stop_probability > 1:
|
||||
raise ValueError("`stop_probability` must be in range [0, 1]")
|
||||
|
||||
if not isinstance(data, list) and not isinstance(data, tuple):
|
||||
data = [data]
|
||||
|
||||
|
||||
@@ -237,6 +237,19 @@ def test_ransac_dynamic_max_trials():
|
||||
assert_equal(_dynamic_max_trials(1, 100, 10, 1), float('inf'))
|
||||
|
||||
|
||||
def test_ransac_invalid_input():
|
||||
assert_raises(ValueError, ransac, np.zeros((10, 2)), None, min_samples=-1,
|
||||
residual_threshold=0)
|
||||
assert_raises(ValueError, ransac, np.zeros((10, 2)), None, min_samples=2,
|
||||
residual_threshold=0, max_trials=-1)
|
||||
assert_raises(ValueError, ransac, np.zeros((10, 2)), None, min_samples=2,
|
||||
residual_threshold=0,
|
||||
stop_probability=-1)
|
||||
assert_raises(ValueError, ransac, np.zeros((10, 2)), None, min_samples=2,
|
||||
residual_threshold=0,
|
||||
stop_probability=1.01)
|
||||
|
||||
|
||||
def test_deprecated_params_attribute():
|
||||
model = LineModel()
|
||||
model.params = (10, 1)
|
||||
|
||||
Reference in New Issue
Block a user