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

    https://github.com/apache/spark/pull/12498#discussion_r60305477
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/feature/HashingTF.scala ---
    @@ -97,3 +126,41 @@ class HashingTF(val numFeatures: Int) extends 
Serializable {
         dataset.rdd.map(this.transform).toJavaRDD()
       }
     }
    +
    +object HashingTF {
    +
    +  private[spark] val Native: String = "native"
    +
    +  private[spark] val Murmur3: String = "murmur3"
    +
    +  private[spark] val supportedHashAlgorithms = Set(Native, Murmur3)
    +
    +  private val seed = 42
    +
    +  /**
    +   * Calculate a hash code value for the term object using the native 
Scala implementation.
    +   */
    +  private[spark] def nativeHash(term: Any): Int = term.##
    +
    +  /**
    +   * Calculate a hash code value for the term object using
    +   * Austin Appleby's MurmurHash 3 algorithm (MurmurHash3_x86_32).
    +   */
    +  private[spark] def murmur3Hash(term: Any): Int = {
    +    term match {
    +      case null => seed
    +      case b: Boolean => hashInt(if (b) 1 else 0, seed)
    +      case b: Byte => hashInt(b, seed)
    +      case s: Short => hashInt(s, seed)
    +      case i: Int => hashInt(i, seed)
    +      case l: Long => hashLong(l, seed)
    +      case f: Float => hashInt(java.lang.Float.floatToIntBits(f), seed)
    +      case d: Double => hashLong(java.lang.Double.doubleToLongBits(d), 
seed)
    +      case s: String =>
    +        val utf8 = UTF8String.fromString(s)
    +        hashUnsafeBytes(utf8.getBaseObject, utf8.getBaseOffset, 
utf8.numBytes(), seed)
    +      case _ => throw new SparkException("HashingTF with murmur3 algorithm 
does not " +
    +        "support the type of input data.")
    --- End diff --
    
    State the type of input data in the error message


---
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