[
https://issues.apache.org/jira/browse/MAHOUT-1746?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14600261#comment-14600261
]
ASF GitHub Bot commented on MAHOUT-1746:
----------------------------------------
Github user avati commented on a diff in the pull request:
https://github.com/apache/mahout/pull/145#discussion_r33203139
--- Diff:
math-scala/src/main/scala/org/apache/mahout/math/drm/RLikeDrmOps.scala ---
@@ -50,7 +50,11 @@ class RLikeDrmOps[K: ClassTag](drm: DrmLike[K]) extends
DrmLikeOps[K](drm) {
def *:(that: Double): DrmLike[K] = OpAewUnaryFunc[K](A = this, f = that
* _)
- def ^(that: Double): DrmLike[K] = OpAewUnaryFunc[K](A = this, f =
math.pow(_, that))
+ def ^(that: Double): DrmLike[K] = that match {
+ case 2.0 ⇒ OpAewUnaryFunc[K](A = this, f = x ⇒ x * x)
--- End diff --
Can we have a comment here explaining the reason behind special-case for
2.0 and 0.5? This will help future code readers. Same comment applies to rest
of the similar changes further below.
> Fix: mxA ^ 2, mxA ^ 0.5 to mean the same thing as mxA * mxA and mxA ::= sqrt _
> ------------------------------------------------------------------------------
>
> Key: MAHOUT-1746
> URL: https://issues.apache.org/jira/browse/MAHOUT-1746
> Project: Mahout
> Issue Type: Blog - New Blog Request
> Reporter: Dmitriy Lyubimov
> Assignee: Dmitriy Lyubimov
> Fix For: 0.10.2
>
>
> it so happens that in java, if x is of double type, Math.pow(x,2.0) and x * x
> produce different values approximately once in million random values.
> This is extremely annoying as it creates rounding errors, especially with
> things like euclidean distance computations, which eventually may produce
> occasional NaNs.
> This issue suggests to get special treatment on vector and matrix dsl to make
> sure identical fpu algorithms are running as follows:
> x ^ 2 <=> x * x
> x ^ 0.5 <=> sqrt(x)
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)