[CppAD] numpy eigenvalues in pyCppAD
Jyotiranjan Beuria
jyotiranjan.beuria at gmail.com
Thu Aug 3 21:04:21 EDT 2017
Even after removing "x=independent(arg)" in the function definition
also does not solve the problem. It seems that np.linalg.eigvalsh()
is not accepting a_float types. At this point I have a naive question,
are all linear algebra modules offered by numpy compatible with
CppAD?
I still get following error:
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
On Fri, Aug 4, 2017 at 4:02 AM, Brad Bell <bradbell at seanet.com> wrote:
> 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.co
>> in-2Dor.org_mailman_listinfo_cppad&d=DwICAg&c=Ngd-ta5yRYsqe
>> UsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=UxLhbaqYMJLc2OFXF6T8as
>> Qht7vpwIClD1FdrFb8omo&m=rPTSQO84d-cZe99G2qE3-3_iukhRo0
>> yydos83tDxCYY&s=r9S0qITbXtLfkk3Dqx1Hb9vdoXe5h3QmEjLvr_on3-c&e=
>>
>> _______________________________________________
> CppAD mailing list
> CppAD at list.coin-or.org
> https://urldefense.proofpoint.com/v2/url?u=https-3A__list.co
> in-2Dor.org_mailman_listinfo_cppad&d=DwICAg&c=Ngd-ta5yRYsqe
> UsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=Q-ytHio7AaRRiIuJRtbXN8
> AT1n8UpuHlx7zvJ-OkcrY&m=a1LG50d2vI9UL7Ttk1Y1nZpCgW-ApCfzJSZO
> Me2Vsr4&s=OY_pnnHykR6L0RkY2b-r897K_2vIklZz85RoBJMwd6E&e=
--
Jyotiranjan Beuria
Ph.D Student, HRI Allahabad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cppad/attachments/20170804/c7fe277d/attachment.html>
More information about the CppAD
mailing list