Rigid Body Dynamics Library
MX_Xd_utils.h
Go to the documentation of this file.
1#ifndef MX_XD_UTILS_H
2#define MX_XD_UTILS_H
3
8
9
10namespace RBDLCasadiMath {
11
12template <unsigned int nrows, unsigned int ncols>
15 const MX_Xd_scalar& other) {
16 return casadi::MX::mtimes(me, other);
17}
18template <unsigned int nrows, unsigned int ncols>
21 const double& other) {
22 return casadi::MX::mtimes(me, other);
23}
24template <unsigned int nrows, unsigned int ncols>
26 const MX_Xd_scalar& other,
28 ) {
29 return casadi::MX::mtimes(me, other);
30}
31template <unsigned int nrows, unsigned int ncols>
33 const double& other,
35 ) {
36 return casadi::MX::mtimes(me, other);
37}
38
39template <unsigned int nrows, unsigned int ncols>
42 const MX_Xd_dynamic& other) {
44 return out.casadi::MX::operator+=(other);
45}
46template <unsigned int nrows, unsigned int ncols>
49 const MX_Xd_SubMatrix& other) {
51 return out.casadi::MX::operator+=(other);
52}
54 MX_Xd_scalar me,
55 const MX_Xd_SubMatrix& other) {
56 return me.casadi::MX::operator+=(other);
57}
59 MX_Xd_scalar me,
60 const double& other) {
61 return me.casadi::MX::operator+=(other);
62}
63template <unsigned int nrows, unsigned int ncols>
65 const MX_Xd_SubMatrix& me,
66 const MX_Xd_static<nrows, ncols>& other) {
68 return out.casadi::MX::operator+=(me);
69}
70
71template <unsigned int nrows, unsigned int ncols>
73 const MX_Xd_static<nrows, ncols>& other) {
74 return other.casadi::MX::operator-();
75}
76template <unsigned int nrows, unsigned int ncols>
79 const MX_Xd_dynamic& other) {
81 return out.casadi::MX::operator-=(other);
82}
83template <unsigned int nrows, unsigned int ncols>
86 const MX_Xd_SubMatrix& other) {
88 return out.casadi::MX::operator-=(other);
89}
90template <unsigned int nrows, unsigned int ncols>
92 const MX_Xd_SubMatrix& me,
93 const MX_Xd_static<nrows, ncols>& other) {
95 return out.casadi::MX::operator-=(me);
96}
97
99 const MX_Xd_SubMatrix& me,
100 const MX_Xd_scalar& other){
101 return MX_Xd_SubMatrix::times(me, other);
102}
104 const MX_Xd_SubMatrix& me,
105 const MX_Xd_SubMatrix& other){
106 return MX_Xd_SubMatrix::mtimes(me, other);
107}
108
110 const MX_Xd_SubMatrix& me,
111 const MX_Xd_SubMatrix& scalar) {
112 MX_Xd_SubMatrix result (me);
113 result.MX_Xd_SubMatrix::operator/=(scalar);
114 return result;
115}
117 const MX_Xd_SubMatrix& me,
118 const double& scalar) {
119 MX_Xd_SubMatrix result (me);
120 result.MX_Xd_SubMatrix::operator/=(scalar);
121 return result;
122}
123
125 const MX_Xd_scalar& m1,
126 const MX_Xd_dynamic m2){
127 return casadi::MX::mtimes(m1, m2);
128}
130 const double& m1,
131 const MX_Xd_dynamic m2){
132 return casadi::MX::mtimes(m1, m2);
133}
135 const double& m1,
136 const MX_Xd_SubMatrix m2){
137 return casadi::MX::mtimes(m1, m2);
138}
139template <unsigned int nrows, unsigned int ncols>
142 const MX_Xd_dynamic m2){
143 return casadi::MX::mtimes(m1, m2);
144}
145template <unsigned int nrows, unsigned int ncols>
147 const MX_Xd_dynamic m1,
149 return casadi::MX::mtimes(m1, m2);
150}
151template <unsigned int nrows, unsigned int ncols>
153 const MX_Xd_SubMatrix& m1,
155 return casadi::MX::mtimes(m1, m2);
156}
157template <unsigned int nrows, unsigned int ncols>
160 const MX_Xd_SubMatrix& m2){
161 return casadi::MX::mtimes(m1, m2);
162}
163
164inline MX_Xd_dynamic operator/(double scalar, MX_Xd_SubMatrix mat){
165 for (unsigned int i=0; i<mat.rows(); ++i){
166 for (unsigned int j=0; j<mat.columns(); ++j){
167 mat(i, j) = scalar / mat(i, j);
168 }
169 }
170 return mat;
171}
172inline MX_Xd_dynamic operator/(double scalar, MX_Xd_dynamic mat){
173 for (unsigned int i=0; i<mat.rows(); ++i){
174 for (unsigned int j=0; j<mat.columns(); ++j){
175 mat(i, j) = scalar / mat(i, j);
176 }
177 }
178 return mat;
179}
180inline MX_Xd_scalar operator/(double scalar, const MX_Xd_scalar& mat){
181 MX_Xd_scalar out(scalar);
182 return out.casadi::MX::operator/=(mat(0, 0));
183}
184template <unsigned int nrows, unsigned int ncols>
186 for (unsigned int i=0; i<nrows; ++i){
187 for (unsigned int j=0; j<ncols; ++j){
188 mat(i, j) = scalar / mat(i, j);
189 }
190 }
191 return mat;
192}
193
194
195template <unsigned int nrows, unsigned int ncols>
197 const MX_Xd_dynamic& me,
198 const MX_Xd_static<nrows, ncols>& other
199 ) {
201 return out.casadi::MX::operator+=(other);
202}
204 const MX_Xd_dynamic& me) {
205 return me.casadi::MX::operator-();
206}
208 const MX_Xd_SubMatrix& me) {
209 return me.casadi::MX::operator-();
210}
213 const MX_Xd_scalar& scalar){
214 return me.casadi::SubMatrix<casadi::MX, casadi::Slice, casadi::Slice>::operator-=(scalar);
215}
217 MX_Xd_scalar me,
218 const MX_Xd_SubMatrix& other) {
219 return me.casadi::MX::operator-=(other);
220}
222 const MX_Xd_dynamic& me,
223 const MX_Xd_scalar& other
224 ) {
225 MX_Xd_scalar out(me);
226 return out.casadi::MX::operator+=(other);
227}
229 const MX_Xd_scalar& me,
230 const MX_Xd_dynamic& other
231 ) {
232 MX_Xd_scalar out(me);
233 return out.casadi::MX::operator+=(other);
234}
236 const MX_Xd_SubMatrix& me,
237 const MX_Xd_dynamic& other
238 ) {
239 MX_Xd_dynamic out(other);
240 return out.casadi::MX::operator+=(me);
241}
243 const MX_Xd_dynamic& me,
244 const MX_Xd_SubMatrix& other
245 ) {
246 MX_Xd_dynamic out(me);
247 return out.casadi::MX::operator+=(other);
248}
249
252 const MX_Xd_SubMatrix& other){
253 return me.casadi::SubMatrix<casadi::MX, casadi::Slice, casadi::Slice>::operator+=(other);
254}
255
256template <unsigned int nrows, unsigned int ncols>
258 const MX_Xd_dynamic& me,
259 const MX_Xd_static<nrows, ncols>& other
260 ) {
262 return out.casadi::MX::operator-=(other);
263}
265 const MX_Xd_dynamic& me,
266 const MX_Xd_scalar& other
267 ) {
268 MX_Xd_scalar out(me);
269 return out.casadi::MX::operator-=(other);
270}
272 const MX_Xd_scalar& me,
273 const MX_Xd_dynamic& other
274 ) {
275 MX_Xd_scalar out(me);
276 return out.casadi::MX::operator-=(other);
277}
279 const MX_Xd_SubMatrix& me,
280 const MX_Xd_dynamic& other
281 ) {
282 MX_Xd_dynamic out(-other);
283 return out.casadi::MX::operator+=(me);
284}
286 const MX_Xd_dynamic& me,
287 const MX_Xd_SubMatrix& other
288 ) {
289 MX_Xd_dynamic out(me);
290 return out.casadi::MX::operator-=(other);
291}
293 const MX_Xd_SubMatrix& me,
294 const MX_Xd_SubMatrix& other
295 ) {
296 MX_Xd_dynamic out(me);
297 return out.casadi::MX::operator-=(other);
298}
299
300
302 double other,
303 const MX_Xd_scalar& me
304 ) {
305 return casadi::MX::times(me, other);
306}
308 const MX_Xd_scalar& other,
309 const MX_Xd_SubMatrix& me
310 ) {
311 return casadi::MX::times(me, other);
312}
313
315 double other,
316 const MX_Xd_scalar& me) {
317 MX_Xd_scalar out(me);
318 return out.casadi::MX::operator+=(other);
319}
320
322 const MX_Xd_scalar& other) {
323 return other.casadi::MX::operator-();
324}
326 double other,
327 const MX_Xd_scalar& me) {
328 MX_Xd_scalar out(-me);
329 return out.casadi::MX::operator+=(other);
330}
331
332}
333
334
336 return casadi::MX::exp(x);
337}
338
339namespace std {
340using namespace RBDLCasadiMath;
341
343 return casadi::MX::sqrt(x);
344}
346 return casadi::MX::sin(x);
347}
349 return casadi::MX::asin(x);
350}
352 return casadi::MX::cos(x);
353}
355 return casadi::MX::acos(x);
356}
358 return casadi::MX::tan(x);
359}
360inline MX_Xd_scalar atan2(const MX_Xd_scalar& x, const MX_Xd_scalar& y){
361 return casadi::MX::atan2(x,y);
362}
364 return casadi::MX::tanh(x);
365}
366inline bool isnan(const casadi::MX& x){
367 return !x.is_regular();
368}
369
370template <unsigned int nrows, unsigned int ncols>
372 return casadi::MX::abs(m);
373}
374template <unsigned int nrows, unsigned int ncols>
376 return casadi::MX::abs(m);
377}
379 return casadi::MX::abs(m);
380}
381
382template <unsigned int nrows, unsigned int ncols>
384 return casadi::MX::mpower(m, exponent);
385}
386template <unsigned int nrows, unsigned int ncols>
387inline MX_Xd_static<nrows, ncols> pow(const MX_Xd_static<nrows, ncols>& m, unsigned int exponent){
388 return casadi::MX::mpower(m, exponent);
389}
390template <unsigned int nrows, unsigned int ncols>
392 return casadi::MX::mpower(m, exponent);
393}
394inline MX_Xd_scalar pow(const MX_Xd_scalar& m, int exponent){
395 return casadi::MX::mpower(m, exponent);
396}
397inline MX_Xd_scalar pow(const MX_Xd_scalar& m, unsigned int exponent){
398 return casadi::MX::mpower(m, exponent);
399}
400inline MX_Xd_scalar pow(const MX_Xd_scalar& m, double exponent){
401 return casadi::MX::mpower(m, exponent);
402}
403
404}
405
406#endif
RBDLCasadiMath::MX_Xd_scalar exp(const RBDLCasadiMath::MX_Xd_scalar &x)
Definition: MX_Xd_utils.h:335
unsigned int rows() const
Definition: MX_Xd_dynamic.h:95
MX_Xd_static< nrows, ncols > operator*(const MX_Xd_static< nrows, ncols > &me, const MX_Xd_scalar &other)
Definition: MX_Xd_utils.h:13
MX_Xd_static< nrows, ncols > operator+(const MX_Xd_static< nrows, ncols > &me, const MX_Xd_dynamic &other)
Definition: MX_Xd_utils.h:40
MX_Xd_static< nrows, ncols > operator-(const MX_Xd_static< nrows, ncols > &other)
Definition: MX_Xd_utils.h:72
MX_Xd_SubMatrix operator/(const MX_Xd_SubMatrix &me, const MX_Xd_SubMatrix &scalar)
Definition: MX_Xd_utils.h:109
STL namespace.
bool isnan(const casadi::MX &x)
Definition: MX_Xd_utils.h:366
MX_Xd_dynamic fabs(const MX_Xd_dynamic &m)
Definition: MX_Xd_utils.h:371
MX_Xd_static< nrows, ncols > pow(const MX_Xd_static< nrows, ncols > &m, int exponent)
Definition: MX_Xd_utils.h:383
MX_Xd_scalar sqrt(const MX_Xd_scalar &x)
Definition: MX_Xd_utils.h:342
MX_Xd_scalar acos(const MX_Xd_scalar &x)
Definition: MX_Xd_utils.h:354
MX_Xd_scalar atan2(const MX_Xd_scalar &x, const MX_Xd_scalar &y)
Definition: MX_Xd_utils.h:360
MX_Xd_scalar cos(const MX_Xd_scalar &x)
Definition: MX_Xd_utils.h:351
MX_Xd_scalar tan(const MX_Xd_scalar &x)
Definition: MX_Xd_utils.h:357
MX_Xd_scalar tanh(const MX_Xd_scalar &x)
Definition: MX_Xd_utils.h:363
MX_Xd_scalar sin(const MX_Xd_scalar &x)
Definition: MX_Xd_utils.h:345
MX_Xd_scalar asin(const MX_Xd_scalar &x)
Definition: MX_Xd_utils.h:348