MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / generate_data

Function generate_data

tests/cvcuda/python/cvcuda_util.py:74–100  ·  view source on GitHub ↗

Generate data as numpy array Args: shape (tuple or list): Data shape dtype (numpy dtype): Data type (e.g. np.uint8) max_random (number or tuple or list): Maximum random value rng (numpy random Generator): To fill data with random values Returns: nump

(shape, dtype, max_random=None, rng=None)

Source from the content-addressed store, hash-verified

72
73
74def generate_data(shape, dtype, max_random=None, rng=None):
75 """Generate data as numpy array
76
77 Args:
78 shape (tuple or list): Data shape
79 dtype (numpy dtype): Data type (e.g. np.uint8)
80 max_random (number or tuple or list): Maximum random value
81 rng (numpy random Generator): To fill data with random values
82
83 Returns:
84 numpy.array: The generated data
85 """
86 if rng is None:
87 data = np.zeros(shape, dtype=dtype)
88 else:
89 if max_random is not None and type(max_random) in {tuple, list}:
90 assert len(max_random) == shape[-1]
91 if issubclass(dtype, numbers.Integral):
92 if max_random is None:
93 max_random = [np.iinfo(dtype).max for _ in range(shape[-1])]
94 data = rng.integers(max_random, size=shape, dtype=dtype)
95 elif issubclass(dtype, numbers.Real):
96 if max_random is None:
97 max_random = [1.0 for _ in range(shape[-1])]
98 data = rng.random(size=shape, dtype=dtype) * np.array(max_random)
99 data = data.astype(dtype)
100 return data
101
102
103class CudaBuffer:

Callers 2

create_tensorFunction · 0.85
create_imageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected