[CppAD] numpy eigenvalues in pyCppAD
Jyotiranjan Beuria
jyotiranjan.beuria at gmail.com
Thu Aug 3 08:07:56 EDT 2017
Dear Experts,
I am trying to use python wrapper for CppAD. My function
depends on the eigenvalues of a matrix. Can anyone help
me in this regard. The code is given below.
*************************************************************
from pycppad import *
import numpy as np
def Pot(arg):
x=independent(arg)
m00=x[0]*x[0]
m11=x[1]*x[1]
m01=x[0]*x[1]
m10=-x[0]*x[1]
m=np.array([[m00,m01],[m10,m11]])
return np.array([np.sum(np.linalg.eigvalsh(m))],dtype='a2float')
def hessian():
delta = 10. * np.finfo(float).eps
x = np.array( [ 0., 0. ] )
a_x = independent(x)
a_y = Pot(a_x)
f = adfun(a_x, a_y)
x = np.array( [ 2., 3. ] )
H = f.hessian(x, [0])
print H
hessian()
*************************************************************
I am getting following error.
*Traceback (most recent call last): File "hessian2.py", line 37, in
<module> pycppad_test_hessian() File "hessian2.py", line 30, in
pycppad_test_hessian a_y = Pot(a_x) File "hessian2.py", line 24, in
Pot return np.array([np.sum(np.linalg.eigvalsh(m))],dtype='a2float')
File "/usr/local/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line
994, in eigvalsh w = gufunc(a, signature=signature,
extobj=extobj)TypeError: No loop matching the specified signature and
castingwas found for ufunc eigvalsh_lo*
Regards,
Jyotiranjan Beuria
Graduate student, HRI, INDIA
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cppad/attachments/20170803/92b285d4/attachment.html>
More information about the CppAD
mailing list