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)
def test_empty_huge_size_fill0(self): a = cupyx.empty_pinned((1024, 2048, 1024), dtype='b') a.fill(0) assert (a == 0).all() # Free huge memory for slow test del a cupy.get_default_pinned_memory_pool().free_all_blocks()
def test_empty_int_huge_size(self): a = cupyx.empty_pinned(2**31, dtype='b') a.fill(123) assert (a == 123).all() # Free huge memory for slow test del a cupy.get_default_pinned_memory_pool().free_all_blocks()
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)
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))
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)
def __init__(self, size, dtype): self.size = size self.dtype = dtype self.host = cupyx.empty_pinned(size, dtype) self.device = cp.empty(size, dtype)
def test_empty_zero_sized_array_strides(self, order): a = numpy.empty((1, 0, 2), dtype='d', order=order) b = cupyx.empty_pinned((1, 0, 2), dtype='d', order=order) assert b.strides == a.strides