Build tensor data spreading the range [min_value, max_value).
(dtype, shape, min_value=-100, max_value=100)
| 237 | |
| 238 | |
| 239 | def create_tensor_data(dtype, shape, min_value=-100, max_value=100): |
| 240 | """Build tensor data spreading the range [min_value, max_value).""" |
| 241 | |
| 242 | if dtype in TF_TYPE_INFO: |
| 243 | dtype = TF_TYPE_INFO[dtype][0] |
| 244 | |
| 245 | if dtype in (tf.float32, tf.float16): |
| 246 | value = (max_value-min_value)*np.random.random_sample(shape)+min_value |
| 247 | elif dtype in (tf.int32, tf.uint8, tf.int64, tf.int16): |
| 248 | value = np.random.randint(min_value, max_value+1, shape) |
| 249 | elif dtype == tf.bool: |
| 250 | value = np.random.choice([True, False], size=shape) |
| 251 | elif dtype == np.string_: |
| 252 | # Not the best strings, but they will do for some basic testing. |
| 253 | letters = list(string.ascii_uppercase) |
| 254 | return np.random.choice(letters, size=shape).astype(dtype) |
| 255 | return np.dtype(dtype).type(value) if np.isscalar(value) else value.astype( |
| 256 | dtype) |
| 257 | |
| 258 | |
| 259 | def create_scalar_data(dtype, min_value=-100, max_value=100): |
no test coverage detected