35 #include <qpOASES.hpp> 42 const char *
const TRANS =
"TRANS";
96 for ( i=0; i<
nRows; ++i )
110 for (i = 0; i < icols->
length; i++)
113 for (i = 0; i < icols->
length; i++)
116 for (i = 0; i < icols->
length; i++)
122 for (i = 0; i <
nCols; i++)
125 for (i = 0; i <
nCols; i++)
128 for (i = 0; i <
nCols; i++)
139 for (i = 0; i < irows->
length; i++)
142 for (i = 0; i < irows->
length; i++)
145 for (i = 0; i < irows->
length; i++)
155 GEMM(
TRANS,
NOTRANS, &_nRows, &_xN, &_nCols, &alpha,
val, &_nCols, x, &_xLD, &beta, y, &_yLD);
163 GEMM(
NOTRANS,
NOTRANS, &_nCols, &_xN, &_nRows, &alpha,
val, &_nCols, x, &_xLD, &beta, y, &_yLD);
171 int i, j, k,
row,
col, iy, irA;
176 for (k = 0; k < xN; k++)
177 for (j = 0; j < irows->
length; j++)
180 for (k = 0; k < xN; k++)
181 for (j = 0; j < irows->
length; j++)
182 y[j+k*yLD] = -y[j+k*yLD];
184 for (k = 0; k < xN; k++)
185 for (j = 0; j < irows->
length; j++)
190 for (k = 0; k < xN; k++)
191 for (j = 0; j < irows->
length; j++)
193 row = irows->
iSort[j];
196 for (i = 0; i <
nCols; i++)
197 y[iy] +=
val[irA+i] * x[k*xLD+i];
200 for (k = 0; k < xN; k++)
201 for (j = 0; j < irows->
length; j++)
203 row = irows->
iSort[j];
206 for (i = 0; i <
nCols; i++)
207 y[iy] -=
val[irA+i] * x[k*xLD+i];
210 for (k = 0; k < xN; k++)
211 for (j = 0; j < irows->
length; j++)
213 row = irows->
iSort[j];
216 for (i = 0; i <
nCols; i++)
217 y[iy] += alpha *
val[irA+i] * x[k*xLD+i];
221 for (k = 0; k < xN; k++)
222 for (j = 0; j < irows->
length; j++)
224 row = irows->
iSort[j];
227 for (i = 0; i < icols->
length; i++)
229 col = icols->
iSort[i];
234 for (k = 0; k < xN; k++)
235 for (j = 0; j < irows->
length; j++)
237 row = irows->
iSort[j];
240 for (i = 0; i < icols->
length; i++)
242 col = icols->
iSort[i];
247 for (k = 0; k < xN; k++)
248 for (j = 0; j < irows->
length; j++)
250 row = irows->
iSort[j];
253 for (i = 0; i < icols->
length; i++)
255 col = icols->
iSort[i];
263 for (k = 0; k < xN; k++)
264 for (j = 0; j < irows->
length; j++)
265 y[irows->
number[j]+k*yLD] = 0.0;
267 for (k = 0; k < xN; k++)
268 for (j = 0; j < irows->
length; j++)
269 y[irows->
number[j]+k*yLD] = -y[j+k*yLD];
271 for (k = 0; k < xN; k++)
272 for (j = 0; j < irows->
length; j++)
273 y[irows->
number[j]+k*yLD] *= beta;
277 for (k = 0; k < xN; k++)
278 for (j = 0; j < irows->
length; j++)
283 for (i = 0; i <
nCols; i++)
284 y[iy] +=
val[irA+i] * x[k*xLD+i];
287 for (k = 0; k < xN; k++)
288 for (j = 0; j < irows->
length; j++)
293 for (i = 0; i <
nCols; i++)
294 y[iy] -=
val[irA+i] * x[k*xLD+i];
297 for (k = 0; k < xN; k++)
298 for (j = 0; j < irows->
length; j++)
303 for (i = 0; i <
nCols; i++)
304 y[iy] += alpha *
val[irA+i] * x[k*xLD+i];
308 for (k = 0; k < xN; k++)
309 for (j = 0; j < irows->
length; j++)
314 for (i = 0; i < icols->
length; i++)
316 col = icols->
iSort[i];
321 for (k = 0; k < xN; k++)
322 for (j = 0; j < irows->
length; j++)
327 for (i = 0; i < icols->
length; i++)
329 col = icols->
iSort[i];
334 for (k = 0; k < xN; k++)
335 for (j = 0; j < irows->
length; j++)
340 for (i = 0; i < icols->
length; i++)
342 col = icols->
iSort[i];
357 for (k = 0; k < xN; k++)
358 for (j = 0; j < icols->
length; j++)
361 for (k = 0; k < xN; k++)
362 for (j = 0; j < icols->
length; j++)
363 y[j+k*yLD] = -y[j+k*yLD];
365 for (k = 0; k < xN; k++)
366 for (j = 0; j < icols->
length; j++)
370 for (k = 0; k < xN; k++)
371 for (j = 0; j < irows->
length; j++)
373 row = irows->
iSort[j];
374 for (i = 0; i < icols->
length; i++)
376 col = icols->
iSort[i];
381 for (k = 0; k < xN; k++)
382 for (j = 0; j < irows->
length; j++)
384 row = irows->
iSort[j];
385 for (i = 0; i < icols->
length; i++)
387 col = icols->
iSort[i];
392 for (k = 0; k < xN; k++)
393 for (j = 0; j < irows->
length; j++)
395 row = irows->
iSort[j];
396 for (i = 0; i < icols->
length; i++)
398 col = icols->
iSort[i];
451 for (ii = 0; ii < xN; ii++)
452 for (jj = 0; jj < xN; jj++)
457 for (i=0;i<icols->
length * xN;++i)
461 for (j = 0; j < icols->
length; j++) {
463 for (i = 0; i < icols->
length; i++)
466 for (k = 0; k < xN; k++)
467 Ax[j + k * icols->
length] += h * x[k*xLD+icols->
number[i]];
471 for (ii = 0; ii < icols->
length; ++ii) {
473 for (jj = 0; jj < xN; ++jj) {
474 for (kk = 0; kk < xN; ++kk) {
475 y[kk + jj*yLD] += x[col + jj*xLD] * Ax[ii + kk*icols->
length];
495 ir =
new long[nr*nc];
499 for (j = 0; j <
nCols; j++)
502 for (i = 0; i <
nRows; i++)
506 val[nnz++] = v[i*ld+j];
522 if (
ir != 0)
delete[]
ir;
524 if (
jc != 0)
delete[]
jc;
526 if (
jd != 0)
delete[]
jd;
528 if (
val != 0)
delete[]
val;
540 dupl->
ir =
new long[length];
545 for (i = 0; i < length; i++) dupl->
ir[i] =
ir[i];
546 for (i = 0; i <=
nCols; i++) dupl->
jc[i] =
jc[i];
547 for (i = 0; i <
nCols; i++) dupl->
jd[i] =
jd[i];
548 for (i = 0; i < length; i++) dupl->
val[i] =
val[i];
558 return (entry <
jc[i+1] &&
ir[entry] == i) ?
val[entry] : 0.0;
573 for (k = 0; k < icols->
length; k++)
576 for (i =
jc[j]; i <
jc[j+1] &&
ir[i] < rNum; i++);
577 row[icols->
iSort[k]] = (i <
jc[j+1] &&
ir[i] == rNum) ?
val[i] : 0.0;
580 for (k = 0; k < icols->
length; k++)
583 for (i =
jc[j]; i <
jc[j+1] &&
ir[i] < rNum; i++);
584 row[icols->
iSort[k]] = (i <
jc[j+1] &&
ir[i] == rNum) ? -
val[i] : 0.0;
587 for (k = 0; k < icols->
length; k++)
590 for (i =
jc[j]; i <
jc[j+1] &&
ir[i] < rNum; i++);
591 row[icols->
iSort[k]] = (i <
jc[j+1] &&
ir[i] == rNum) ? alpha*
val[i] : 0.0;
597 for (j = 0; j <
nCols; j++)
599 for (i =
jc[j]; i <
jc[j+1] &&
ir[i] < rNum; i++);
600 row[j] = (i <
jc[j+1] &&
ir[i] == rNum) ?
val[i] : 0.0;
603 for (j = 0; j < icols->
length; j++)
605 for (i =
jc[j]; i <
jc[j+1] &&
ir[i] < rNum; i++);
606 row[j] = (i <
jc[j+1] &&
ir[i] == rNum) ? -
val[i] : 0.0;
609 for (j = 0; j < icols->
length; j++)
611 for (i =
jc[j]; i <
jc[j+1] &&
ir[i] < rNum; i++);
612 row[j] = (i <
jc[j+1] &&
ir[i] == rNum) ? alpha*
val[i] : 0.0;
625 while (i <
jc[cNum+1] && j < irows->length)
629 col[irows->
iSort[j++]] = 0.0;
633 while (i <
jc[cNum+1] && j < irows->length)
637 col[irows->
iSort[j++]] = 0.0;
641 while (i <
jc[cNum+1] && j < irows->length)
643 col[irows->
iSort[j++]] = alpha *
val[i++];
645 col[irows->
iSort[j++]] = 0.0;
650 while (j < irows->length)
651 col[irows->
iSort[j++]] = 0.0;
662 for (k = 0; k < xN; k++)
663 for (j = 0; j <
nRows; j++)
666 for (k = 0; k < xN; k++)
667 for (j = 0; j <
nRows; j++)
668 y[j+k*yLD] = -y[j+k*yLD];
670 for (k = 0; k < xN; k++)
671 for (j = 0; j <
nRows; j++)
675 for (k = 0; k < xN; k++)
676 for (j = 0; j <
nCols; j++)
677 for (i =
jc[j]; i <
jc[j+1]; i++)
678 y[
ir[i]+k*yLD] +=
val[i] * x[j+k*xLD];
680 for (k = 0; k < xN; k++)
681 for (j = 0; j <
nCols; j++)
682 for (i = jc[j]; i < jc[j+1]; i++)
683 y[
ir[i]+k*yLD] -=
val[i] * x[j+k*xLD];
685 for (k = 0; k < xN; k++)
686 for (j = 0; j <
nCols; j++)
687 for (i = jc[j]; i < jc[j+1]; i++)
688 y[
ir[i]+k*yLD] += alpha *
val[i] * x[j+k*xLD];
699 for (k = 0; k < xN; k++)
700 for (j = 0; j <
nCols; j++)
703 for (k = 0; k < xN; k++)
704 for (j = 0; j <
nCols; j++)
705 y[j+k*yLD] = -y[j+k*yLD];
707 for (k = 0; k < xN; k++)
708 for (j = 0; j <
nCols; j++)
712 for (k = 0; k < xN; k++)
713 for (j = 0; j <
nCols; j++)
714 for (i =
jc[j]; i <
jc[j+1]; i++)
715 y[j+k*yLD] +=
val[i] * x[
ir[i]+k*xLD];
717 for (k = 0; k < xN; k++)
718 for (j = 0; j <
nCols; j++)
719 for (i = jc[j]; i < jc[j+1]; i++)
720 y[j+k*yLD] -=
val[i] * x[
ir[i]+k*xLD];
722 for (k = 0; k < xN; k++)
723 for (j = 0; j <
nCols; j++)
724 for (i = jc[j]; i < jc[j+1]; i++)
725 y[j+k*yLD] += alpha *
val[i] * x[
ir[i]+k*xLD];
734 long i, j, k, l,
col;
739 for (k = 0; k < xN; k++)
740 for (j = 0; j < irows->
length; j++)
743 for (k = 0; k < xN; k++)
744 for (j = 0; j < irows->
length; j++)
745 y[j+k*yLD] = -y[j+k*yLD];
747 for (k = 0; k < xN; k++)
748 for (j = 0; j < irows->
length; j++)
753 for (l = 0; l <
nCols; l++)
757 while (i <
jc[l+1] && j < irows->length)
760 for (k = 0; k < xN; k++)
761 y[k*yLD+irows->
iSort[j]] +=
val[i] * x[k*xLD+l];
768 for (l = 0; l <
nCols; l++)
772 while (i <
jc[l+1] && j < irows->length)
775 for (k = 0; k < xN; k++)
776 y[k*yLD+irows->
iSort[j]] -=
val[i] * x[k*xLD+l];
783 for (l = 0; l <
nCols; l++)
787 while (i <
jc[l+1] && j < irows->length)
790 for (k = 0; k < xN; k++)
791 y[k*yLD+irows->
iSort[j]] += alpha *
val[i] * x[k*xLD+l];
799 for (l = 0; l < icols->
length; l++)
801 col = icols->
iSort[l];
804 while (i <
jc[icols->
number[col]+1] && j < irows->length)
807 for (k = 0; k < xN; k++)
808 y[k*yLD+irows->
iSort[j]] +=
val[i] * x[k*xLD+col];
815 for (l = 0; l < icols->
length; l++)
817 col = icols->
iSort[l];
820 while (i <
jc[icols->
number[col]+1] && j < irows->length)
823 for (k = 0; k < xN; k++)
824 y[k*yLD+irows->
iSort[j]] -=
val[i] * x[k*xLD+col];
831 for (l = 0; l < icols->
length; l++)
833 col = icols->
iSort[l];
836 while (i <
jc[icols->
number[col]+1] && j < irows->length)
839 for (k = 0; k < xN; k++)
840 y[k*yLD+irows->
iSort[j]] += alpha *
val[i] * x[k*xLD+col];
850 for (k = 0; k < xN; k++)
851 for (j = 0; j < irows->
length; j++)
852 y[irows->
number[j]+k*yLD] = 0.0;
854 for (k = 0; k < xN; k++)
855 for (j = 0; j < irows->
length; j++)
856 y[irows->
number[j]+k*yLD] = -y[j+k*yLD];
858 for (k = 0; k < xN; k++)
859 for (j = 0; j < irows->
length; j++)
860 y[irows->
number[j]+k*yLD] *= beta;
864 for (l = 0; l <
nCols; l++)
868 while (i <
jc[l+1] && j < irows->length)
871 for (k = 0; k < xN; k++)
879 for (l = 0; l <
nCols; l++)
883 while (i <
jc[l+1] && j < irows->length)
886 for (k = 0; k < xN; k++)
894 for (l = 0; l <
nCols; l++)
898 while (i <
jc[l+1] && j < irows->length)
901 for (k = 0; k < xN; k++)
902 y[k*yLD+irows->
number[irows->
iSort[j]]] += alpha *
val[i] * x[k*xLD+l];
910 for (l = 0; l < icols->
length; l++)
912 col = icols->
iSort[l];
915 while (i <
jc[icols->
number[col]+1] && j < irows->length)
918 for (k = 0; k < xN; k++)
926 for (l = 0; l < icols->
length; l++)
928 col = icols->
iSort[l];
931 while (i <
jc[icols->
number[col]+1] && j < irows->length)
934 for (k = 0; k < xN; k++)
942 for (l = 0; l < icols->
length; l++)
944 col = icols->
iSort[l];
947 while (i <
jc[icols->
number[col]+1] && j < irows->length)
950 for (k = 0; k < xN; k++)
951 y[k*yLD+irows->
number[irows->
iSort[j]]] += alpha *
val[i] * x[k*xLD+col];
964 long i, j, k, l,
col;
967 for (k = 0; k < xN; k++)
968 for (j = 0; j < icols->
length; j++)
971 for (k = 0; k < xN; k++)
972 for (j = 0; j < icols->
length; j++)
973 y[j+k*yLD] = -y[j+k*yLD];
975 for (k = 0; k < xN; k++)
976 for (j = 0; j < icols->
length; j++)
980 for (l = 0; l < icols->
length; l++)
982 col = icols->
iSort[l];
985 while (i <
jc[icols->
number[col]+1] && j < irows->length)
988 for (k = 0; k < xN; k++)
989 y[k*yLD+col] +=
val[i] * x[k*xLD+irows->
iSort[j]];
996 for (l = 0; l < icols->
length; l++)
998 col = icols->
iSort[l];
1001 while (i <
jc[icols->
number[col]+1] && j < irows->length)
1004 for (k = 0; k < xN; k++)
1005 y[k*yLD+col] -=
val[i] * x[k*xLD+irows->
iSort[j]];
1012 for (l = 0; l < icols->
length; l++)
1014 col = icols->
iSort[l];
1017 while (i <
jc[icols->
number[col]+1] && j < irows->length)
1020 for (k = 0; k < xN; k++)
1021 y[k*yLD+col] += alpha *
val[i] * x[k*xLD+irows->
iSort[j]];
1038 if (
ir[
jd[i]] == i)
val[
jd[i]] += alpha;
1052 for (j = 0; j <
nCols; j++)
1054 for (i =
jc[j]; i <
jc[j+1] &&
ir[i] < j; i++);
1070 for (j = 0; j <
nCols; j++)
1071 for (i =
jc[j]; i <
jc[j+1]; i++)
1072 v[
ir[i] * nCols + j] =
val[i];
1093 dupl->
ir =
new long[length];
1098 for (i = 0; i < length; i++) dupl->
ir[i] =
ir[i];
1099 for (i = 0; i <=
nCols; i++) dupl->
jc[i] =
jc[i];
1100 for (i = 0; i <
nCols; i++) dupl->
jd[i] =
jd[i];
1101 for (i = 0; i < length; i++) dupl->
val[i] =
val[i];
1111 int i, j, k, l, idx,
row,
col;
1114 for (i = 0; i < xN*xN; i++)
1118 for (l = 0; l < icols->
length; l++)
1123 while (idx <
jc[col+1] && k < icols->length)
1131 for (i = 0; i < xN; i++)
1132 for (j = i; j < xN; j++)
1133 y[i*yLD+j] +=
val[idx] * x[i*xLD+col] * x[j*xLD+col];
1135 for (i = 0; i < xN; i++)
1136 for (j = i; j < xN; j++)
1137 y[i*yLD+j] +=
val[idx] * (x[i*xLD+col] * x[j*xLD+row] + x[i*xLD+row] * x[j*xLD+col]);
1140 else if (
ir[idx] > row) k++;
1146 for (i = 0; i < xN; i++)
1147 for (j = i; j < xN; j++)
1148 y[j*yLD+i] = y[i*yLD+j];
Interfaces matrix-vector operations tailored to symmetric sparse matrices.
virtual returnValue transTimes(int xN, real_t alpha, const real_t *x, int xLD, real_t beta, real_t *y, int yLD) const
virtual BooleanType isDiag() const
virtual returnValue addToDiag(real_t alpha)
virtual returnValue getRow(int rNum, const Indexlist *const icols, real_t alpha, real_t *row) const
virtual Matrix * duplicate() const
virtual returnValue getCol(int cNum, const Indexlist *const irows, real_t alpha, real_t *col) const
BEGIN_NAMESPACE_ACADO const double EPS
virtual Matrix * duplicate() const
Allows to pass back messages to the calling function.
Interfaces matrix-vector operations tailored to symmetric dense matrices.
virtual returnValue getRow(int rNum, const Indexlist *const icols, real_t alpha, real_t *row) const
#define THROWERROR(retval)
virtual returnValue getCol(int cNum, const Indexlist *const irows, real_t alpha, real_t *col) const
returnValue myPrintf(const char *s)
virtual Matrix * duplicate() const
virtual returnValue times(int xN, real_t alpha, const real_t *x, int xLD, real_t beta, real_t *y, int yLD) const
virtual real_t diag(int i) const
Interfaces matrix-vector operations tailored to general dense matrices.
Interfaces matrix-vector operations tailored to general sparse matrices.
virtual returnValue print() const
returnValue transTimes(int xN, real_t alpha, const real_t *x, int xLD, real_t beta, real_t *y, int yLD) const
virtual Matrix * duplicate() const
virtual returnValue print() const
virtual returnValue addToDiag(real_t alpha)
Abstract base class for interfacing tailored matrix-vector operations.
virtual returnValue bilinear(const Indexlist *const icols, int xN, const real_t *x, int xLD, real_t *y, int yLD) const
const char *const NOTRANS
virtual real_t diag(int i) const
BEGIN_NAMESPACE_QPOASES const char *const TRANS
#define END_NAMESPACE_QPOASES
BooleanType needToFreeMemory() const
bool isExactlyMinusOne(real_t a)
BEGIN_NAMESPACE_QPOASES bool isExactlyOne(real_t a)
int number[INDEXLISTFACTOR *(NVMAX+NCMAX)]
Stores and manages index lists.
returnValue times(int xN, real_t alpha, const real_t *x, int xLD, real_t beta, real_t *y, int yLD) const
virtual returnValue bilinear(const Indexlist *const icols, int xN, const real_t *x, int xLD, real_t *y, int yLD) const
BEGIN_NAMESPACE_QPOASES returnValue print(const real_t *const v, int n)
virtual BooleanType isDiag() const
#define BEGIN_NAMESPACE_QPOASES
bool isExactlyZero(real_t a)