ad
ad copied to clipboard
Add ad.math functions to ADF objects.
Consider the following code:
>>> import ad
>>> import numpy as np
>>> x = ad.adnumber(1.0)
>>> y = np.sin(x)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-20-bb2b9cec7df6> in <module>()
----> 1 y = np.sin(x)
AttributeError: 'ADV' object has no attribute 'sin'
Typically in the past I have allowed np
to be replaced with a module like ad.math
when I needed derivatives, but I believe that the ad
package could become much simpler if the ADF
class simply grew methods like those in ad.math
. For example, the following seems to work nicely.
class ADF(object):
...
def sin(self):
return ad.admath.sin(self)
>>> import ad
>>> import numpy as np
>>> x = ad.adnumber(1.0)
>>> y = np.sin(x)
ad(0.8414709848078965)
Are there any issues to be aware of? (I don't recall seeing this behaviour before so maybe the call to self.sin
etc. is a new feature in numpy? I can't seem to find a reference to this behaviour though. I am using version 1.11.0.)
I checked to see if this would work with sympy
: there the issue comes up that some expressions already have method that clash ((x**y).exp
was the example stated). However, I don't see why this would be a problem for ad
right now.