Esempio n. 1
0
    def test_empty_like_K_strides_reshape(self, dtype):
        # test strides that are both non-contiguous and non-descending
        a = testing.shaped_arange((2, 3, 4), numpy, dtype)
        a = a[:, ::2, :].swapaxes(0, 1)
        b = cupyx.empty_like_pinned(a, order='K', shape=self.shape)
        b.fill(0)

        # GPU case
        ag = testing.shaped_arange((2, 3, 4), cupy, dtype)
        ag = ag[:, ::2, :].swapaxes(0, 1)
        bg = cupyx.empty_like_pinned(ag, order='K', shape=self.shape)
        bg.fill(0)

        # make sure NumPy and CuPy strides agree
        assert b.strides == bg.strides
        return
Esempio n. 2
0
 def test_empty_like_reshape_cupy_only(self, dtype, order):
     a = testing.shaped_arange((2, 3, 4), cupy, dtype)
     b = cupyx.empty_like_pinned(a, shape=self.shape)
     b.fill(0)
     c = cupyx.empty_pinned(self.shape, order=order, dtype=dtype)
     c.fill(0)
     numpy.testing.assert_array_equal(b, c)
Esempio n. 3
0
 def test_empty_like_reshape_contiguity_cupy_only(self, dtype, order):
     a = testing.shaped_arange((2, 3, 4), cupy, dtype)
     b = cupyx.empty_like_pinned(a, order=order, shape=self.shape)
     b.fill(0)
     c = cupyx.empty_pinned(self.shape)
     c.fill(0)
     if order in ['f', 'F']:
         assert b.flags.f_contiguous
     else:
         assert b.flags.c_contiguous
     numpy.testing.assert_array_equal(b, c)
Esempio n. 4
0
    def __init__(self, size, config):
        self.size = size
        self.bg_feat_scale_factor = config['bg_feat_scale_factor']
        self.opt_flow_scale_factor = config['opt_flow_scale_factor']
        self.feature_density = config['feature_density']
        self.feat_dist_factor = config['feat_dist_factor']
        self.ransac_max_iter = config['ransac_max_iter']
        self.ransac_conf = config['ransac_conf']
        self.max_error = config['max_error']
        self.inlier_thresh = config['inlier_thresh']

        self.bg_feat_thresh = config['bg_feat_thresh']
        self.target_feat_params = config['target_feat_params']
        self.opt_flow_params = config['opt_flow_params']

        self.bg_feat_detector = cv2.FastFeatureDetector_create(
            threshold=self.bg_feat_thresh)

        # background feature points for visualization
        self.bg_keypoints = None
        self.prev_bg_keypoints = None

        # preallocate frame buffers
        opt_flow_sz = (round(self.opt_flow_scale_factor[0] * self.size[0]),
                       round(self.opt_flow_scale_factor[1] * self.size[1]))
        self.frame_gray = cupyx.empty_pinned(self.size[::-1], np.uint8)
        self.frame_small = cupyx.empty_pinned(opt_flow_sz[::-1], np.uint8)
        self.prev_frame_gray = cupyx.empty_like_pinned(self.frame_gray)
        self.prev_frame_small = cupyx.empty_like_pinned(self.frame_small)

        bg_feat_sz = (round(self.bg_feat_scale_factor[0] * self.size[0]),
                      round(self.bg_feat_scale_factor[1] * self.size[1]))
        self.prev_frame_bg = cupyx.empty_pinned(bg_feat_sz[::-1], np.uint8)
        self.bg_mask_small = cupyx.empty_like_pinned(self.prev_frame_bg)

        self.fg_mask = cupyx.empty_like_pinned(self.frame_gray)
        self.frame_rect = to_tlbr((0, 0, *self.size))
Esempio n. 5
0
 def test_empty_like_reshape_contiguity2_cupy_only(self, dtype, order):
     a = testing.shaped_arange((2, 3, 4), cupy, dtype)
     a = cupy.asfortranarray(a)
     b = cupyx.empty_like_pinned(a, order=order, shape=self.shape)
     b.fill(0)
     c = cupyx.empty_pinned(self.shape)
     c.fill(0)
     shape = self.shape if not numpy.isscalar(self.shape) else (
         self.shape, )
     if (order in ['c', 'C']
             or (order in ['k', 'K', None] and len(shape) != a.ndim)):
         assert b.flags.c_contiguous
     else:
         assert b.flags.f_contiguous
     numpy.testing.assert_array_equal(b, c)
Esempio n. 6
0
    def test_empty_like_reshape_contiguity3_cupy_only(self, dtype, order):
        a = testing.shaped_arange((2, 3, 4), cupy, dtype)
        # test strides that are both non-contiguous and non-descending
        a = a[:, ::2, :].swapaxes(0, 1)
        b = cupyx.empty_like_pinned(a, order=order, shape=self.shape)
        b.fill(0)
        shape = self.shape if not numpy.isscalar(self.shape) else (
            self.shape, )
        if len(shape) == 1:
            assert b.flags.c_contiguous
            assert b.flags.f_contiguous
        elif order in ['k', 'K', None] and len(shape) == a.ndim:
            assert not b.flags.c_contiguous
            assert not b.flags.f_contiguous
        elif order in ['f', 'F']:
            assert not b.flags.c_contiguous
            assert b.flags.f_contiguous
        else:
            assert b.flags.c_contiguous
            assert not b.flags.f_contiguous

        c = cupyx.zeros_pinned(self.shape)
        c.fill(0)
        testing.assert_array_equal(b, c)
Esempio n. 7
0
 def test_empty_like_subok(self):
     a = testing.shaped_arange((2, 3, 4), numpy)
     with pytest.raises(TypeError):
         cupyx.empty_like_pinned(a, subok=True)
Esempio n. 8
0
 def test_empty_like_invalid_order(self, dtype):
     a = testing.shaped_arange((2, 3, 4), numpy, dtype)
     with pytest.raises(ValueError):
         cupyx.empty_like_pinned(a, order='Q')