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

SparseVector.__getitem__ should check if value can be non-zero before executing searchsorted

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.3.0, 1.4.0, 1.5.0, 1.6.0
    • 1.6.0
    • MLlib, PySpark
    • None

    Description

      At this moment SparseVector.__getitem__ executes np.searchsorted first and checks if result is in an expected range after that:

      insert_index = np.searchsorted(inds, index)
      if insert_index >= inds.size:
          return 0.
      
      row_ind = inds[insert_index]
      ...
      

      See: https://issues.apache.org/jira/browse/SPARK-10973

      It is possible to check if index can contain non-zero value before binary search:

      if (inds.size == 0) or (index > inds.item(-1)):
          return 0.
      
      insert_index = np.searchsorted(inds, index)
      row_ind = inds[insert_index]
      ...
      

      It is not a huge improvement but should save some work on large vectors.

      Attachments

        Activity

          People

            zero323 Maciej Szymkiewicz
            zero323 Maciej Szymkiewicz
            Joseph K. Bradley Joseph K. Bradley
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: