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

julia/ndarray: fix flaky test cases for clamp #14776

Merged
merged 1 commit into from
Apr 24, 2019
Merged
Changes from all 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
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