cholesky.h 5.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*Daala video codec
  2. Copyright (c) 2008-2012 Daala project contributors. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. - Redistributions of source code must retain the above copyright notice, this
  6. list of conditions and the following disclaimer.
  7. - Redistributions in binary form must reproduce the above copyright notice,
  8. this list of conditions and the following disclaimer in the documentation
  9. and/or other materials provided with the distribution.
  10. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
  11. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  12. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  13. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  14. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  15. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  16. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  17. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  18. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  19. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
  20. #if !defined(_cpack_linalg_cholesky_H)
  21. # define _cpack_linalg_cholesky_H (1)
  22. # include "matidx.h"
  23. /*Computes the Cholesky decomposition of the symmetric positive semidefinite
  24. matrix A=R^T.R, R upper-triangular.
  25. @param _rr On input, contains the upper-triangular portion of A packed
  26. linearly in row-wise fashion, i.e.,
  27. _rr[UT_IDX(i,j,_n)]=A_ij, i<=j.
  28. On output, returns the upper-trapezoidal matrix R packed
  29. linearly in row-wise fashion, i.e.,
  30. _rr[UT_IDX(i,j,_n)]=R_ij, i<=j.
  31. Only the first r rows of R are computed, where r is the rank
  32. of A; the remaining rows are taken to be zero, but their
  33. contents in _rr are undefined.
  34. @param _pivot Returns the pivot list, so that column i of R corresponds to
  35. row and column _pivot[i] of A.
  36. That is, if A'=R^T.R, then A_{_pivot[i],_pivot[j]}=A'_ij.
  37. This may be NULL to skip pivoting, but will result in less
  38. accuracy and a less reliable positive-definite test.
  39. @param _tol The expected relative error in the elements of A (e.g.,
  40. DBL_EPSILON).
  41. @param _n The number of rows and columns in A.
  42. @return The number of positive eigenvalues of A encountered, r.
  43. If A is positive semidefinite and pivoting was enabled, this is also
  44. the estimated rank of A.*/
  45. int cholesky(double *_rr,int *_pivot,double _tol,int _n);
  46. /*Computes the complete orthogonal decomposition of the upper-trapezoidal _r by
  47. _n matrix R, in the case that A was positive semidefinite.
  48. That is, computes R' and V such that R={{R',0}}.V, R' is an _r by _r
  49. upper-triangular matrix, and V is orthogonal.
  50. This allows computation of the pseudoinverse and the minimum norm solution of
  51. rank-deficient least squares problems (e.g., by chsolve()).
  52. @param _rr On input, contains the upper-trapezoidal matrix R packed linearly
  53. in row-wise fashion, i.e., _rr[UT_IDX(i,j,_n)]=R_ij, i<=j.
  54. On output, returns the new upper-triangular matrix packed into
  55. the left portion of _rr, and the Householder vectors used to
  56. annihilate the last _n-_r columns in the right portion.
  57. @param _tau Returns the _r scale factors of the Householder reflections.
  58. @param _r The number of rows (the rank) of R, _r<=_n.
  59. @param _n The number of columns of R.*/
  60. void chdecomp(double *_rr,double *_tau,int _r,int _n);
  61. /*Returns the number of elements needed in the work array for chsolve().
  62. The contents of _pivot need not be initialized, but it must be non-NULL if
  63. pivoting will be used.*/
  64. int chsolve_worksz(const int *_pivot,int _n);
  65. /*Solves the system R^T.R.x=b given a full-rank upper-triangular matrix R or a
  66. complete orthogonal decomposition (for rank-deficient R).
  67. @param _rr In the case that _r==_n, the full-rank upper-triangular matrix
  68. R as computed by cholesky() or rrcholesky().
  69. Otherwise, the complete orthogonal decomposition as computed by
  70. chdecomp().
  71. @param _pivot The pivot list as computed by cholesky() or rrcholesky(), so
  72. that column i of R corresponds to element _pivot[i] of _x and
  73. _b.
  74. This may be NULL if no pivoting was done.
  75. @param _tau The scale values of the Householder reflectors for a
  76. rank-deficient solution.
  77. This paramter is ignored if _r==_n.
  78. @param _x Returns the solution vector.
  79. This may be aliased to _b to compute the solution in-place.
  80. @param _b Contains the right hand side.
  81. @param _work Work array with chsolve_worksz() elements, or NULL to allocate
  82. one internally.
  83. @param _r The number of rows in R.
  84. @param _n The number of columns in R.*/
  85. void chsolve(const double *_rr,const int *_pivot,const double *_tau,double *_x,
  86. const double *_b,double *_work,int _r,int _n);
  87. #endif