splamm.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 setup phase, i.e. this module
  21. * accesses malloc and hence should not go on an embedded platform.
  22. */
  23. #ifndef __SPLAMM_H__
  24. #define __SPLAMM_H__
  25. #include "glblopts.h"
  26. #include "spla.h"
  27. /**
  28. * Create a sparse matrix from existing arrays.
  29. */
  30. spmat* ecoscreateSparseMatrix(idxint m, idxint n, idxint nnz, idxint* jc, idxint* ir, pfloat* pr);
  31. /**
  32. * Create a new sparse matrix (uses MALLOC!)
  33. */
  34. spmat* newSparseMatrix(idxint m, idxint n, idxint nnz);
  35. /**
  36. * Create a new sparse matrix (uses FREE!)
  37. */
  38. void freeSparseMatrix(spmat* M);
  39. /**
  40. * Transpose a matrix; returns A = M' (uses malloc!)
  41. */
  42. spmat* transposeSparseMatrix(spmat* M, idxint* MtoMt);
  43. /**
  44. * Permutes a symmetric matrix with only the upper triangular part stored.
  45. * Writes the upper triangular part of C = A(p,p) in column compressed
  46. * storage format.
  47. *
  48. * The function additionally returns the mapping PK that maps the row indices
  49. * of the sparse matrix A on the row indices of C, such that C[P[k]] = A[k].
  50. *
  51. * NOTE: The matrix C and the vector PK are NOT created within this function
  52. * - you need to allocate them beforehand!!
  53. *
  54. * If PK is NULL then the last output argument is ignored.
  55. */
  56. void permuteSparseSymmetricMatrix(spmat* A, idxint* pinv, spmat* C, idxint* PK);
  57. /**
  58. * Returns the inverse of permutation p of length n.
  59. */
  60. void pinv(idxint n, idxint* p, idxint* pinv);
  61. /**
  62. * Returns a copy of a sparse matrix A.
  63. */
  64. spmat* copySparseMatrix(spmat* A);
  65. /* ============================= DEBUG FUNCTIONS ======================= */
  66. #if PRINTLEVEL > 0
  67. /**
  68. * Prints a dense matrix.
  69. */
  70. void printDenseMatrix(pfloat *M, idxint dim1, idxint dim2, char *name);
  71. /**
  72. * Prints a dense integer matrix.
  73. */
  74. void printDenseMatrix_i(idxint *M, idxint dim1, idxint dim2, char *name);
  75. /**
  76. * Prints a sparse matrix.
  77. */
  78. void printSparseMatrix(spmat* M);
  79. /**
  80. * Dumps a sparse matrix in Matlab format.
  81. * Use SPCONVERT to read in the file.
  82. */
  83. void dumpSparseMatrix(spmat* M, char* fn);
  84. /**
  85. * Dumps a dense matrix of doubles to a CSV file.
  86. */
  87. void dumpDenseMatrix(pfloat *M, int dim1, int dim2, char *fn);
  88. /**
  89. * Dumps a dense matrix of integers to a CSV file.
  90. */
  91. void dumpDenseMatrix_i(idxint *M, int dim1, int dim2, char *fn);
  92. #endif
  93. #endif