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

    https://github.com/apache/spark/pull/2451#discussion_r17813573
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/mllib/util/TestingUtils.scala ---
    @@ -169,4 +169,67 @@ object TestingUtils {
         override def toString = x.toString
       }
     
    +  case class CompareMatrixRightSide(
    +     fun: (Matrix, Matrix, Double) => Boolean, y: Matrix, eps: Double, 
method: String)
    +
    +  /**
    +   * Implicit class for comparing two matrices using relative tolerance or 
absolute tolerance.
    +   */
    +  implicit class MatrixWithAlmostEquals(val x: Matrix) {
    +
    +    /**
    +     * When the difference of two vectors are within eps, returns true; 
otherwise, returns false.
    +     */
    +    def ~=(r: CompareMatrixRightSide): Boolean = r.fun(x, r.y, r.eps)
    +
    +    /**
    +     * When the difference of two vectors are within eps, returns false; 
otherwise, returns true.
    +     */
    +    def !~=(r: CompareMatrixRightSide): Boolean = !r.fun(x, r.y, r.eps)
    +
    +    /**
    +     * Throws exception when the difference of two vectors are NOT within 
eps;
    +     * otherwise, returns true.
    +     */
    +    def ~==(r: CompareMatrixRightSide): Boolean = {
    +      if (!r.fun(x, r.y, r.eps)) {
    +        throw new TestFailedException(
    +          s"Expected \n$x\n and \n${r.y}\n to be within 
${r.eps}${r.method} for all elements.", 0)
    +      }
    +      true
    +    }
    +
    +    /**
    +     * Throws exception when the difference of two matrices are within 
eps; otherwise, returns true.
    +     */
    +    def !~==(r: CompareMatrixRightSide): Boolean = {
    +      if (r.fun(x, r.y, r.eps)) {
    +        throw new TestFailedException(
    +          s"Did not expect \n$x\n and \n${r.y}\n to be within " +
    +            "${r.eps}${r.method} for all elements.", 0)
    +      }
    +      true
    +    }
    +
    +    /**
    +     * Comparison using absolute tolerance.
    +     */
    +    def absTol(eps: Double): CompareMatrixRightSide = 
CompareMatrixRightSide(
    +      (x: Matrix, y: Matrix, eps: Double) => {
    +        x.toArray.zip(y.toArray).forall(x => x._1 ~= x._2 absTol eps)
    +      }, x, eps, ABS_TOL_MSG)
    +
    +    /**
    +     * Comparison using relative tolerance. Note that comparing against 
sparse vector
    +     * with elements having value of zero will raise exception because it 
involves with
    +     * comparing against zero.
    +     */
    +    def relTol(eps: Double): CompareMatrixRightSide = 
CompareMatrixRightSide(
    +      (x: Matrix, y: Matrix, eps: Double) => {
    +        x.toArray.zip(y.toArray).forall(x => x._1 ~= x._2 relTol eps)
    --- End diff --
    
    confusing having 2 things called "x"


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