dsyrk.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. // Implements symmetric rank update. C <- alpha A**T * A + beta C
  14. //or C <- alpha A * A**T + beta C. Triangular parameters says whether
  15. //the update is upper or lower. C is N by N
  16. #include "eclblas.hpp"
  17. namespace eclblas {
  18. ECLBLAS_CALL void dsyrk(bool & __isAllResult, size32_t & __lenResult,
  19. void * &__result, uint8_t tri, bool transposeA,
  20. uint32_t n, uint32_t k, double alpha, bool isAllA,
  21. size32_t lenA, const void * a, double beta,
  22. bool isAllC, size32_t lenC, const void * c,
  23. bool clear) {
  24. __isAllResult = false;
  25. __lenResult = lenC;
  26. double *new_c = (double*) rtlMalloc(lenC);
  27. if (clear) {
  28. unsigned int pos = 0;
  29. for(unsigned int i=0; i<n; i++) {
  30. pos = i*n; // pos is head of column
  31. for (unsigned int j=0; j<n; j++) {
  32. new_c[pos+j] = tri==UPPER ? i>=j ? ((double*)c)[pos+j] : 0.0
  33. : i<=j ? ((double*)c)[pos+j] : 0.0;
  34. }
  35. }
  36. } else memcpy(new_c, c, __lenResult);
  37. unsigned int lda = (transposeA) ? k : n;
  38. cblas_dsyrk(CblasColMajor,
  39. tri==UPPER ? CblasUpper : CblasLower,
  40. transposeA ? CblasTrans : CblasNoTrans,
  41. n, k, alpha, (const double *)a, lda, beta, new_c, n);
  42. __result = (void*) new_c;
  43. }
  44. }