所以我是一个函数的trying to compare two implementations和Hypothesis来确定它们是否以同样的方式处理各种各样的不同输入,而我可能不会想到我自己
我试着用numpy.testing.assert_allclose
来比较输出,但假设只是反复地比它聪明。我越是扩大可接受的容差,假设就抛出越大的值,直到它失败,即使输出非常相似,被认为是相同的
E Not equal to tolerance rtol=0.1, atol=0.001
...
Falsifying example: test_resample_1d_consistency(a=array([7.696582e+12, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00], dtype=float32), num=11)
你知道吗
E Not equal to tolerance rtol=0.1, atol=0.01
...
Falsifying example: test_resample_1d_consistency(a=array([7.366831e+13, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00], dtype=float32), num=11)
你知道吗
E Not equal to tolerance rtol=1000, atol=1000
...
Falsifying example: test_resample_1d_consistency(a=array([8.360933e+18, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00], dtype=float32), num=186)
等等
所以我想我需要一个不同的“足够好”的相似性测试,或者我需要以某种方式限制输入值的范围?但我不知道如何做到这些,不会错过真正错误的答案。有什么建议吗
在我看来,在极端情况下
rfft
确实会给出非常不同的结果—因此您需要确定这是否是一个bug。也许这个假设已经证明了它不是一个合适的优化换句话说,为给定的输入量确定适当的误差容限的问题实际上是测试中最困难的部分(在文献中,这就是如何区分善恶行为的“神谕问题”
一旦有了一个绑定,比如说
rtol=0.1, atol=0.001
所有数组的元素都在[-1000., 1000.]
中,就可以将elements
参数传递给arrays
策略来约束每个测试的值,或者尝试一系列大小/公差组合相关问题 更多 >
编程相关推荐