[CppAD] numpy eigenvalues in pyCppAD

Brad Bell bradbell at seanet.com
Thu Aug 3 18:32:16 EDT 2017


It seems from the statement
	a_y   = Pot(a_x)
that the return value from Pot should be an a_float.

Looking at the code for Pot(arg), it is not clear what the call to 
independent is doing,
nor how two levels are AD are used here.

This makes me think that
	def Pot(arg) :
		x=independent(arg)
should be replaced by
	def Pot(x) :
and
	dtype='a2float'
should be replaced by
	dtype='a_float'



On 08/03/2017 05:07 AM, Jyotiranjan Beuria wrote:
> 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 casting
> was found for ufunc eigvalsh_lo*
>
> Regards,
> Jyotiranjan Beuria
> Graduate student, HRI, INDIA
>
>
>
> _______________________________________________
> CppAD mailing list
> CppAD at list.coin-or.org
> https://urldefense.proofpoint.com/v2/url?u=https-3A__list.coin-2Dor.org_mailman_listinfo_cppad&d=DwICAg&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=UxLhbaqYMJLc2OFXF6T8asQht7vpwIClD1FdrFb8omo&m=rPTSQO84d-cZe99G2qE3-3_iukhRo0yydos83tDxCYY&s=r9S0qITbXtLfkk3Dqx1Hb9vdoXe5h3QmEjLvr_on3-c&e=
>


More information about the CppAD mailing list