def test_extrema02(): labels = cp.asarray([1, 2]) for type in types: input = cp.asarray([[1, 2], [3, 4]], type) # TODO: grlee77: avoid use of item()? output1 = ndimage.extrema(input, labels=labels, index=2) output2 = ndimage.minimum(input, labels=labels, index=2) output3 = ndimage.maximum(input, labels=labels, index=2) output4 = ndimage.minimum_position(input, labels=labels, index=2) output5 = ndimage.maximum_position(input, labels=labels, index=2) assert_equal(output1, (output2, output3, output4, output5))
def test_extrema04(): labels = cp.asarray([1, 2, 0, 4]) for type in types: input = cp.asarray([[5, 4, 2, 5], [3, 7, 8, 2], [1, 5, 1, 1]], type) output1 = ndimage.extrema(input, labels, [1, 2]) output2 = ndimage.minimum(input, labels, [1, 2]) output3 = ndimage.maximum(input, labels, [1, 2]) output4 = ndimage.minimum_position(input, labels, [1, 2]) output5 = ndimage.maximum_position(input, labels, [1, 2]) assert_array_almost_equal(output1[0], output2) assert_array_almost_equal(output1[1], output3) assert_array_almost_equal(output1[2], output4) assert_array_almost_equal(output1[3], output5)
def test_extrema03(): labels = cp.asarray([[1, 2], [2, 3]]) for type in types: input = cp.asarray([[1, 2], [3, 4]], type) output1 = ndimage.extrema(input, labels=labels, index=[2, 3, 8]) output2 = ndimage.minimum(input, labels=labels, index=[2, 3, 8]) output3 = ndimage.maximum(input, labels=labels, index=[2, 3, 8]) output4 = ndimage.minimum_position(input, labels=labels, index=[2, 3, 8]) output5 = ndimage.maximum_position(input, labels=labels, index=[2, 3, 8]) assert_array_almost_equal(output1[0], output2) assert_array_almost_equal(output1[1], output3) assert_array_almost_equal(output1[2], output4) assert_array_almost_equal(output1[3], output5)
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_minimum04(): labels = cp.asarray([[1, 2], [2, 3]]) for type in types: input = cp.asarray([[1, 2], [3, 4]], type) output = ndimage.minimum(input, labels=labels, index=[2, 3, 8]) assert_array_almost_equal(output, [2.0, 4.0, 0.0])
def test_minimum03(): labels = cp.asarray([1, 2]) for type in types: input = cp.asarray([[1, 2], [3, 4]], type) output = ndimage.minimum(input, labels=labels, index=2) assert_almost_equal(output, 2.0)
def test_minimum02(): labels = cp.asarray([1, 0], bool) input = cp.asarray([[2, 2], [2, 4]], bool) output = ndimage.minimum(input, labels=labels) assert_almost_equal(output, 1.0)
def test_minimum01(): labels = cp.asarray([1, 0], bool) for type in types: input = cp.asarray([[1, 2], [3, 4]], type) output = ndimage.minimum(input, labels=labels) assert_almost_equal(output, 1.0)