spla.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * ECOS - Embedded Conic Solver.
  3. * Copyright (C) 2012-2015 A. Domahidi [domahidi@embotech.com],
  4. * Automatic Control Lab, ETH Zurich & embotech GmbH, Zurich, Switzerland.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /*
  20. * Sparse linear algebra library for solver, i.e. no memory manager
  21. * such as malloc is accessed by this module.
  22. */
  23. #ifndef __SPLA_H__
  24. #define __SPLA_H__
  25. #include "glblopts.h"
  26. /* Data structure for sparse matrices */
  27. typedef struct spmat{
  28. idxint* jc;
  29. idxint* ir;
  30. pfloat* pr;
  31. idxint n;
  32. idxint m;
  33. idxint nnz;
  34. } spmat;
  35. /* SPARSE MATRIX OPERATIONS PROVIDED BY THIS MODULE -------------------- */
  36. /*
  37. * Sparse matrix-vector multiply for operations
  38. *
  39. * y = A*x (if a > 0 && newVector == 1)
  40. * y += A*x (if a > 0 && newVector == 0)
  41. * y = -A*x (if a < 0 && newVector == 1)
  42. * y -= A*x (if a < 0 && newVector == 0)
  43. *
  44. * where A is a sparse matrix and both x and y are assumed to be dense.
  45. */
  46. void sparseMV(spmat* A, pfloat* x, pfloat* y, idxint a, idxint newVector);
  47. /*
  48. * Sparse matrix-transpose-vector multiply with subtraction.
  49. *
  50. * If newVector > 0, then this computes y = -A'*x,
  51. * otherwise y -= A'*x,
  52. *
  53. * where A is a sparse matrix and both x and y are assumed to be dense.
  54. * If skipDiagonal == 1, then the contributions of diagonal elements are
  55. * not counted.
  56. *
  57. * NOTE: The product is calculating without explicitly forming the
  58. * transpose.
  59. */
  60. void sparseMtVm(spmat* A, pfloat* x, pfloat* y, idxint newVector, idxint skipDiagonal);
  61. /*
  62. * Vector addition y += x of size n.
  63. */
  64. void vadd(idxint n, pfloat* x, pfloat* y);
  65. /*
  66. * Vector subtraction with scaling: y -= a*x of size n.
  67. */
  68. void vsubscale(idxint n, pfloat a, pfloat* x, pfloat* y);
  69. /*
  70. * 2-norm of a vector.
  71. */
  72. pfloat norm2(pfloat* v, idxint n);
  73. /*
  74. * inf-norm of a vector.
  75. */
  76. pfloat norminf(pfloat* v, idxint n);
  77. /*
  78. * ECOS dot product z = x'*y of size n.
  79. */
  80. pfloat eddot(idxint n, pfloat* x, pfloat* y);
  81. #endif