raysect / source

The main source repository for the Raysect project.
http://www.raysect.org
BSD 3-Clause "New" or "Revised" License
88 stars 23 forks source link

Add erf and sqrt into function1D framework #330

Closed Mateasek closed 4 years ago

Mateasek commented 4 years ago

Adding error function and square root into function1D framewrok

related to #305

Mateasek commented 4 years ago
Traceback (most recent call last):

  File "/home/travis/build/raysect/source/raysect/core/math/function/function1d/tests/test_cmath.py", line 113, in test_erf

    self.assertEqual(function(x), expected, "Erf1D call did not match reference value.")

AssertionError: -0.00011283791633342487 != -0.00011283791633342489 : Erf1D call did not match reference value.

Could this be caused by Differences in algorithms used by c and python?

CnlPepper commented 4 years ago
Traceback (most recent call last):

  File "/home/travis/build/raysect/source/raysect/core/math/function/function1d/tests/test_cmath.py", line 113, in test_erf

    self.assertEqual(function(x), expected, "Erf1D call did not match reference value.")

AssertionError: -0.00011283791633342487 != -0.00011283791633342489 : Erf1D call did not match reference value.

Could this be caused by Differences in algorithms used by c and python?

Yes, it is possible they are using a slightly different version implementation of the algorithm leading to small differences. You;ll need to switch the assert to AlmostEqual and specify a tolerance. See the other tests for an example of it's usage. I recommend setting an absolute tolerance by taking the expected value and multiplying by a suitable small number e.g. 1e-10.

CnlPepper commented 4 years ago

Other than the minor comments in the review, this looks good. Thanks @Mateasek.

Mateasek commented 4 years ago

I used the AssertAlmostEqual with 10 decimals precition for the value tests of the error function. We can get a little bit higher to 15 decimals for example, if needed.

CnlPepper commented 4 years ago

Excellent, thanks @Mateasek.