3 from __future__
import absolute_import
4 from __future__
import division
5 from __future__
import print_function
6 from __future__
import unicode_literals
13 def rand_array(*dims):
16 return np.array(np.random.rand(*dims) - 0.5).astype(np.float32)
19 def randBlob(name, type, *dims, **kwargs):
20 offset = kwargs[
'offset']
if 'offset' in kwargs
else 0.0
21 workspace.FeedBlob(name, np.random.rand(*dims).astype(type) + offset)
24 def randBlobFloat32(name, *dims, **kwargs):
25 randBlob(name, np.float32, *dims, **kwargs)
28 def randBlobsFloat32(names, *dims, **kwargs):
30 randBlobFloat32(name, *dims, **kwargs)
34 return len(net.Proto().op)
37 def str_compare(a, b, encoding="utf8"):
38 if isinstance(a, bytes):
39 a = a.decode(encoding)
40 if isinstance(b, bytes):
41 b = b.decode(encoding)
45 def get_default_test_flags():
48 '--caffe2_log_level=0',
49 '--caffe2_cpu_allocator_do_zero_fill=0',
50 '--caffe2_cpu_allocator_do_junk_fill=1',
57 workspace.GlobalInit(get_default_test_flags())
60 core.SetEnginePref({}, {})
63 self.
ws = workspace.C.Workspace()
64 workspace.ResetWorkspace()
67 workspace.ResetWorkspace()