Skip to content

Commit

Permalink
julia/ndarray: fix flaky test cases for clamp (#14776)
Browse files Browse the repository at this point in the history
ref: #14757
  • Loading branch information
iblislin authored and lanking520 committed Apr 24, 2019
1 parent 24d4b70 commit 2fbe8d9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions 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 2fbe8d9

Please sign in to comment.