function blockDiag (arr, N) {
    const M = []
    for (let i = 0; i < N; i++) {
      M[i] = Array(N).fill(0)
    }

    let I = 0
    for (const sub of arr) {
      const n = sub.length

      for (let i = 0; i < n; i++) {
        for (let j = 0; j < n; j++) {
          M[I + i][I + j] = sub[i][j]
        }
      }

      I += n
    }

    return M
  }
Create a block-diagonal matrix with the given square matrices on the diagonal
@param {Matrix[] | number[][][]} arr array of matrices to be placed on the diagonal
@param {number} N the size of the resulting matrix