Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
x_mx = struct_symSX([
entry("x",shape=n),
entry("S",shape=(n,n))
])
X_sx = struct_SX(x_sx)
X_sx["x"] = DM(list(range(n)))
X_sx["S"] = c.reshape(DM(list(range(n,n+n*n))),n,n)
X_mx = struct_MX(x_sx)
X_mx["x"] = DM(list(range(n)))
X_mx["S"] = c.reshape(DM(list(range(n,n+n*n))),n,n)
self.checkarray(x_sx.struct.map[("S",)],c.reshape(DM(list(range(n,n+n*n))),n,n))
self.checkarray(x_mx.struct.map[("S",)],c.reshape(DM(list(range(n,n+n*n))),n,n))
self.checkarray(X_sx.cat,DM(list(range(n+n*n))))
self.checkarray(X_mx.cat,DM(list(range(n+n*n))))
for s, S in [(x_sx,struct_symSX),(x_mx,struct_symMX)]:
h = S([entry("w",struct=s)])
hX = struct_SX(h)
hX["w","x"] = DM(list(range(n)))
hX["w","S"] = c.reshape(DM(list(range(n,n+n*n))),n,n)
self.checkarray(h.struct.map[("w","S",)],c.reshape(DM(list(range(n,n+n*n))),n,n))
self.checkarray(hX.cat,DM(list(range(n+n*n))))
self.checkarray(h.struct.map[("w",)],DM(list(range(n+n*n))))
self.checkarray(hX["w"],DM(list(range(n+n*n))))
hX["w"] = DM(list(range(n+n*n)))
checkMXoperations(self,lambda x: c.reshape(x.T,(6,4)),lambda x: numpy.reshape(x,(4,6)).T,'trans(reshape(vertcat))')
inp[4,0]=z
inp[5,0]=w
sp = Sparsity(1,6,[0, 1, 1, 2, 2, 3, 4],[0, 0, 0, 0]).T
spT = Sparsity(6,1,[0, 4],[0, 2, 4, 5]).T
self.sxinputs = {
"column" : {
"dense": [vertcat(*[x,y,z,w])],
"sparse": [inp] }
, "row": {
"dense": [vertcat(*[x,y,z,w]).T],
"sparse": [inp.T]
}, "matrix": {
"dense": [c.reshape(vertcat(*[x,y,z,w]),2,2)],
"sparse": [c.reshape(inp,3,2)]
}
}
self.mxinputs = {
"column" : {
"dense": [MX.sym("xyzw",4,1)],
"sparse": [MX.sym("xyzw",sp)]
},
"row" : {
"dense": [MX.sym("xyzw",1,4)],
"sparse": [MX.sym("xyzw",spT)]
},
"matrix": {
"dense": [MX.sym("xyzw",2,2)],
"sparse": [MX.sym("xyzw",c.reshape(inp,3,2).sparsity())]
}
def test_bug_structSXMX(self):
n= 2
x_sx = struct_symSX([
entry("x",shape=n),
entry("S",shape=(n,n))
])
x_mx = struct_symSX([
entry("x",shape=n),
entry("S",shape=(n,n))
])
X_sx = struct_SX(x_sx)
X_sx["x"] = DM(list(range(n)))
X_sx["S"] = c.reshape(DM(list(range(n,n+n*n))),n,n)
X_mx = struct_MX(x_sx)
X_mx["x"] = DM(list(range(n)))
X_mx["S"] = c.reshape(DM(list(range(n,n+n*n))),n,n)
self.checkarray(x_sx.struct.map[("S",)],c.reshape(DM(list(range(n,n+n*n))),n,n))
self.checkarray(x_mx.struct.map[("S",)],c.reshape(DM(list(range(n,n+n*n))),n,n))
self.checkarray(X_sx.cat,DM(list(range(n+n*n))))
self.checkarray(X_mx.cat,DM(list(range(n+n*n))))
for s, S in [(x_sx,struct_symSX),(x_mx,struct_symMX)]:
h = S([entry("w",struct=s)])
hX = struct_SX(h)
hX["w","x"] = DM(list(range(n)))
hX["w","S"] = c.reshape(DM(list(range(n,n+n*n))),n,n)
"sparse": [c.reshape(inp,3,2)]
}
}
self.mxinputs = {
"column" : {
"dense": [MX.sym("xyzw",4,1)],
"sparse": [MX.sym("xyzw",sp)]
},
"row" : {
"dense": [MX.sym("xyzw",1,4)],
"sparse": [MX.sym("xyzw",spT)]
},
"matrix": {
"dense": [MX.sym("xyzw",2,2)],
"sparse": [MX.sym("xyzw",c.reshape(inp,3,2).sparsity())]
}
}
def temp1(xyz):
X=MX(6,1)
X[0,0]=xyz.nz[0]
X[2,0]=xyz.nz[0]+2*xyz.nz[1]**2
X[4,0]=xyz.nz[0]+2*xyz.nz[1]**3+3*xyz.nz[2]**4
X[5,0]=xyz.nz[3]
return [X]
def temp2(xyz):
X=MX(1,6)
X[0,0]=xyz.nz[0]
X[0,2]=xyz.nz[0]+2*xyz.nz[1]**2
X[0,4]=xyz.nz[0]+2*xyz.nz[1]**3+3*xyz.nz[2]**4
])
x_mx = struct_symSX([
entry("x",shape=n),
entry("S",shape=(n,m))
])
X_sx = struct_SX(x_sx)
X_sx["x"] = DM(list(range(n)))
X_sx["S"] = c.reshape(DM(list(range(n,n+n*m))),n,m)
X_mx = struct_MX(x_sx)
X_mx["x"] = DM(list(range(n)))
X_mx["S"] = c.reshape(DM(list(range(n,n+n*m))),n,m)
self.checkarray(x_sx.struct.map[("S",)],c.reshape(DM(list(range(n,n+n*m))),n,m))
self.checkarray(x_mx.struct.map[("S",)],c.reshape(DM(list(range(n,n+n*m))),n,m))
self.checkarray(X_sx.cat,DM(list(range(n+n*m))))
self.checkarray(X_mx.cat,DM(list(range(n+n*m))))
n = 3
x_sx = struct_symSX([
entry("x",shape=n),
entry("S",shape=Sparsity.upper(n))
])
x_mx = struct_symSX([
entry("x",shape=n),
entry("S",shape=Sparsity.upper(n))
])
X_sx = struct_SX(x_sx)
def chain_dyn(x, u, model_parameters):
""" returns the derivative of the state dx=f(x) """
a=3
positions = cd.reshape(x[0:model_parameters.dimension * (model_parameters.number_of_balls + 1), 0], \
( model_parameters.dimension,model_parameters.number_of_balls + 1) \
)
velocities=cd.reshape(\
x[model_parameters.dimension * (model_parameters.number_of_balls + 1):, 0], \
(model_parameters.dimension,model_parameters.number_of_balls)\
)
# compute distance between masses
distance_between_balls = \
positions[0:model_parameters.dimension, 1:model_parameters.number_of_balls + 1 ] - \
positions[0:model_parameters.dimension, 0:model_parameters.number_of_balls ]
# add the distance(and its norm) between the first ball and the fixed wall
distance_between_balls = cd.horzcat(
positions[0:model_parameters.dimension, 0],distance_between_balls \
)
distance_between_balls_norm = cd.sqrt(cd.sum1(distance_between_balls ** 2))
# calculate force between balls on springs
def T2W(T,p,dp):
"""
w_101 = T2W(T_10,p,dp)
"""
R = T2R(T)
dR = c.reshape(c.mul(c.jacobian(R,p),dp),(3,3))
return invskew(c.mul(R.T,dR))
v = x_i[label][name]
ind = self.q_i[child][name]
sym2 = MX.zeros(sym.size())
sym2[ind] = v
sym2 = reshape(sym2, sym.shape)
c = substitute(c, sym, sym2)
break
for nghb in self.q_ij.keys():
for label, child in nghb.group.items():
if sym.name() in child.symbol_dict:
name = child.symbol_dict[sym.name()][1]
v = z_ij[nghb.label, label, name]
ind = self.q_ij[nghb][child][name]
sym2 = MX.zeros(sym.size())
sym2[ind] = v
sym2 = reshape(sym2, sym.shape)
c = substitute(c, sym, sym2)
break
for name, s in self.par_global.items():
if s.name() == sym.name():
c = substitute(c, sym, par[name])
lb, ub = con[1], con[2]
self.define_constraint(c, lb, ub)
# construct problem
prob, buildtime = self.father_updx.construct_problem(
self.options, str(self._index), problem)
self.problem_upd_xz = prob
self.father_updx.init_transformations(self.problem.init_primal_transform,
self.problem.init_dual_transform)
self.init_var_dd()
return buildtime