diagBlocks function

Matrix diagBlocks(
  1. Matrix input
)

Creates a matrix with input as its diagonal

Implementation

Matrix diagBlocks(Matrix input) {
  List<List<double>> output = [];

  for (int i = 0; i < input.rowsNum * 2; i++) {
    output.add(List.filled(input.columnsNum * 2, 0));
  }

  for (int i = 0; i < input.rowsNum; i++) {
    for (int j = 0; j < input.columnsNum; j++) {
      output[i][j] = input[i][j];
      output[i + input.rowsNum][j + input.columnsNum] = input[i][j];
    }
  }

  return Matrix.fromList(output);
}