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

Commit

Permalink
julia/ndarray: fix flaky test cases for clamp
Browse files Browse the repository at this point in the history
ref: #14757
  • Loading branch information
iblislin committed Apr 23, 2019
1 parent 871626e commit 9f2159b
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions julia/test/unittest/ndarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -886,18 +886,20 @@ function test_saveload()
end

function test_clamp()
dims = rand_dims()
@info("NDArray::clamp::dims = $dims")

j_array, nd_array = rand_tensors(dims)
clip_up = maximum(abs.(j_array)) / 2
clip_down = 0
clipped = clamp(nd_array, clip_down, clip_up)
@info("NDArray::clamp::dims")

A = [1 2 3;
4 5 6;
7 8 9.]
B = [3 3 3;
4 5 6;
7 8 8.]
x = NDArray(A)
y = clamp(x, 3., 8.)

# make sure the original array is not modified
@test copy(nd_array) j_array

@test all(clip_down .<= copy(clipped) .<= clip_up)
@test copy(x) A
@test copy(y) B

@info("NDArray::clamp!")
let
Expand Down

0 comments on commit 9f2159b

Please sign in to comment.