Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ad.math functions to ADF objects. #12

Open
mforbes opened this issue Jun 7, 2016 · 1 comment
Open

Add ad.math functions to ADF objects. #12

mforbes opened this issue Jun 7, 2016 · 1 comment

Comments

@mforbes
Copy link

mforbes commented Jun 7, 2016

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.)

@mforbes
Copy link
Author

mforbes commented Jun 7, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant