def test_variance06(): labels = cp.asarray([2, 2, 3, 3, 4]) olderr = np.seterr(all="ignore") try: for type in types: input = cp.asarray([1, 3, 8, 10, 8], type) output = ndimage.variance(input, labels, cp.asarray([2, 3, 4])) assert_array_almost_equal(output, [1.0, 1.0, 0.0]) finally: np.seterr(**olderr)
def test_variance01(): olderr = np.seterr(all="ignore") try: for type in types: input = cp.asarray([], type) with suppress_warnings() as sup: sup.filter(RuntimeWarning, "Mean of empty slice") output = ndimage.variance(input) assert_(cp.isnan(output)) finally: np.seterr(**olderr)
def test_stat_funcs_2d(): a = cp.asarray([[5, 6, 0, 0, 0], [8, 9, 0, 0, 0], [0, 0, 0, 3, 5]]) lbl = cp.asarray([[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 0, 2, 2]]) index = cp.asarray([1, 2]) mean = ndimage.mean(a, labels=lbl, index=index) assert_array_equal(mean, [7.0, 4.0]) var = ndimage.variance(a, labels=lbl, index=index) assert_array_equal(var, [2.5, 1.0]) std = ndimage.standard_deviation(a, labels=lbl, index=index) assert_array_almost_equal(std, cp.sqrt(cp.asarray([2.5, 1.0]))) med = ndimage.median(a, labels=lbl, index=index) assert_array_equal(med, [7.0, 4.0]) min = ndimage.minimum(a, labels=lbl, index=index) assert_array_equal(min, [5, 3]) max = ndimage.maximum(a, labels=lbl, index=index) assert_array_equal(max, [9, 5])
def test_variance05(): labels = cp.asarray([2, 2, 3]) for type in types: input = cp.asarray([1, 3, 8], type) output = ndimage.variance(input, labels, 2) assert_almost_equal(output, 1.0)
def test_variance04(): input = cp.asarray([1, 0], bool) output = ndimage.variance(input) assert_almost_equal(output, 0.25)
def test_variance03(): for type in types: input = cp.asarray([1, 3], type) output = ndimage.variance(input) assert_almost_equal(output, 1.0)