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))
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))
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]))
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]))
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]))
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]))
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]))
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]))
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]))
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]))
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]))
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]))
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))