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

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

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.3.0, 1.4.0, 1.5.0, 1.6.0
    • Fix Version/s: 1.6.0
    • Component/s: MLlib, PySpark
    • Labels:
      None
    • Target Version/s:

      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

            • Assignee:
              zero323 Maciej Szymkiewicz
              Reporter:
              zero323 Maciej Szymkiewicz
              Shepherd:
              Joseph K. Bradley

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment