Caffe2 - Python API
A deep learning, cross platform ML framework
test_util.py
1 ## @package test_util
2 # Module caffe2.python.test_util
3 from __future__ import absolute_import
4 from __future__ import division
5 from __future__ import print_function
6 from __future__ import unicode_literals
7 import numpy as np
8 from caffe2.python import core, workspace
9 
10 import unittest
11 
12 
13 def rand_array(*dims):
14  # np.random.rand() returns float instead of 0-dim array, that's why need to
15  # do some tricks
16  return np.array(np.random.rand(*dims) - 0.5).astype(np.float32)
17 
18 
19 class TestCase(unittest.TestCase):
20  @classmethod
21  def setUpClass(cls):
22  workspace.GlobalInit([
23  'caffe2',
24  '--caffe2_log_level=0',
25  ])
26  # clear the default engines settings to separate out its
27  # affect from the ops tests
28  core.SetEnginePref({}, {})
29 
30  def setUp(self):
31  self.ws = workspace.C.Workspace()
32  workspace.ResetWorkspace()
33 
34  def tearDown(self):
35  workspace.ResetWorkspace()