Here are the examples of the python api numpy.testing.assert_array_almost_equal_nulp taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
147 Examples
3
Source : test_utils.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_float64_pass(self):
# The number of units of least precision
# In this case, use a few places above the lowest level (ie nulp=1)
nulp = 5
x = np.linspace(-20, 20, 50, dtype=np.float64)
x = 10**x
x = np.r_[-x, x]
# Addition
eps = np.finfo(x.dtype).eps
y = x + x*eps*nulp/2.
assert_array_almost_equal_nulp(x, y, nulp)
# Subtraction
epsneg = np.finfo(x.dtype).epsneg
y = x - x*epsneg*nulp/2.
assert_array_almost_equal_nulp(x, y, nulp)
def test_float64_fail(self):
3
Source : test_utils.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_float32_pass(self):
nulp = 5
x = np.linspace(-20, 20, 50, dtype=np.float32)
x = 10**x
x = np.r_[-x, x]
eps = np.finfo(x.dtype).eps
y = x + x*eps*nulp/2.
assert_array_almost_equal_nulp(x, y, nulp)
epsneg = np.finfo(x.dtype).epsneg
y = x - x*epsneg*nulp/2.
assert_array_almost_equal_nulp(x, y, nulp)
def test_float32_fail(self):
3
Source : test_basic.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_definition(self):
x = [[1,2,3],[4,5,6],[7,8,9]]
y = fftn(np.array(x, np.float32))
if not y.dtype == np.complex64:
raise ValueError("double precision output with single precision")
y_r = np.array(fftn(x), np.complex64)
assert_array_almost_equal_nulp(y, y_r)
def test_size_accuracy(self):
3
Source : test_basic.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_definition_float16(self):
x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
y = fftn(np.array(x, np.float16))
assert_equal(y.dtype, np.complex64)
y_r = np.array(fftn(x), np.complex64)
assert_array_almost_equal_nulp(y, y_r)
def test_float16_input(self):
3
Source : test_basic.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_definition(self):
x = np.array([[1,2,3],[4,5,6],[7,8,9]], dtype=self.dtype)
y = ifftn(x)
assert_equal(y.dtype, self.cdtype)
assert_array_almost_equal_nulp(y,direct_idftn(x),self.maxnlp)
x = random((20,26))
assert_array_almost_equal_nulp(ifftn(x),direct_idftn(x),self.maxnlp)
x = random((5,4,3,20))
assert_array_almost_equal_nulp(ifftn(x),direct_idftn(x),self.maxnlp)
def test_random_complex(self):
3
Source : test_basic.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_random_complex(self):
for size in [1,2,51,32,64,92]:
x = random([size,size]) + 1j*random([size,size])
assert_array_almost_equal_nulp(ifftn(fftn(x)),x,self.maxnlp)
assert_array_almost_equal_nulp(fftn(ifftn(x)),x,self.maxnlp)
def test_invalid_sizes(self):
3
Source : test_hb.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def assert_csc_almost_equal(r, l):
r = csc_matrix(r)
l = csc_matrix(l)
assert_equal(r.indptr, l.indptr)
assert_equal(r.indices, l.indices)
assert_array_almost_equal_nulp(r.data, l.data, 10000)
class TestHBReader(object):
3
Source : test_linesearch.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def assert_fp_equal(x, y, err_msg="", nulp=50):
"""Assert two arrays are equal, up to some floating-point rounding error"""
try:
assert_array_almost_equal_nulp(x, y, nulp)
except AssertionError as e:
raise AssertionError("%s\n%s" % (e, err_msg))
class TestLineSearch(object):
3
Source : test_spectral.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_nd_axis_m1(self):
x = np.zeros(20, dtype=np.float64)
x = x.reshape((2,1,10))
x[:,:,0] = 1.0
f, p = periodogram(x)
assert_array_equal(p.shape, (2, 1, 6))
assert_array_almost_equal_nulp(p[0,0,:], p[1,0,:], 60)
f0, p0 = periodogram(x[0,0,:])
assert_array_almost_equal_nulp(p0[np.newaxis,:], p[1,:], 60)
def test_nd_axis_0(self):
3
Source : test_spectral.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_nd_axis_0(self):
x = np.zeros(20, dtype=np.float64)
x = x.reshape((10,2,1))
x[0,:,:] = 1.0
f, p = periodogram(x, axis=0)
assert_array_equal(p.shape, (6,2,1))
assert_array_almost_equal_nulp(p[:,0,0], p[:,1,0], 60)
f0, p0 = periodogram(x[:,0,0])
assert_array_almost_equal_nulp(p0, p[:,1,0])
def test_window_external(self):
3
Source : test_spectral.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_window_external(self):
x = np.zeros(16)
x[0] = 1
f, p = periodogram(x, 10, 'hann')
win = signal.get_window('hann', 16)
fe, pe = periodogram(x, 10, win)
assert_array_almost_equal_nulp(p, pe)
assert_array_almost_equal_nulp(f, fe)
win_err = signal.get_window('hann', 32)
assert_raises(ValueError, periodogram, x,
10, win_err) # win longer than signal
def test_padded_fft(self):
3
Source : test_spectral.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_window_external(self):
x = np.zeros(16)
x[0] = 1
x[8] = 1
f, p = welch(x, 10, 'hann', nperseg=8)
win = signal.get_window('hann', 8)
fe, pe = welch(x, 10, win, nperseg=None)
assert_array_almost_equal_nulp(p, pe)
assert_array_almost_equal_nulp(f, fe)
assert_array_equal(fe.shape, (5,)) # because win length used as nperseg
assert_array_equal(pe.shape, (5,))
assert_raises(ValueError, welch, x,
10, win, nperseg=4) # because nperseg != win.shape[-1]
win_err = signal.get_window('hann', 32)
assert_raises(ValueError, welch, x,
10, win_err, nperseg=None) # win longer than signal
def test_empty_input(self):
3
Source : test_spectral.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_window_external(self):
x = np.zeros(16)
x[0] = 1
x[8] = 1
f, p = csd(x, x, 10, 'hann', 8)
win = signal.get_window('hann', 8)
fe, pe = csd(x, x, 10, win, nperseg=None)
assert_array_almost_equal_nulp(p, pe)
assert_array_almost_equal_nulp(f, fe)
assert_array_equal(fe.shape, (5,)) # because win length used as nperseg
assert_array_equal(pe.shape, (5,))
assert_raises(ValueError, csd, x, x,
10, win, nperseg=256) # because nperseg != win.shape[-1]
win_err = signal.get_window('hann', 32)
assert_raises(ValueError, csd, x, x,
10, win_err, nperseg=None) # because win longer than signal
def test_empty_input(self):
3
Source : test_matfuncs.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_padecases_dtype_float(self):
for dtype in [np.float32, np.float64]:
for scale in [1e-2, 1e-1, 5e-1, 1, 10]:
A = scale * eye(3, dtype=dtype)
observed = expm(A)
expected = exp(scale) * eye(3, dtype=dtype)
assert_array_almost_equal_nulp(observed, expected, nulp=100)
def test_padecases_dtype_complex(self):
3
Source : test_matfuncs.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_padecases_dtype_complex(self):
for dtype in [np.complex64, np.complex128]:
for scale in [1e-2, 1e-1, 5e-1, 1, 10]:
A = scale * eye(3, dtype=dtype)
observed = expm(A)
expected = exp(scale) * eye(3, dtype=dtype)
assert_array_almost_equal_nulp(observed, expected, nulp=100)
def test_padecases_dtype_sparse_float(self):
3
Source : test_matfuncs.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_padecases_dtype_sparse_float(self):
# float32 and complex64 lead to errors in spsolve/UMFpack
dtype = np.float64
for scale in [1e-2, 1e-1, 5e-1, 1, 10]:
a = scale * speye(3, 3, dtype=dtype, format='csc')
e = exp(scale) * eye(3, dtype=dtype)
with suppress_warnings() as sup:
sup.filter(SparseEfficiencyWarning,
"Changing the sparsity structure of a csc_matrix is expensive.")
exact_onenorm = _expm(a, use_exact_onenorm=True).toarray()
inexact_onenorm = _expm(a, use_exact_onenorm=False).toarray()
assert_array_almost_equal_nulp(exact_onenorm, e, nulp=100)
assert_array_almost_equal_nulp(inexact_onenorm, e, nulp=100)
def test_padecases_dtype_sparse_complex(self):
3
Source : test_matfuncs.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_padecases_dtype_sparse_complex(self):
# float32 and complex64 lead to errors in spsolve/UMFpack
dtype = np.complex128
for scale in [1e-2, 1e-1, 5e-1, 1, 10]:
a = scale * speye(3, 3, dtype=dtype, format='csc')
e = exp(scale) * eye(3, dtype=dtype)
with suppress_warnings() as sup:
sup.filter(SparseEfficiencyWarning,
"Changing the sparsity structure of a csc_matrix is expensive.")
assert_array_almost_equal_nulp(expm(a).toarray(), e, nulp=100)
def test_logm_consistency(self):
3
Source : test_basic.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_ellipkinc_2(self):
# Regression test for gh-3550
# ellipkinc(phi, mbad) was NaN and mvals[2:6] were twice the correct value
mbad = 0.68359375000000011
phi = 0.9272952180016123
m = np.nextafter(mbad, 0)
mvals = []
for j in range(10):
mvals.append(m)
m = np.nextafter(m, 1)
f = special.ellipkinc(phi, mvals)
assert_array_almost_equal_nulp(f, 1.0259330100195334 * np.ones_like(f), 1)
# this bug also appears at phi + n * pi for at least small n
f1 = special.ellipkinc(phi + pi, mvals)
assert_array_almost_equal_nulp(f1, 5.1296650500976675 * np.ones_like(f1), 2)
def test_ellipkinc_singular(self):
3
Source : test_basic.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_ellipeinc_2(self):
# Regression test for gh-3550
# ellipeinc(phi, mbad) was NaN and mvals[2:6] were twice the correct value
mbad = 0.68359375000000011
phi = 0.9272952180016123
m = np.nextafter(mbad, 0)
mvals = []
for j in range(10):
mvals.append(m)
m = np.nextafter(m, 1)
f = special.ellipeinc(phi, mvals)
assert_array_almost_equal_nulp(f, 0.84442884574781019 * np.ones_like(f), 2)
# this bug also appears at phi + n * pi for at least small n
f1 = special.ellipeinc(phi + pi, mvals)
assert_array_almost_equal_nulp(f1, 3.3471442287390509 * np.ones_like(f1), 4)
class TestErf(object):
3
Source : test_spfun_stats.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def _check_multigammaln_array_result(a, d):
# Test that the shape of the array returned by multigammaln
# matches the input shape, and that all the values match
# the value computed when multigammaln is called with a scalar.
result = multigammaln(a, d)
assert_array_equal(a.shape, result.shape)
a1 = a.ravel()
result1 = result.ravel()
for i in range(a.size):
assert_array_almost_equal_nulp(result1[i], multigammaln(a1[i], d))
def test_multigammaln_array_arg():
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_vflip_float(target):
img = np.array([[0.4, 0.4, 0.4], [0.0, 0.4, 0.4], [0.0, 0.0, 0.4]], dtype=np.float32)
expected = np.array([[0.0, 0.0, 0.4], [0.0, 0.4, 0.4], [0.4, 0.4, 0.4]], dtype=np.float32)
img, expected = convert_2d_to_target_format([img, expected], target=target)
flipped_img = F.vflip(img)
assert_array_almost_equal_nulp(flipped_img, expected)
@pytest.mark.parametrize("target", ["image", "mask"])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_hflip_float(target):
img = np.array([[0.4, 0.4, 0.4], [0.0, 0.4, 0.4], [0.0, 0.0, 0.4]], dtype=np.float32)
expected = np.array([[0.4, 0.4, 0.4], [0.4, 0.4, 0.0], [0.4, 0.0, 0.0]], dtype=np.float32)
img, expected = convert_2d_to_target_format([img, expected], target=target)
flipped_img = F.hflip(img)
assert_array_almost_equal_nulp(flipped_img, expected)
@pytest.mark.parametrize("target", ["image", "mask"])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_random_flip_float(code, func, target):
img = np.array([[0.4, 0.4, 0.4], [0.0, 0.4, 0.4], [0.0, 0.0, 0.4]], dtype=np.float32)
img = convert_2d_to_target_format([img], target=target)
assert_array_almost_equal_nulp(F.random_flip(img, code), func(img))
@pytest.mark.parametrize(["input_shape", "expected_shape"], [[(128, 64), (64, 128)], [(128, 64, 3), (64, 128, 3)]])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_rot90_float(target):
img = np.array([[0.0, 0.0, 0.4], [0.0, 0.0, 0.4], [0.0, 0.0, 0.4]], dtype=np.float32)
expected = np.array([[0.4, 0.4, 0.4], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], dtype=np.float32)
img, expected = convert_2d_to_target_format([img, expected], target=target)
rotated = F.rot90(img, factor=1)
assert_array_almost_equal_nulp(rotated, expected)
def test_normalize():
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_normalize():
img = np.ones((100, 100, 3), dtype=np.uint8) * 127
normalized = F.normalize(img, mean=50, std=3)
expected = (np.ones((100, 100, 3), dtype=np.float32) * 127 / 255 - 50) / 3
assert_array_almost_equal_nulp(normalized, expected)
def test_normalize_float():
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_normalize_float():
img = np.ones((100, 100, 3), dtype=np.float32) * 0.4
normalized = F.normalize(img, mean=50, std=3, max_pixel_value=1.0)
expected = (np.ones((100, 100, 3), dtype=np.float32) * 0.4 - 50) / 3
assert_array_almost_equal_nulp(normalized, expected)
def test_compare_rotate_and_shift_scale_rotate(image):
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_center_crop_float(target):
img = np.array(
[[0.4, 0.4, 0.4, 0.4], [0.0, 0.4, 0.4, 0.4], [0.0, 0.0, 0.4, 0.4], [0.0, 0.0, 0.0, 0.4]], dtype=np.float32
)
expected = np.array([[0.4, 0.4], [0.0, 0.4]], dtype=np.float32)
img, expected = convert_2d_to_target_format([img, expected], target=target)
cropped_img = A.center_crop(img, 2, 2)
assert_array_almost_equal_nulp(cropped_img, expected)
def test_center_crop_with_incorrectly_large_crop_size():
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_random_crop_float(target):
img = np.array(
[[0.01, 0.02, 0.03, 0.04], [0.05, 0.06, 0.07, 0.08], [0.09, 0.10, 0.11, 0.12], [0.13, 0.14, 0.15, 0.16]],
dtype=np.float32,
)
expected = np.array([[0.05, 0.06], [0.09, 0.10]], dtype=np.float32)
img, expected = convert_2d_to_target_format([img, expected], target=target)
cropped_img = A.random_crop(img, crop_height=2, crop_width=2, h_start=0.5, w_start=0)
assert_array_almost_equal_nulp(cropped_img, expected)
def test_random_crop_with_incorrectly_large_crop_size():
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_clip_float():
img = np.array([[-0.02, 0], [0.5, 2.2]], dtype=np.float32)
expected = np.array([[0, 0], [0.5, 1.0]], dtype=np.float32)
clipped = F.clip(img, dtype=np.float32, maxval=1.0)
assert_array_almost_equal_nulp(clipped, expected)
@pytest.mark.parametrize("target", ["image", "mask"])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_pad_float(target):
img = np.array([[0.1, 0.2], [0.3, 0.4]], dtype=np.float32)
expected = np.array(
[[0.4, 0.3, 0.4, 0.3], [0.2, 0.1, 0.2, 0.1], [0.4, 0.3, 0.4, 0.3], [0.2, 0.1, 0.2, 0.1]], dtype=np.float32
)
img, expected = convert_2d_to_target_format([img, expected], target=target)
padded_img = F.pad(img, min_height=4, min_width=4)
assert_array_almost_equal_nulp(padded_img, expected)
@pytest.mark.parametrize("target", ["image", "mask"])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_rotate_float_from_shift_scale_rotate(target):
img = np.array(
[[0.01, 0.02, 0.03, 0.04], [0.05, 0.06, 0.07, 0.08], [0.09, 0.10, 0.11, 0.12], [0.13, 0.14, 0.15, 0.16]],
dtype=np.float32,
)
expected = np.array(
[[0.00, 0.00, 0.00, 0.00], [0.04, 0.08, 0.12, 0.16], [0.03, 0.07, 0.11, 0.15], [0.02, 0.06, 0.10, 0.14]],
dtype=np.float32,
)
img, expected = convert_2d_to_target_format([img, expected], target=target)
rotated_img = FGeometric.shift_scale_rotate(
img, angle=90, scale=1, dx=0, dy=0, interpolation=cv2.INTER_NEAREST, border_mode=cv2.BORDER_CONSTANT
)
assert_array_almost_equal_nulp(rotated_img, expected)
@pytest.mark.parametrize("target", ["image", "mask"])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_scale_float_from_shift_scale_rotate(target):
img = np.array(
[[0.01, 0.02, 0.03, 0.04], [0.05, 0.06, 0.07, 0.08], [0.09, 0.10, 0.11, 0.12], [0.13, 0.14, 0.15, 0.16]],
dtype=np.float32,
)
expected = np.array(
[[0.06, 0.07, 0.07, 0.08], [0.10, 0.11, 0.11, 0.12], [0.10, 0.11, 0.11, 0.12], [0.14, 0.15, 0.15, 0.16]],
dtype=np.float32,
)
img, expected = convert_2d_to_target_format([img, expected], target=target)
scaled_img = FGeometric.shift_scale_rotate(
img, angle=0, scale=2, dx=0, dy=0, interpolation=cv2.INTER_NEAREST, border_mode=cv2.BORDER_CONSTANT
)
assert_array_almost_equal_nulp(scaled_img, expected)
@pytest.mark.parametrize("target", ["image", "mask"])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_shift_x_float_from_shift_scale_rotate(target):
img = np.array(
[[0.01, 0.02, 0.03, 0.04], [0.05, 0.06, 0.07, 0.08], [0.09, 0.10, 0.11, 0.12], [0.13, 0.14, 0.15, 0.16]],
dtype=np.float32,
)
expected = np.array(
[[0.00, 0.00, 0.01, 0.02], [0.00, 0.00, 0.05, 0.06], [0.00, 0.00, 0.09, 0.10], [0.00, 0.00, 0.13, 0.14]],
dtype=np.float32,
)
img, expected = convert_2d_to_target_format([img, expected], target=target)
shifted_along_x_img = FGeometric.shift_scale_rotate(
img, angle=0, scale=1, dx=0.5, dy=0, interpolation=cv2.INTER_NEAREST, border_mode=cv2.BORDER_CONSTANT
)
assert_array_almost_equal_nulp(shifted_along_x_img, expected)
@pytest.mark.parametrize("target", ["image", "mask"])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_shift_y_float_from_shift_scale_rotate(target):
img = np.array(
[[0.01, 0.02, 0.03, 0.04], [0.05, 0.06, 0.07, 0.08], [0.09, 0.10, 0.11, 0.12], [0.13, 0.14, 0.15, 0.16]],
dtype=np.float32,
)
expected = np.array(
[[0.00, 0.00, 0.00, 0.00], [0.00, 0.00, 0.00, 0.00], [0.01, 0.02, 0.03, 0.04], [0.05, 0.06, 0.07, 0.08]],
dtype=np.float32,
)
img, expected = convert_2d_to_target_format([img, expected], target=target)
shifted_along_y_img = FGeometric.shift_scale_rotate(
img, angle=0, scale=1, dx=0, dy=0.5, interpolation=cv2.INTER_NEAREST, border_mode=cv2.BORDER_CONSTANT
)
assert_array_almost_equal_nulp(shifted_along_y_img, expected)
@pytest.mark.parametrize(
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_shift_rgb_float(shift_params, expected):
img = np.ones((100, 100, 3), dtype=np.float32) * 0.4
r_shift, g_shift, b_shift = shift_params
img = F.shift_rgb(img, r_shift=r_shift, g_shift=g_shift, b_shift=b_shift)
expected_r, expected_g, expected_b = [
np.ones((100, 100), dtype=np.float32) * channel_value for channel_value in expected
]
assert img.dtype == np.dtype("float32")
assert_array_almost_equal_nulp(img[:, :, 0], expected_r)
assert_array_almost_equal_nulp(img[:, :, 1], expected_g)
assert_array_almost_equal_nulp(img[:, :, 2], expected_b)
@pytest.mark.parametrize(["alpha", "expected"], [(1.5, 190), (3, 255)])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_random_contrast_float(alpha, expected):
img = np.ones((100, 100, 3), dtype=np.float32) * 0.4
expected = np.ones((100, 100, 3), dtype=np.float32) * expected
img = F.brightness_contrast_adjust(img, alpha=alpha)
assert img.dtype == np.dtype("float32")
assert_array_almost_equal_nulp(img, expected)
@pytest.mark.parametrize(["beta", "expected"], [(-0.5, 50), (0.25, 125)])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_random_brightness_float(beta, expected):
img = np.ones((100, 100, 3), dtype=np.float32) * 0.4
expected = np.ones_like(img) * expected
img = F.brightness_contrast_adjust(img, beta=beta)
assert img.dtype == np.dtype("float32")
assert_array_almost_equal_nulp(img, expected)
@pytest.mark.parametrize(["gamma", "expected"], [(1, 1), (0.8, 3)])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_to_float_without_max_value_specified(dtype, divider):
img = np.ones((100, 100, 3), dtype=dtype)
expected = img.astype("float32") / divider
assert_array_almost_equal_nulp(F.to_float(img), expected)
@pytest.mark.parametrize("max_value", [255.0, 65535.0, 4294967295.0])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_to_float_with_max_value_specified(max_value):
img = np.ones((100, 100, 3), dtype=np.uint16)
expected = img.astype("float32") / max_value
assert_array_almost_equal_nulp(F.to_float(img, max_value=max_value), expected)
def test_to_float_unknown_dtype():
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_to_float_unknown_dtype_with_max_value(max_value):
img = np.ones((100, 100, 3), dtype=np.int16)
expected = img.astype("float32") / max_value
assert_array_almost_equal_nulp(F.to_float(img, max_value=max_value), expected)
@pytest.mark.parametrize(["dtype", "multiplier"], [(np.uint8, 255), (np.uint16, 65535), (np.uint32, 4294967295)])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_from_float_without_max_value_specified(dtype, multiplier):
img = np.ones((100, 100, 3), dtype=np.float32)
expected = (img * multiplier).astype(dtype)
assert_array_almost_equal_nulp(F.from_float(img, np.dtype(dtype)), expected)
@pytest.mark.parametrize("max_value", [255.0, 65535.0, 4294967295.0])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_from_float_with_max_value_specified(max_value):
img = np.ones((100, 100, 3), dtype=np.float32)
expected = (img * max_value).astype(np.uint32)
assert_array_almost_equal_nulp(F.from_float(img, dtype=np.uint32, max_value=max_value), expected)
@pytest.mark.parametrize("target", ["image", "mask"])
3
Source : test_functional.py
with MIT License
from albumentations-team
with MIT License
from albumentations-team
def test_resize_default_interpolation_float(target):
img = np.array(
[[0.1, 0.1, 0.1, 0.1], [0.2, 0.2, 0.2, 0.2], [0.3, 0.3, 0.3, 0.3], [0.4, 0.4, 0.4, 0.4]], dtype=np.float32
)
expected = np.array([[0.15, 0.15], [0.35, 0.35]], dtype=np.float32)
img, expected = convert_2d_to_target_format([img, expected], target=target)
resized_img = FGeometric.resize(img, 2, 2)
height, width = resized_img.shape[:2]
assert height == 2
assert width == 2
assert_array_almost_equal_nulp(resized_img, expected)
@pytest.mark.parametrize("target", ["image", "mask"])
3
Source : test_mlab.py
with MIT License
from alvarobartt
with MIT License
from alvarobartt
def test_psd_csd_equal(self):
freqs = self.freqs_density
Pxx, freqsxx = mlab.psd(x=self.y,
NFFT=self.NFFT_density,
Fs=self.Fs,
noverlap=self.nover_density,
pad_to=self.pad_to_density,
sides=self.sides)
Pxy, freqsxy = mlab.csd(x=self.y, y=self.y,
NFFT=self.NFFT_density,
Fs=self.Fs,
noverlap=self.nover_density,
pad_to=self.pad_to_density,
sides=self.sides)
assert_array_almost_equal_nulp(Pxx, Pxy)
assert_array_equal(freqsxx, freqsxy)
def test_specgram_auto_default_equal(self):
3
Source : test_utils.py
with MIT License
from alvarobartt
with MIT License
from alvarobartt
def test_float16_pass(self):
nulp = 5
x = np.linspace(-4, 4, 10, dtype=np.float16)
x = 10**x
x = np.r_[-x, x]
eps = np.finfo(x.dtype).eps
y = x + x*eps*nulp/2.
assert_array_almost_equal_nulp(x, y, nulp)
epsneg = np.finfo(x.dtype).epsneg
y = x - x*epsneg*nulp/2.
assert_array_almost_equal_nulp(x, y, nulp)
def test_float16_fail(self):
3
Source : test_basic.py
with MIT License
from buds-lab
with MIT License
from buds-lab
def test_definition(self):
x = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
y = fftn(np.array(x, np.float32))
assert_(y.dtype == np.complex64,
msg="double precision output with single precision")
y_r = np.array(fftn(x), np.complex64)
assert_array_almost_equal_nulp(y, y_r)
@pytest.mark.parametrize('size', SMALL_COMPOSITE_SIZES + SMALL_PRIME_SIZES)
3
Source : test_basic.py
with MIT License
from buds-lab
with MIT License
from buds-lab
def test_size_accuracy_small(self, size):
x = np.random.rand(size, size) + 1j*np.random.rand(size, size)
y1 = fftn(x.real.astype(np.float32))
y2 = fftn(x.real.astype(np.float64)).astype(np.complex64)
assert_equal(y1.dtype, np.complex64)
assert_array_almost_equal_nulp(y1, y2, 2000)
@pytest.mark.parametrize('size', LARGE_COMPOSITE_SIZES + LARGE_PRIME_SIZES)
3
Source : test_basic.py
with MIT License
from buds-lab
with MIT License
from buds-lab
def test_size_accuracy_large(self, size):
x = np.random.rand(size, 3) + 1j*np.random.rand(size, 3)
y1 = fftn(x.real.astype(np.float32))
y2 = fftn(x.real.astype(np.float64)).astype(np.complex64)
assert_equal(y1.dtype, np.complex64)
assert_array_almost_equal_nulp(y1, y2, 2000)
def test_definition_float16(self):
3
Source : test_basic.py
with MIT License
from buds-lab
with MIT License
from buds-lab
def test_definition_float16(self):
x = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
y = fftn(np.array(x, np.float16))
assert_equal(y.dtype, np.complex64)
y_r = np.array(fftn(x), np.complex64)
assert_array_almost_equal_nulp(y, y_r)
@pytest.mark.parametrize('size', SMALL_COMPOSITE_SIZES + SMALL_PRIME_SIZES)
3
Source : test_basic.py
with MIT License
from buds-lab
with MIT License
from buds-lab
def test_float16_input_small(self, size):
x = np.random.rand(size, size) + 1j*np.random.rand(size, size)
y1 = fftn(x.real.astype(np.float16))
y2 = fftn(x.real.astype(np.float64)).astype(np.complex64)
assert_equal(y1.dtype, np.complex64)
assert_array_almost_equal_nulp(y1, y2, 5e5)
@pytest.mark.parametrize('size', LARGE_COMPOSITE_SIZES + LARGE_PRIME_SIZES)
See More Examples