Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. proc sparseDiag (ref X: [?Xdom] ?eltype, in p: int, const val: eltype = 0)
  2. where isSparseArr(X) {
  3. if Adom.rank != 2 then
  4. halt("Wrong rank for matrix inverse");
  5. var start, end = 0;
  6. if (p >= 0) { // upper or main diagonal
  7. start = 1;
  8. end = Xdom.shape(1) - p;
  9. }
  10. else { // lower diagonal
  11. start = 1 - p;
  12. end = Xdom.shape(1);
  13. }
  14. var indices : [start..end] (Xdom.idxType, Xdom.idxType);
  15. forall ind in {start..end} {
  16. indices[ind] = (ind, ind+p);
  17. }
  18. D.bulkAdd(indices, dataSorted=true, isUnique=true, preserveInds=false);
  19. coforall l in Locales do on l {
  20. const localDomain = X.localSubdomain();
  21. var (low_i, low_j) = localDomain.low;
  22. var (high_i, high_j) = localDomain.high;
  23. var localindices = indices;
  24. forall ij in localindices[low_i..high_i] {
  25. // Prevent unnecessary cross-locale communication
  26. if (localDomain.contains(ij)) {
  27. X(ij) = val;
  28. }
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement