Uploaded image for project: 'Mahout'
  1. Mahout
  2. MAHOUT-1691

iterable of vectors to matrix

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Not A Problem
    • 0.10.1
    • 0.11.1
    • classic

    Description

      In Mahout scala bindings, instead of writing

      val res = drmX.mapBlock(drmX.ncol) {
        case (keys, block) => {
          val copy = block.like
          copy := block.map(row => (row - mean) / std)
          (keys, copy)
        }
      }
      

      I would like to be able to write

      val res = drmX.mapBlock(drmX.ncol) {
        case (keys, block) => {
          keys -> block.map(row => (row - mean) / std)
        }
      }
      

      Solution: add a method for implicit conversion from iterable to Matrix:

        implicit def iterable2Matrix(that: Iterable[Vector]): Matrix = {
          val first = that.head
          val nrow = that.size
          val ncol = first.size
      
          val m = if (first.isDense) {
            new DenseMatrix(nrow, ncol)
          } else {
            new SparseRowMatrix(nrow, ncol)
          }
      
          that.zipWithIndex.foreach { case (row, idx) => 
            m.assignRow(idx.toInt, row)
          }
      
          m
        }
      

      If it sounds nice, I can send a pull request with this implemented

      Attachments

        Activity

          People

            smarthi Suneel Marthi
            agrigorev Alexey Grigorev
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: