The way this code block is indented is a bit hard to read. You can move the fold to the same line as the map to improve readability slightly
```scala
    // Compute column sums and normalize matrix
    val colSumsTemp = matrix.map(x => (x, 1)).fold((Array.ofDim[Double](n), 0)) { (a, b) => 
      val am = new DoubleMatrix(a._1)
      val bm = new DoubleMatrix(b._1)
      am.addi(bm)
      (a._1, a._2 + b._2)
    }
```