0

I have tried setting Error.stackTraceLimit = Infinity in chrome and firefox, but no effect. I'm just trying to multiply two matrixes in a recursive way. it breakes at the point of a [32][32] matrix.

Here is the code that i run, a simple devide and conquer matrix multiplication first i generate 2 random matrices and then multiply them

function divideConquer(a, b) {
  var i = 0,
    j = 0,
    k = 0;
  var c = [];
  let row = [];

  // creating the output
  for (let l = 0; l < a.length; l++) {
    row = [];
    for (let m = 0; m < b[0].length; m++) {
      row.push(parseInt(0));
    }
    c.push(row);
  }

  multiplyRecursion(a, b);
  return c;

  function multiplyRecursion(a, b) {
    // If all rows traversed
    if (i >= a.length)
      return;

    // If i < row1
    if (j < b[0].length) {
      if (k < a[0].length) {
        c[i][j] += a[i][k] * b[k][j];
        k++;
        multiplyRecursion(a, b);
      }

      k = 0;
      j++;
      multiplyRecursion(a, b);
    }

    j = 0;
    i++;
    multiplyRecursion(a, b);
  }
}

function generateRandomMatrix(n) {
  let row = [],
    matrix = [];
  for (let i = 0; i < n; i++) {
    row = [];
    for (let j = 0; j < n; j++) {
      row.push(Math.floor(Math.random() * 10));
    }
    matrix.push(row);
  }
  return matrix;
}

let a = generateRandomMatrix(32);
let b = generateRandomMatrix(32);
console.log(divideConquer(a, b));
ariel
  • 15,620
  • 12
  • 61
  • 73
Sadegh Shaikhi
  • 152
  • 1
  • 13

0 Answers0