np.linalg.solve()不适用于AutoDiff吗?我用它来求解机械手方程。错误消息如下所示。我尝试了类似的“双”版本代码,这是没有问题的。请告诉我怎么修理,谢谢!
### here is the error message
vdot_ad = np.linalg.solve(M_,ggg_ad)
File "<__array_function__ internals>", line 5, in solve
File "/usr/local/lib/python3.8/site-packages/numpy/linalg/linalg.py", line 394, in solve
r = gufunc(a, b, signature=signature, extobj=extobj)
TypeError: No loop matching the specified signature and casting was found for ufunc solve1
####. here is the code
plant = MultibodyPlant(time_step= 0.01)
parser = Parser(plant)
parser.AddModelFromFile("double_pendulum.sdf")
plant.Finalize()
plant_autodiff = plant.ToAutoDiffXd()
####### <AutoDiff> get the error message
xu = np.hstack((x, u))
xu_ad = initializeAutoDiff(xu)[:,0]
x_ad = xu_ad[:4]
q_ad = x_ad[:2]
v_ad = x_ad[2:4]
u_ad = xu_ad[4:]
(M_, Cv_, tauG_, B_, tauExt_) = ManipulatorDynamics(plant_autodiff, q_ad, v_ad)
vdot_ad = np.linalg.solve(M_,tauG_ + np.dot(B_,u_ad) - np.dot(Cv_,v_ad)) 发布于 2020-10-29 21:01:23
注意,在pydrake中,AutoDiffXd标量使用dtype=object向NumPy公开。
这种方法有一些缺点,比如您现在遇到的问题。
这不一定是Drake的问题,但是考虑到在18.04版(超级老版本)上实现的ufunc,这是对NumPy本身的限制。
为了说明,下面是我在Ubuntu18.04,CPython 3.6.9,NumPy 1.13.3上看到的内容:
>>> import numpy as np
>>> A = np.eye(2)
>>> b = np.array([1, 2])
>>> np.linalg.solve(A, b)
array([ 1., 2.])
>>> A = A.astype(object)
>>> b = b.astype(object)
>>> np.linalg.solve(A, b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/numpy/linalg/linalg.py", line 375, in solve
r = gufunc(a, b, signature=signature, extobj=extobj)
TypeError: No loop matching the specified signature and casting
was found for ufunc solve1最直接的解决方案是在pydrake中公开一个类似的例程,让用户利用它。
这也是我们必须为np.linalg.inv所做的:
https://github.com/RobotLocomotion/drake/pull/11173/files
这不是最好的解决方案:(然而,这很简单!)
https://stackoverflow.com/questions/64593813
复制相似问题