private def innerSum()

in algebird-core/src/main/scala/com/twitter/algebird/DecayingCMS.scala [560:595]


        private def innerSum(arr: Array[CMS], num: Int): CMS =
          if (num == 0) zero
          else if (num == 1) arr(0)
          else if (num == 2) plus(arr(0), arr(1))
          else {
            // start with zero
            val scratch: Array[Double] = new Array(totalCells)

            val latestTimeInHL: Double =
              arr.iterator.take(num).map(cms => cms.timeInHL).max

            var i = 0
            while (i < num) {
              val cms = arr(i)
              val scale = cms.getScale(latestTimeInHL)
              var j = 0
              while (j < depth) {
                val row = cms.cells(j)
                val stride = j * width
                var k = 0
                while (k < width) {
                  val n = row(k)
                  if (n > 0.0) {
                    scratch(stride + k) += scale * n
                  }
                  k += 1
                }
                j += 1
              }
              i += 1
            }

            val cells = scratchToCells(scratch)

            new CMS(cells, 0.0, latestTimeInHL)
          }