extract_tri.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. //Extract the upper triangular matrix or the lower triangular matrix
  14. //from a composite. Composites are produced by some factorizations.
  15. //
  16. #include "eclblas.hpp"
  17. namespace eclblas {
  18. ECLBLAS_CALL void extract_tri(bool & __isAllResult, size32_t & __lenResult,
  19. void * & __result, uint32_t m, uint32_t n, uint8_t tri,
  20. uint8_t dt, bool isAllA, size32_t lenA, const void * a){
  21. int cells = m * n;
  22. __isAllResult = false;
  23. __lenResult = lenA;
  24. double *new_a = (double*) rtlMalloc(lenA);
  25. unsigned int r=0; //row
  26. unsigned int c=0; //column
  27. for (int i=0; i<cells; i++) {
  28. double a_element = ((const double*)a)[i];
  29. if (r==c) new_a[i] = (dt==UNIT_TRI) ? 1.0 : a_element;
  30. else if (r > c) { // lower part
  31. new_a[i] = (tri==UPPER) ? 0.0 : a_element;
  32. } else { // upper part
  33. new_a[i] = (tri==UPPER) ? a_element : 0.0;
  34. }
  35. r++;
  36. if (r==m) {
  37. r=0;
  38. c++;
  39. }
  40. }
  41. __result = (void*) new_a;
  42. }
  43. }