Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 基于属性的测试和浮点相等_Python_Python Hypothesis - Fatal编程技术网

Python 基于属性的测试和浮点相等

Python 基于属性的测试和浮点相等,python,python-hypothesis,Python,Python Hypothesis,因此,我需要一个函数来确定它们是否以相同的方式处理大量不同的输入,而我可能不会想到我自己 我试着使用numpy.testing.assert\u allclose来比较输出,但假设只是反复地超过了它。我越是扩大可接受的公差,假设值越大,直到它失败为止,即使输出非常相似,可以认为是相同的 E Not equal to tolerance rtol=0.1, atol=0.001 ... Falsifying example: test_resample_1d_consistency(a=arr

因此,我需要一个函数来确定它们是否以相同的方式处理大量不同的输入,而我可能不会想到我自己

我试着使用
numpy.testing.assert\u 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)

等等


所以我想我需要一个不同的“足够好”的相似性测试,或者我需要以某种方式限制输入值的范围?但我不知道如何做到这一点,不会错过真正错误的答案。有什么建议吗?

在我看来,
rfft
在极端情况下会给出非常不同的结果,所以您需要确定这是否是一个bug。也许这个假设实际上已经表明它不是一个合适的优化

换句话说,为给定输入量确定适当的误差容限是测试中最困难的部分!(在文献中,这是如何区分好行为和坏行为的“甲骨文问题”)


一旦你有了一个绑定-比如说
rtol=0.1,atol=0.001
对于所有数组,元素在
[-1000,1000.]
中,你可以将
元素
参数传递给
数组
策略来约束每个测试的值,或者尝试一系列的大小/公差组合。

如你所知,最好将mcve放在github的链接上,而不是声明“我尝试使用numpy和假设”。@Sanyash我不理解你的评论。什么是mvce?@Sanyash不适用于这种类型的问题
为给定的输入量确定适当的容错能力的问题实际上是测试中最困难的部分是的,这就是为什么我不能自己解决它,并且问了一个关于如何决定它的问题!:D
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)