示例#1
0
 def test_numpy_scalar_hits_lower_bound_int8(self):
     # single value arrays, shape == tuple()
     arr = np.int8(-10)
     observed = iadt.clip_(arr, -10, 10)
     assert np.array_equal(observed, np.int8(-10))
示例#2
0
 def test_numpy_scalar_exceeds_upper_bound_int8(self):
     arr = np.int8(10)
     observed = iadt.clip_(arr, -10, 1)
     assert np.array_equal(observed, np.int8(1))
示例#3
0
 def test_upper_bound_is_none_int8(self):
     arr = np.int8([1])
     observed = iadt.clip_(arr, -10, None)
     assert np.array_equal(observed, np.int8([1]))
示例#4
0
 def test_values_exceed_lower_bound_and_upper_bound_is_none_int8(self):
     arr = np.int8([-10])
     observed = iadt.clip_(arr, -1, None)
     assert np.array_equal(observed, np.int8([-1]))
示例#5
0
 def test_values_hit_upper_bound_negative_lower_bound_int8(self):
     arr = np.int8([127])
     observed = iadt.clip_(arr, -1, 127)
     assert np.array_equal(observed, np.int8([127]))
示例#6
0
 def test_both_bounds_are_none_int8(self):
     arr = np.int8([1])
     observed = iadt.clip_(arr, None, None)
     assert np.array_equal(observed, np.int8([1]))
示例#7
0
 def test_values_exceed_upper_bound_negative_lower_bound_uint32(self):
     arr = np.uint32([10])
     observed = iadt.clip_(arr, -1, 1)
     assert np.array_equal(observed, np.uint32([1]))
示例#8
0
 def test_values_within_bounds_upper_bound_is_dtype_limit_int8(self):
     arr = np.int8([127])
     observed = iadt.clip_(arr, 0, 128)
     assert np.array_equal(observed, np.int8([127]))
示例#9
0
 def test_values_exceed_upper_bound_uint32(self):
     arr = np.uint32([2])
     observed = iadt.clip_(arr, 0, 1)
     assert np.array_equal(observed, np.uint32([1]))
示例#10
0
 def test_values_hit_lower_bound_uint32(self):
     arr = np.uint32([0])
     observed = iadt.clip_(arr, 0, 1)
     assert np.array_equal(observed, np.uint32([0]))
示例#11
0
 def test_values_hit_lower_bound_float32(self):
     arr = np.float32([-1.0])
     observed = iadt.clip_(arr, -1.0, 1)
     assert np.allclose(observed, np.float32([-1.0]))
示例#12
0
 def test_values_hit_lower_bound_exceed_upper_bound_int32(self):
     arr = np.int32([0, 1, 2, 3, 4, 5])
     observed = iadt.clip_(arr, 0, 4)
     assert np.array_equal(observed, np.int32([0, 1, 2, 3, 4, 4]))
示例#13
0
def test_clip():
    arr = np.int32([0, 1, 2, 3, 4, 5])
    observed = iadt.clip_(arr, 0, 10)
    assert np.array_equal(observed, np.int32([0, 1, 2, 3, 4, 5]))

    arr = np.int32([0, 1, 2, 3, 4, 5])
    observed = iadt.clip_(arr, 0, 5)
    assert np.array_equal(observed, np.int32([0, 1, 2, 3, 4, 5]))

    arr = np.int32([0, 1, 2, 3, 4, 5])
    observed = iadt.clip_(arr, 0, 4)
    assert np.array_equal(observed, np.int32([0, 1, 2, 3, 4, 4]))

    arr = np.float32([-1.0])
    observed = iadt.clip_(arr, 0, 1)
    assert np.allclose(observed, np.float32([0.0]))

    arr = np.float32([-1.0])
    observed = iadt.clip_(arr, -1.0, 1)
    assert np.allclose(observed, np.float32([-1.0]))

    arr = np.uint32([0])
    observed = iadt.clip_(arr, 0, 1)
    assert np.array_equal(observed, np.uint32([0]))

    arr = np.uint32([1])
    observed = iadt.clip_(arr, 0, 1)
    assert np.array_equal(observed, np.uint32([1]))

    arr = np.uint32([2])
    observed = iadt.clip_(arr, 0, 1)
    assert np.array_equal(observed, np.uint32([1]))

    arr = np.uint32([1])
    observed = iadt.clip_(arr, -1, 1)
    assert np.array_equal(observed, np.uint32([1]))

    arr = np.uint32([10])
    observed = iadt.clip_(arr, -1, 1)
    assert np.array_equal(observed, np.uint32([1]))

    arr = np.int8([127])
    observed = iadt.clip_(arr, 0, 127)
    assert np.array_equal(observed, np.int8([127]))

    arr = np.int8([127])
    observed = iadt.clip_(arr, 0, 128)
    assert np.array_equal(observed, np.int8([127]))

    arr = np.int8([127])
    observed = iadt.clip_(arr, -1, 127)
    assert np.array_equal(observed, np.int8([127]))

    arr = np.int8([1])
    observed = iadt.clip_(arr, None, None)
    assert np.array_equal(observed, np.int8([1]))

    arr = np.int8([1])
    observed = iadt.clip_(arr, None, 10)
    assert np.array_equal(observed, np.int8([1]))

    arr = np.int8([1])
    observed = iadt.clip_(arr, -10, None)
    assert np.array_equal(observed, np.int8([1]))

    arr = np.int8([10])
    observed = iadt.clip_(arr, None, 1)
    assert np.array_equal(observed, np.int8([1]))

    arr = np.int8([-10])
    observed = iadt.clip_(arr, -1, None)
    assert np.array_equal(observed, np.int8([-1]))

    # single value arrays, shape == tuple()
    arr = np.int8(-10)
    observed = iadt.clip_(arr, -10, 10)
    assert np.array_equal(observed, np.int8(-10))

    arr = np.int8(-10)
    observed = iadt.clip_(arr, -1, 10)
    assert np.array_equal(observed, np.int8(-1))

    arr = np.int8(10)
    observed = iadt.clip_(arr, -10, 1)
    assert np.array_equal(observed, np.int8(1))