Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-30329

add iterator/foreach methods for Vectors

    XMLWordPrintableJSON

Details

    • Wish
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.0.0
    • 3.0.0
    • ML
    • None

    Description

      1, foreach: there are a lot of places that we need to traversal all the elements, current we impl like this:

      
      var i = 0; while (i < vec.size) { val v = vec(i); ...; i += 1 } 

      This method is for both convenience and performace:

      For a SparseVector, the total complexity is O(size * log(nnz)), since an apply call has log(nnz) complexity due to usage of binary search;

      However, this can be optimized by operations of cursors.

       

      2, foreachNonZero: the usage of foreachActive is mostly binded with filter value!=0, like

      vec.foreachActive { case (i, v) =>
        if (v != 0.0) {
          ...
        }
      }
       

      Here we can add this method for convenience.

       

      3, iterator/activeIterator/nonZeroIterator: add those three iterators, so that we can futuremore add/change some impls based on those iterators for both ml and mllib sides, to avoid vector conversions.

      For example, I want to optimize PCA by using ml.stat.Summarizer instead of

      Statistics.colStats/mllib.MultivariateStatisticalSummary, to avoid computation of unused variables.

      After having these iterators, I can do it without vector conversions.

       

      Attachments

        Issue Links

          Activity

            People

              podongfeng Ruifeng Zheng
              podongfeng Ruifeng Zheng
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: