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

Incompatibility of cppad_py.a_double with float in python #6

Open
zhengp0 opened this issue Aug 15, 2018 · 3 comments
Open

Incompatibility of cppad_py.a_double with float in python #6

zhengp0 opened this issue Aug 15, 2018 · 3 comments

Comments

@zhengp0
Copy link
Contributor

zhengp0 commented Aug 15, 2018

Here is a simple test program where the issue happens.

Test case:

import cppad_py
import numpy

# initialize dimensions
n_dep = 1
n_ind = 1

# declare independent variables
x  = numpy.ones(n_ind, dtype=float)
ax = cppad_py.independent(x)

# declare dependent variables (quadratic function)
ay = numpy.zeros(n_dep, dtype=cppad_py.a_double)
ay[0] = 0.5*ax[0]*ax[0]

# define corresponding function
af = cppad_py.a_fun(ax, ay)

# calculate the gradient
g  = af.jacobian(x)

Error report:

Traceback (most recent call last):
  File "test.py", line 14, in <module>
    ay[0] = 0.5*ax[0]*ax[0]
TypeError: unsupported operand type(s) for *: 'float' and 'a_double'

Thanks!

@bradbell
Copy link
Owner

This will take some time for me to get to and fix.
My current plan is to create a python type called a_float that wraps a_double and accomplishes this.

For now, you can use
ay[0] = a_double(0.5) * ax[0] * ax[0]

@bradbell
Copy link
Owner

I am getting the following error message with your test above:

(Pdb) 
TypeError: __init__() takes 2 positional arguments but 3 were given
> /home/bradbell/repo/cppad_py.git/junk.py(21)<module>()
-> af = cppad_py.a_fun(ax, ay)

@bradbell
Copy link
Owner

bradbell commented Apr 23, 2020

The problem is you are calling a_fun instead of d_fun; see
https://bradbell.github.io/cppad_py/doc/py_fun_ctor.htm
I need to get a better error message for this case.

There is a python __init__ function for the a_fun class in the lib/python/cppad_py/fun.py file. This is the function that the error message below is for:
TypeError: __init__() takes 2 positional arguments but 3 were given

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

2 participants