I am trying to write a conversion from a pytorch neural network to a casadi neural network.
I am getting an error where the dot product requires equal shapes, whereas numpy does not require that.
Example:
import numpy as np
A = np.array([[1, 2, 3]])
B = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
])
C = np.dot(A, B) # array([[30, 36, 42]])
In casadi:
import casadi as ca
A = ca.MX(*A.shape)
B = ca.MX(*B.shape)
C = ca.dot(A, B)
Traceback (most recent call last):
File "/home/tom/.local/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3433, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-72-07337ba0e18e>", line 1, in <module>
C = ca.dot(A, B)
File "/home/tom/miniconda3/envs/vpp3/lib/python3.10/site-packages/casadi/casadi.py", line 36361, in dot
return _casadi.dot(*args)
RuntimeError: .../casadi/core/matrix_impl.hpp:2000: Assertion "x.size()==y.size()" failed:
dot: Dimension mismatch
How can I perform this dot product?