MCPcopy Create free account
hub / github.com/PythonOT/POT / _bench

Method _bench

ot/backend.py:3240–3264  ·  view source on GitHub ↗
(self, callable, *args, n_runs=1, warmup_runs=1)

Source from the content-addressed store, hash-verified

3238 return self.dtype_device(type_as)[1].split(":")[0]
3239
3240 def _bench(self, callable, *args, n_runs=1, warmup_runs=1):
3241 results = dict()
3242 device_contexts = [tf.device("/CPU:0")]
3243 if len(tf.config.list_physical_devices("GPU")) > 0: # pragma: no cover
3244 device_contexts.append(tf.device("/GPU:0"))
3245
3246 for device_context in device_contexts:
3247 with device_context:
3248 for type_as in self.__type_list__:
3249 inputs = [self.from_numpy(arg, type_as=type_as) for arg in args]
3250 for _ in range(warmup_runs):
3251 callable(*inputs)
3252 t0 = time.perf_counter()
3253 for _ in range(n_runs):
3254 res = callable(*inputs)
3255 _ = res.numpy()
3256 t1 = time.perf_counter()
3257 key = (
3258 "Tensorflow",
3259 self.device_type(inputs[0]),
3260 self.bitsize(type_as),
3261 )
3262 results[key] = (t1 - t0) / n_runs
3263
3264 return results
3265
3266 def solve(self, a, b):
3267 return tf.linalg.solve(a, b)

Callers

nothing calls this directly

Calls 3

device_typeMethod · 0.95
bitsizeMethod · 0.95
from_numpyMethod · 0.80

Tested by

no test coverage detected