Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7818#discussion_r36024394
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/fpm/PrefixSpan.scala 
---
    @@ -237,13 +247,33 @@ class PrefixSpan private (
        */
       private def getPatternsInLocal(
           minCount: Long,
    -      data: RDD[(List[Int], Iterable[Array[Int]])]): RDD[(List[Int], 
Long)] = {
    +      data: RDD[(List[Set[Int]], Iterable[List[Set[Int]]])]): 
RDD[(List[Set[Int]], Long)] = {
         data.flatMap {
    -      case (prefix, projDB) =>
    -        LocalPrefixSpan.run(minCount, maxPatternLength, 
prefix.toList.reverse, projDB)
    -          .map { case (pattern: List[Int], count: Long) =>
    -          (pattern.reverse, count)
    -        }
    +      case (prefix, projDB) => LocalPrefixSpan.run(minCount, 
maxPatternLength, prefix, projDB)
    +    }
    +  }
    +
    +}
    +
    +object PrefixSpan {
    +  private[fpm] val DELIMITER = -1
    +
    +  private[fpm] def splitAtDelimiter(pattern: List[Int]): List[Set[Int]] = {
    +    pattern.span(_ != DELIMITER) match {
    +      case (x, xs) if xs.length > 1 => x.toSet :: splitAtDelimiter(xs.tail)
    +      case (x, xs) => List(x.toSet)
         }
       }
    +
    +  private[fpm] def insertDelimiters(sequence: List[Set[Int]]): List[Int] = 
{
    +    // TODO: avoid allocating new arrays when appending
    +    sequence.zip(Seq.fill(sequence.size)(PrefixSpan.DELIMITER))
    --- End diff --
    
    Use `ArrayBuilder` instead of functional style. Creating a sequence of 
delimiters is not efficient. As a reference, Scala also use builder in 
`mkString`: 
https://github.com/scala/scala/blob/2.11.x/src/library/scala/collection/TraversableOnce.scala#L351.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to