transpose method Null safety

Matrix<T> transpose()

Computes transpose.

Implementation

Matrix<T> transpose() {
  final builder = toBuilder();
  builder.tensorShape = TensorShape(tensorShape.y, tensorShape.x);
  for (var y = 0; y < height; y++) {
    for (var x = 0; x < width; x++) {
      builder.setXY(y, x, getXY(x, y));
    }
  }
  return builder.build() as Matrix<T>;
}