Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Fix relative difference scala #14417

Merged
merged 4 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ object CheckUtils {
def reldiff(a: NDArray, b: NDArray): Float = {
val diff = NDArray.sum(NDArray.abs(a - b)).toScalar
val norm = NDArray.sum(NDArray.abs(a)).toScalar
diff / norm
if (diff < Float.MinPositiveValue) diff else diff / norm
}

def reldiff(a: Array[Float], b: Array[Float]): Float = {
val diff =
(a zip b).map { case (aElem, bElem) => Math.abs(aElem - bElem) }.sum
val norm: Float = a.reduce(Math.abs(_) + Math.abs(_))
diff / norm
if (diff < Float.MinPositiveValue) diff else diff / norm
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class NDArraySuite extends FunSuite with BeforeAndAfterAll with Matchers {
}

test("arange") {
for (i <- 0 until 5) {
for (i <- 0 until 10000) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of increasing the number of iterations, could you maybe add a test case that specifically hits the behaviour you're trying to circumvent here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. That's definitely a better solution.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lanking520 @nswamy could you give me a hand here and review the scala code?

val start = scala.util.Random.nextFloat() * 5
val stop = start + scala.util.Random.nextFloat() * 100
val step = scala.util.Random.nextFloat() * 4
Expand Down