<commit_before>// Block LU with pivoting.
// Magic square of dimension 10, is used as test matrix A.

// Using array alias operators to implement LU block algorithm
// with pivoting.
// In this version, A1D is a range, not a 1D domain.  The iterator,
// IterateByBlocks returns ranges, not subdomains of A1D.  Temporary
// ranges, slice1 and slice2 are used to define what should be
// subdomains sliced by indefinite ranges.  
//
// The maxIndex reduction routine and the swap operator are not
// implemented yet and need to be coded.  Since passing array aliases
// with slicing to functions doesn't seem to be fully supported yet,
// the pivot calculation and the swapping of pivot rows is coded inline
// in the algorithm.

param n = 10;
param blk = 5;

var A1D = 1..n;
var slice1, slice2: range;
const A2D = [A1D,A1D]; 
var A: [A2D] real;
var piv: [A1D] int;
var ind, temp:int;
var rtemp: real;

initA(A,'Adata.dat');
[i in A1D] piv(i) = i;

writeln("Unfactored Matrix:");
writeln(A);

for (UnfactoredInds,CurrentBlockInds,TrailingBlockInds) 
  in IterateByBlocks(A1D,blk) {
  
  var A1 => A[UnfactoredInds,CurrentBlockInds];
  var A2 => A[UnfactoredInds,TrailingBlockInds];
  var A12 => A[CurrentBlockInds,TrailingBlockInds];
  var A22 => A[TrailingBlockInds,TrailingBlockInds];

// LU factorization of A1 
  for k in CurrentBlockInds {
//  temporaries used instead of subdomains with indefinite ranges.
    slice1 = k+1..UnfactoredInds.high;
    slice2 = k+1..CurrentBlockInds.high;

//  ind = maxIndex reduce (A1(UnfactoredInds,k));
    var maxAk = abs(A1(k,k));
    ind = k;
    for i in slice1 {
      if (abs(A1(i,k)) > maxAk) {
        ind = i;
        maxAk = abs(A1(i,k));    
      }
    }
    if (ind != k) {
//      piv(k) <==> piv(ind);
//      A(k,..) <==> A(ind,..);
      temp = piv(k);
      piv(k) = piv(ind);
      piv(ind) = temp;
      for i in A1D {
        rtemp = A(k,i);
        A(k,i) = A(ind,i);
        A(ind,i) = rtemp;       
      } <commit_msg>Modification to pivlublock-alias.chpl to use maxloc reduce.<commit_after>// Block LU with pivoting.
// Magic square of dimension 10, is used as test matrix A.

// Using array alias operators to implement LU block algorithm
// with pivoting.
// In this version, A1D is a range, not a 1D domain.  The iterator,
// IterateByBlocks returns ranges, not subdomains of A1D.  Temporary
// ranges, slice1 and slice2 are used to define what should be
// subdomains sliced by indefinite ranges.  
//
// The maxIndex reduction routine and the swap operator are not
// implemented yet and need to be coded.  Since passing array aliases
// with slicing to functions doesn't seem to be fully supported yet,
// the pivot calculation and the swapping of pivot rows is coded inline
// in the algorithm.

param n = 10;
param blk = 5;

var A1D = 1..n;
var slice0, slice1, slice2: range;
const A2D = [A1D,A1D]; 
var A: [A2D] real;
var piv: [A1D] int;
var ind, temp:int;
var rtemp: real;

initA(A,'Adata.dat');
[i in A1D] piv(i) = i;

writeln("Unfactored Matrix:");
writeln(A);

for (UnfactoredInds,CurrentBlockInds,TrailingBlockInds) 
  in IterateByBlocks(A1D,blk) {
  
  var A1 => A[UnfactoredInds,CurrentBlockInds];
  var A2 => A[UnfactoredInds,TrailingBlockInds];
  var A12 => A[CurrentBlockInds,TrailingBlockInds];
  var A22 => A[TrailingBlockInds,TrailingBlockInds];

// LU factorization of A1 
  for k in CurrentBlockInds {
//  temporaries used instead of subdomains with indefinite ranges.
    slice0 = k..UnfactoredInds.high;
    slice1 = k+1..UnfactoredInds.high;
    slice2 = k+1..CurrentBlockInds.high;

//  ind = maxIndex reduce (A1(UnfactoredInds(k..),k));
    (_, (ind,_)) = maxloc reduce (abs(A(slice0,k..k)), [slice0,k..k]);

    if (ind != k) {
//      piv(k) <==> piv(ind);
//      A(k,..) <==> A(ind,..);
      temp = piv(k);
      piv(k) = piv(ind);
      piv(ind) = temp;
      for i in A1D {
        rtemp = A(k,i);
        A(k,i) = A(ind,i);
        A(ind,i) = rtemp;       
      } 
{'fraction_non_alphanumeric': 0.129601613716591, 'fraction_numerical': 0.019162884518406455, 'mean_word_length': 3.056237218813906, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7241213', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1430, 'n_words': 456}