dgetf2.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2016 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. //DGETF2 computes the LU factorization of a matrix A. Similar to LAPACK routine
  14. //of same name. Result matrix holds both Upper and Lower triangular matrix, with
  15. //lower matrix diagonal implied since it is a unit triangular matrix.
  16. //This version does not permute the rows.
  17. //This version does not support a sub-matrix, hence no LDA argument.
  18. //This routine would be better if dlamch were available to determine safe min
  19. #include <math.h>
  20. #include "eclblas.hpp"
  21. namespace eclblas {
  22. ECLBLAS_CALL void dgetf2(bool & __isAllResult, size32_t & __lenResult,
  23. void * & __result, uint32_t m, uint32_t n,
  24. bool isAllA, size32_t lenA, const void* a) {
  25. //double sfmin = dlamch('S'); // get safe minimum
  26. unsigned int cells = m*n;
  27. __isAllResult = false;
  28. __lenResult = cells * sizeof(double);
  29. double *new_a = (double*) rtlMalloc(__lenResult);
  30. memcpy(new_a, a, __lenResult);
  31. double akk;
  32. unsigned int i, k;
  33. unsigned int diag, vpos, wpos, mpos;
  34. unsigned int sq_dim = (m < n) ? m : n;
  35. for (k=0; k<sq_dim; k++) {
  36. diag = (k*m) + k; // diag cell
  37. vpos = diag + 1; // top cell of v vector
  38. wpos = diag + m; // left cell of w vector
  39. mpos = diag + m + 1; //upper left of sub-matrix to update
  40. akk = new_a[diag];
  41. if (akk == 0.0) {
  42. rtlFree(new_a);
  43. rtlFail(0, "Permute required"); // need to permute
  44. }
  45. //Ideally, akk should be tested against sfmin, and dscal used
  46. // to update the vector for the L cells.
  47. for (i=vpos; i<vpos+m-k-1; i++) new_a[i] = new_a[i]/akk;
  48. //Update sub-matrix
  49. if (k < sq_dim - 1) {
  50. cblas_dger(CblasColMajor,
  51. m-k-1, n-k-1, -1.0, // sub-matrix dimensions
  52. (new_a+vpos), 1, (new_a+wpos), m, (new_a+mpos), m);
  53. }
  54. }
  55. __result = (void*) new_a;
  56. }
  57. }