Exemplo n.º 1
0
 def test_Slice2D(self):
     len = np.sqrt(self.len).astype(int)
     np_a = np.reshape(self.np_a, (len, len))
     # dc_a  = dc.reshape(self.dc_a, (len, len)) $ BUG (reported bug.py) - for now using a WA
     dc_a = dc.reshape(self.dc_a, (64, 64))
     np_start = np.random.randint(len / 2)
     np_end = np.random.randint(len / 2 + 1, len)
     np_step = np.random.randint(1, len - 1)
     np_axes = 1
     np_start2 = np.random.randint(len / 2)
     np_end2 = np.random.randint(len / 2 + 1, len)
     np_step2 = np.random.randint(1, len - 1)
     np_axes2 = 2
     dc_start = dc.array(2).asTypeULong()
     dc_end = dc.array(2).asTypeULong()
     dc_axes = dc.array(2).asTypeInt()
     dc_step = dc.array(2).asTypeULong()
     dc_start[0] = np_start
     dc_end[0] = np_end
     dc_axes[0] = np_axes
     dc_step[0] = np_step
     dc_start[1] = np_start2
     dc_end[1] = np_end2
     dc_axes[1] = np_axes2
     dc_step[1] = np_step2
     npr = np_a[np_start:np_end:np_step, np_start2:np_end2:np_step2]
     dcr = dc.slice(dc_a, dc_start, dc_end, dc_axes, dc_step)
     np.testing.assert_allclose(npr.flatten(),
                                np.array(dcr.data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Exemplo n.º 2
0
Arquivo: Mod.py Projeto: yyht/deepC
 def setUp(self):
     self.len = 24
     self.np_a_float = np.random.randn(self.len).astype(np.int32)
     self.np_b_float = np.random.randn(self.len).astype(np.int32)
     self.dc_a_float = dc.array(list(self.np_a_float));
     self.dc_b_float = dc.array(list(self.np_b_float));
     self.fmod_flag = 1
Exemplo n.º 3
0
def test_binary():

    t1 = dc.array(2, 3).asTypeFloat()
    t2 = dc.array(2, 3).asTypeInt()

    add = dc.add(t1, t1)
    add = t1 + t1
Exemplo n.º 4
0
Arquivo: Min.py Projeto: yyht/deepC
    def setUp(self):
        self.len = 24
        self.np_a = np.random.randn(self.len).astype(np.float32)
        self.np_b = np.random.randn(self.len).astype(np.float32)
        self.dc_a = dc.array(list(self.np_a))

        self.dc_b = dc.array(list(self.np_b))
Exemplo n.º 5
0
 def setUp(self):
     self.len = 12
     self.np_a = np.random.randint(12, size=self.len)
     self.np_b = np.random.randint(12, size=self.len)
     self.dc_a = dc.array(list(self.np_a)).asTypeInt()
     self.dc_b = dc.array(list(self.np_b)).asTypeInt()
     self.a_zero_point = dc.array(0).asTypeInt()
     self.b_zero_point = dc.array(0).asTypeInt()
Exemplo n.º 6
0
 def setUp(self):
     self.len = 24
     self.np_x = np.random.randn(self.len).astype(np.int)
     self.np_x_scale = np.random.randn(1).astype(np.float32)
     self.np_x_zero_point = np.random.randn(1).astype(np.int)
     self.dc_x = dc.array(list(self.np_x)).asTypeInt()
     self.dc_x_scale = dc.array(list(self.np_x_scale))
     self.dc_x_zero_point = dc.array(list(self.np_x_zero_point)).asTypeInt()
Exemplo n.º 7
0
    def setUp(self):
        self.len = 48

        self.np_float_a = np.random.randn(self.len).astype(np.float32)
        self.dc_float_a = dc.array(list(self.np_float_a))

        self.np_double_a = np.random.randn(self.len).astype(np.float64)
        self.dc_double_a = dc.array(list(self.np_double_a))
Exemplo n.º 8
0
 def setUp(self):
     self.len1 = 20
     self.len2 = 40
     self.np_a = np.random.randn(self.len1).astype(np.float32)
     self.np_b = np.random.randn(self.len2).astype(np.float32)
     self.np_c = np.random.randn(self.len1).astype(np.float32)
     self.np_d = np.random.randn(self.len2).astype(np.float32)
     self.dc_a = dc.array(list(self.np_a))
     self.dc_b = dc.array(list(self.np_b))
     self.dc_c = dc.array(list(self.np_c))
     self.dc_d = dc.array(list(self.np_d))
     self.err = "operands could not be broadcast together with shapes (2,5,2) (4,5,2)   "
Exemplo n.º 9
0
    def setUp(self):
        self.len = 24

        self.np_a = np.random.randn(self.len).astype(np.float32)
        self.dc_a = dc.array(list(self.np_a))

        self.np_slope_1 = np.random.randn(1).astype(np.float32)
        self.dc_slope_1 = dc.array(list(self.np_slope_1))

        self.np_slope = np.random.randn(self.len).astype(np.float32)
        self.dc_slope = dc.array(list(self.np_slope))

        self.prelu_true = prelu_util(self.np_a, self.np_slope)
        self.prelu_true_1 = prelu_util(self.np_a, self.np_slope_1)
Exemplo n.º 10
0
 def test_LSTM_1(self):
   """
   input_shape: [7, 6, 8]
   weight_shape: [1, 72, 8]
   recurrence_weight_shape: [1, 72, 18]
   bias_shape: [1, 144]
   output_shape: [7, 1, 6, 18]
   """
   np_X = np.load('swig/result/LSTM/test_LSTM_1/test_LSTM_1_X.npy')
   np_W = np.load('swig/result/LSTM/test_LSTM_1/test_LSTM_1_W.npy')
   np_R = np.load('swig/result/LSTM/test_LSTM_1/test_LSTM_1_R.npy')
   np_B = np.load('swig/result/LSTM/test_LSTM_1/test_LSTM_1_B.npy')
   np_sequence_lens = np.load('swig/result/LSTM/test_LSTM_1/test_LSTM_1_sequence_lens.npy')
   np_initial_h = np.load('swig/result/LSTM/test_LSTM_1/test_LSTM_1_initial_h.npy')
   np_initial_c = np.load('swig/result/LSTM/test_LSTM_1/test_LSTM_1_initial_c.npy')
   np_P = np.load('swig/result/LSTM/test_LSTM_1/test_LSTM_1_P.npy')
   dc_X = dc.array(np_X.flatten().tolist()).reshape(np_X.shape)
   dc_W = dc.array(np_W.flatten().tolist()).reshape(np_W.shape)
   dc_R = dc.array(np_R.flatten().tolist()).reshape(np_R.shape)
   dc_B = dc.array(np_B.flatten().tolist()).reshape(np_B.shape)
   dc_sequence_lens = dc.array(np_sequence_lens.flatten().tolist()).reshape(np_sequence_lens.shape)
   # print(dc_sequence_lens)
   dc_initial_h = dc.array(np_initial_h.flatten().tolist()).reshape(np_initial_h.shape)
   dc_initial_c = dc.array(np_initial_c.flatten().tolist()).reshape(np_initial_c.shape)
   dc_P = dc.array(np_P.flatten().tolist()).reshape(np_P.shape)
   activation_alpha = [0.4966638953530237, 0.43607014563539637, 0.8097313919008828]
   activation_beta = [0.12651506658849576, 0.1647539653231257, 0.04623650102301935]
   activations = ['tanh', 'relu', 'sigmoid']
   clip = 2.135794928171123
   direction = "forward"
   hidden_size = 18
   input_forget = 1
   rtr = np.load('swig/result/LSTM/test_LSTM_1/test_LSTM_1_Y.npy')
   dcr = dc.lstm(dc_X, dc_W, dc_R, dc_B, dc_sequence_lens, dc_initial_h, dc_initial_c, dc_P)
Exemplo n.º 11
0
 def test_InstanceNormalization4D_1(self):
     np_a = np.reshape(self.np_a, (2, 2, 2, 3))
     dc_a = dc.reshape(self.dc_a, (2, 2, 2, 3))
     scale = np.reshape(self.scale[0:2], (1, 2, 1, 1))
     B = np.reshape(self.B[0:2], (1, 2, 1, 1))
     np_a_mean = np_a.mean(axis=(0, 2, 3), keepdims=True)
     np_a_var = np_a.var(axis=(0, 2, 3), keepdims=True)
     npr = scale * (np_a - np_a_mean) / np.sqrt(np_a_var + self.epsilon) + B
     dcr = dc.instancenormalization(
         dc_a, dc.reshape(dc.array(list(self.scale[0:2])), (2)),
         dc.reshape(dc.array(list(self.B[0:2])), (2)), self.epsilon)
     np.testing.assert_allclose(npr.flatten(),
                                np.array(dcr.data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Exemplo n.º 12
0
 def test_Slice4D(self):
     len = np.sqrt(np.sqrt(self.len)).astype(int)
     np_a = np.reshape(self.np_a, (len, len, len, len))
     # dc_a  = dc.reshape(self.dc_a, (len, len, len))
     dc_a = dc.reshape(self.dc_a, (8, 8, 8, 8))
     np_start = np.random.randint(len / 2)
     np_end = np.random.randint(len / 2 + 1, len)
     np_step = np.random.randint(1, len - 1)
     np_axes = 1
     np_start2 = np.random.randint(len / 2)
     np_end2 = np.random.randint(len / 2 + 1, len)
     np_step2 = np.random.randint(1, len - 1)
     np_axes2 = 2
     np_start3 = np.random.randint(len / 2)
     np_end3 = np.random.randint(len / 2 + 1, len)
     np_step3 = np.random.randint(1, len - 1)
     np_axes3 = 3
     np_start4 = np.random.randint(len / 2)
     np_end4 = np.random.randint(len / 2 + 1, len)
     np_step4 = np.random.randint(1, len - 1)
     np_axes4 = 4
     dc_start = dc.array(4).asTypeULong()
     dc_end = dc.array(4).asTypeULong()
     dc_axes = dc.array(4).asTypeInt()
     dc_step = dc.array(4).asTypeULong()
     dc_start[0] = np_start
     dc_end[0] = np_end
     dc_axes[0] = np_axes
     dc_step[0] = np_step
     dc_start[1] = np_start2
     dc_end[1] = np_end2
     dc_axes[1] = np_axes2
     dc_step[1] = np_step2
     dc_start[2] = np_start3
     dc_end[2] = np_end3
     dc_axes[2] = np_axes3
     dc_step[2] = np_step3
     dc_start[3] = np_start4
     dc_end[3] = np_end4
     dc_axes[3] = np_axes4
     dc_step[3] = np_step4
     npr = np_a[np_start:np_end:np_step, np_start2:np_end2:np_step2,
                np_start3:np_end3:np_step3, np_start4:np_end4:np_step4]
     dcr = dc.slice(dc_a, dc_start, dc_end, dc_axes, dc_step)
     np.testing.assert_allclose(npr.flatten(),
                                np.array(dcr.data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Exemplo n.º 13
0
 def test_Expand1D(self):
     npr = np.broadcast_to(self.np_a, (3, 3))
     dcr = dc.expand(self.dc_a, dc.array([3, 3]).asTypeInt())
     np.testing.assert_allclose(npr,
                                np.array(dcr.data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Exemplo n.º 14
0
 def setUp(self):
     self.len = 24
     self.np_a = np.random.randn(self.len).astype(np.float32)
     self.dc_a = dc.array(list(self.np_a))
     self.scale = np.random.randn(4).astype(np.float32)
     self.B = np.random.randn(4).astype(np.float32)
     self.epsilon = 1e-05
Exemplo n.º 15
0
 def setUp(self):
     self.len = 24
     self.np_a = np.random.randn(self.len).astype(np.float32)
     self.dc_a = dc.array(list(self.np_a))
     self.alpha = 0.0001
     self.beta = 0.75
     self.bias = 1.0
     self.size = 2
Exemplo n.º 16
0
 def setUp(self):
     self.len = 24
     self.np_a = np.random.randn(self.len)
     self.np_a.ravel()[np.random.choice(self.np_a.size, 5,
                                        replace=False)] = np.inf
     self.np_a.ravel()[np.random.choice(self.np_a.size, 5,
                                        replace=False)] = -np.inf
     self.dc_a = dc.array(list(self.np_a))
     self.detect_positive = 0
     self.detect_negative = 1
Exemplo n.º 17
0
 def test_Slice1D (self):
     len   = self.len
     np_a  = self.np_a
     dc_a  = self.dc_a
     np_start = np.random.randint(len/2)
     np_end   = np.random.randint(len/2 + 1, len)
     np_step  = np.random.randint(1, len-1)
     np_axes  = 0
     dc_start = dc.array(1).asTypeInt()
     dc_end   = dc.array(1).asTypeInt()
     dc_axes  = dc.array(1).asTypeInt()
     dc_step  = dc.array(1).asTypeInt()
     dc_start[0] = np_start
     dc_end[0]   = np_end
     dc_axes[0]  = np_axes
     dc_step[0]  = np_step
     npr   = np_a[np_start:np_end:np_step]
     dcr   = dc.slice(dc_a, dc_start, dc_end, dc_axes, dc_step)
     np.testing.assert_allclose(npr, np.array(dcr.data()).astype(np.float32),
             rtol=1e-3, atol=1e-3)
Exemplo n.º 18
0
 def test_LSTM_8(self):
     """
 input_shape: [5, 1, 9]
 weight_shape: [2, 4, 9]
 recurrence_weight_shape: [2, 4, 1]
 bias_shape: [2, 8]
 output_shape: [5, 2, 1, 1]
 """
     np_X = np.load('swig/result/LSTM/test_LSTM_8/test_LSTM_8_X.npy')
     np_W = np.load('swig/result/LSTM/test_LSTM_8/test_LSTM_8_W.npy')
     np_R = np.load('swig/result/LSTM/test_LSTM_8/test_LSTM_8_R.npy')
     np_B = np.load('swig/result/LSTM/test_LSTM_8/test_LSTM_8_B.npy')
     np_sequence_lens = np.load(
         'swig/result/LSTM/test_LSTM_8/test_LSTM_8_sequence_lens.npy')
     np_initial_h = np.load(
         'swig/result/LSTM/test_LSTM_8/test_LSTM_8_initial_h.npy')
     np_initial_c = np.load(
         'swig/result/LSTM/test_LSTM_8/test_LSTM_8_initial_c.npy')
     np_P = np.load('swig/result/LSTM/test_LSTM_8/test_LSTM_8_P.npy')
     dc_X = dc.array(np_X.flatten().tolist()).reshape(np_X.shape)
     dc_W = dc.array(np_W.flatten().tolist()).reshape(np_W.shape)
     dc_R = dc.array(np_R.flatten().tolist()).reshape(np_R.shape)
     dc_B = dc.array(np_B.flatten().tolist()).reshape(np_B.shape)
     dc_sequence_lens = dc.array(
         np_sequence_lens.flatten().tolist()).reshape(
             np_sequence_lens.shape)
     dc_initial_h = dc.array(np_initial_h.flatten().tolist()).reshape(
         np_initial_h.shape)
     dc_initial_c = dc.array(np_initial_c.flatten().tolist()).reshape(
         np_initial_c.shape)
     dc_P = dc.array(np_P.flatten().tolist()).reshape(np_P.shape)
     activation_alpha = [
         0.7746672952847123, 0.036382870533804956, 0.4848161740062119,
         0.9830896771807061, 0.017064708201858125, 0.6242851269185792
     ]
     activation_beta = [
         0.2517994027716025, 0.28976631245816886, 0.38611683342345127,
         0.13080875018242, 0.40170849770653727, 0.956570288835856
     ]
     activations = ['sigmoid', 'relu', 'sigmoid', 'relu', 'tanh', 'tanh']
     clip = 2.72219901402834
     direction = "bidirectional"
     hidden_size = 1
     input_forget = 20
     rtr = np.load('swig/result/LSTM/test_LSTM_8/test_LSTM_8_Y.npy')
     dcr = dc.lstm(dc_X, dc_W, dc_R, dc_B, dc_sequence_lens, dc_initial_h,
                   dc_initial_c, dc_P)
     np.testing.assert_allclose(rtr.flatten(),
                                np.array(dcr[0].data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Exemplo n.º 19
0
 def test_LSTM_2(self):
     """
 input_shape: [8, 4, 1]
 weight_shape: [2, 64, 1]
 recurrence_weight_shape: [2, 64, 16]
 bias_shape: [2, 128]
 output_shape: [8, 2, 4, 16]
 """
     np_X = np.load('swig/result/LSTM/test_LSTM_2/test_LSTM_2_X.npy')
     np_W = np.load('swig/result/LSTM/test_LSTM_2/test_LSTM_2_W.npy')
     np_R = np.load('swig/result/LSTM/test_LSTM_2/test_LSTM_2_R.npy')
     np_B = np.load('swig/result/LSTM/test_LSTM_2/test_LSTM_2_B.npy')
     np_sequence_lens = np.load(
         'swig/result/LSTM/test_LSTM_2/test_LSTM_2_sequence_lens.npy')
     np_initial_h = np.load(
         'swig/result/LSTM/test_LSTM_2/test_LSTM_2_initial_h.npy')
     np_initial_c = np.load(
         'swig/result/LSTM/test_LSTM_2/test_LSTM_2_initial_c.npy')
     np_P = np.load('swig/result/LSTM/test_LSTM_2/test_LSTM_2_P.npy')
     dc_X = dc.array(np_X.flatten().tolist()).reshape(np_X.shape)
     dc_W = dc.array(np_W.flatten().tolist()).reshape(np_W.shape)
     dc_R = dc.array(np_R.flatten().tolist()).reshape(np_R.shape)
     dc_B = dc.array(np_B.flatten().tolist()).reshape(np_B.shape)
     dc_sequence_lens = dc.array(
         np_sequence_lens.flatten().tolist()).reshape(
             np_sequence_lens.shape)
     dc_initial_h = dc.array(np_initial_h.flatten().tolist()).reshape(
         np_initial_h.shape)
     dc_initial_c = dc.array(np_initial_c.flatten().tolist()).reshape(
         np_initial_c.shape)
     dc_P = dc.array(np_P.flatten().tolist()).reshape(np_P.shape)
     activation_alpha = [
         0.20332784907676504, 0.22637955219185357, 0.6021193542725863,
         0.6168572580474495, 0.40207405192136414, 0.036317260701121845
     ]
     activation_beta = [
         0.7717703726511062, 0.027305984207814826, 0.8047659241021807,
         0.6452577518231254, 0.7319012533727602, 0.25505174775324035
     ]
     activations = ['tanh', 'tanh', 'sigmoid', 'relu', 'sigmoid', 'relu']
     clip = 2.907158875085247
     direction = "bidirectional"
     hidden_size = 16
     input_forget = 10
     rtr = np.load('swig/result/LSTM/test_LSTM_2/test_LSTM_2_Y.npy')
     dcr = dc.lstm(dc_X, dc_W, dc_R, dc_B, dc_sequence_lens, dc_initial_h,
                   dc_initial_c, dc_P)
     np.testing.assert_allclose(rtr.flatten(),
                                np.array(dcr[0].data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Exemplo n.º 20
0
 def test_LSTM_10(self):
     """
 input_shape: [9, 6, 2]
 weight_shape: [2, 8, 2]
 recurrence_weight_shape: [2, 8, 2]
 bias_shape: [2, 16]
 output_shape: [9, 2, 6, 2]
 """
     np_X = np.load('swig/result/LSTM/test_LSTM_10/test_LSTM_10_X.npy')
     np_W = np.load('swig/result/LSTM/test_LSTM_10/test_LSTM_10_W.npy')
     np_R = np.load('swig/result/LSTM/test_LSTM_10/test_LSTM_10_R.npy')
     np_B = np.load('swig/result/LSTM/test_LSTM_10/test_LSTM_10_B.npy')
     np_sequence_lens = np.load(
         'swig/result/LSTM/test_LSTM_10/test_LSTM_10_sequence_lens.npy')
     np_initial_h = np.load(
         'swig/result/LSTM/test_LSTM_10/test_LSTM_10_initial_h.npy')
     np_initial_c = np.load(
         'swig/result/LSTM/test_LSTM_10/test_LSTM_10_initial_c.npy')
     np_P = np.load('swig/result/LSTM/test_LSTM_10/test_LSTM_10_P.npy')
     dc_X = dc.array(np_X.flatten().tolist()).reshape(np_X.shape)
     dc_W = dc.array(np_W.flatten().tolist()).reshape(np_W.shape)
     dc_R = dc.array(np_R.flatten().tolist()).reshape(np_R.shape)
     dc_B = dc.array(np_B.flatten().tolist()).reshape(np_B.shape)
     dc_sequence_lens = dc.array(
         np_sequence_lens.flatten().tolist()).reshape(
             np_sequence_lens.shape)
     dc_initial_h = dc.array(np_initial_h.flatten().tolist()).reshape(
         np_initial_h.shape)
     dc_initial_c = dc.array(np_initial_c.flatten().tolist()).reshape(
         np_initial_c.shape)
     dc_P = dc.array(np_P.flatten().tolist()).reshape(np_P.shape)
     activation_alpha = [
         0.5494076090797351, 0.4486022544214028, 0.8555569145519173,
         0.36385914141140563, 0.2786060330869964, 0.3709594247211093
     ]
     activation_beta = [
         0.6841038069275263, 0.12454085979724905, 0.16010194778825715,
         0.43645368358634684, 0.2006827543226236, 0.025382308479808713
     ]
     activations = ['relu', 'tanh', 'relu', 'sigmoid', 'sigmoid', 'tanh']
     clip = 7.52494780016543
     direction = "bidirectional"
     hidden_size = 2
     input_forget = 19
     rtr = np.load('swig/result/LSTM/test_LSTM_10/test_LSTM_10_Y.npy')
     dcr = dc.lstm(dc_X, dc_W, dc_R, dc_B, dc_sequence_lens, dc_initial_h,
                   dc_initial_c, dc_P)
     np.testing.assert_allclose(rtr.flatten(),
                                np.array(dcr[0].data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Exemplo n.º 21
0
 def test_LSTM_7(self):
     """
 input_shape: [6, 8, 6]
 weight_shape: [2, 40, 6]
 recurrence_weight_shape: [2, 40, 10]
 bias_shape: [2, 80]
 output_shape: [6, 2, 8, 10]
 """
     np_X = np.load('swig/result/LSTM/test_LSTM_7/test_LSTM_7_X.npy')
     np_W = np.load('swig/result/LSTM/test_LSTM_7/test_LSTM_7_W.npy')
     np_R = np.load('swig/result/LSTM/test_LSTM_7/test_LSTM_7_R.npy')
     np_B = np.load('swig/result/LSTM/test_LSTM_7/test_LSTM_7_B.npy')
     np_sequence_lens = np.load(
         'swig/result/LSTM/test_LSTM_7/test_LSTM_7_sequence_lens.npy')
     np_initial_h = np.load(
         'swig/result/LSTM/test_LSTM_7/test_LSTM_7_initial_h.npy')
     np_initial_c = np.load(
         'swig/result/LSTM/test_LSTM_7/test_LSTM_7_initial_c.npy')
     np_P = np.load('swig/result/LSTM/test_LSTM_7/test_LSTM_7_P.npy')
     dc_X = dc.array(np_X.flatten().tolist()).reshape(np_X.shape)
     dc_W = dc.array(np_W.flatten().tolist()).reshape(np_W.shape)
     dc_R = dc.array(np_R.flatten().tolist()).reshape(np_R.shape)
     dc_B = dc.array(np_B.flatten().tolist()).reshape(np_B.shape)
     dc_sequence_lens = dc.array(
         np_sequence_lens.flatten().tolist()).reshape(
             np_sequence_lens.shape)
     dc_initial_h = dc.array(np_initial_h.flatten().tolist()).reshape(
         np_initial_h.shape)
     dc_initial_c = dc.array(np_initial_c.flatten().tolist()).reshape(
         np_initial_c.shape)
     dc_P = dc.array(np_P.flatten().tolist()).reshape(np_P.shape)
     activation_alpha = [
         0.28920619362824995, 0.747465052565989, 0.661162342694396,
         0.8477376049646675, 0.07881817761441567, 0.16208001287665696
     ]
     activation_beta = [
         0.7627506699799991, 0.6606114297796492, 0.9585330972395699,
         0.5549681443136113, 0.059042596260018065, 0.04648254501072813
     ]
     activations = ['sigmoid', 'sigmoid', 'tanh', 'relu', 'relu', 'tanh']
     clip = 3.879685115272961
     direction = "bidirectional"
     hidden_size = 10
     input_forget = 11
     rtr = np.load('swig/result/LSTM/test_LSTM_7/test_LSTM_7_Y.npy')
     dcr = dc.lstm(dc_X, dc_W, dc_R, dc_B, dc_sequence_lens, dc_initial_h,
                   dc_initial_c, dc_P)
     np.testing.assert_allclose(rtr.flatten(),
                                np.array(dcr[0].data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Exemplo n.º 22
0
 def test_LSTM_4(self):
     """
 input_shape: [2, 1, 1]
 weight_shape: [2, 72, 1]
 recurrence_weight_shape: [2, 72, 18]
 bias_shape: [2, 144]
 output_shape: [2, 2, 1, 18]
 """
     np_X = np.load('swig/result/LSTM/test_LSTM_4/test_LSTM_4_X.npy')
     np_W = np.load('swig/result/LSTM/test_LSTM_4/test_LSTM_4_W.npy')
     np_R = np.load('swig/result/LSTM/test_LSTM_4/test_LSTM_4_R.npy')
     np_B = np.load('swig/result/LSTM/test_LSTM_4/test_LSTM_4_B.npy')
     np_sequence_lens = np.load(
         'swig/result/LSTM/test_LSTM_4/test_LSTM_4_sequence_lens.npy')
     np_initial_h = np.load(
         'swig/result/LSTM/test_LSTM_4/test_LSTM_4_initial_h.npy')
     np_initial_c = np.load(
         'swig/result/LSTM/test_LSTM_4/test_LSTM_4_initial_c.npy')
     np_P = np.load('swig/result/LSTM/test_LSTM_4/test_LSTM_4_P.npy')
     dc_X = dc.array(np_X.flatten().tolist()).reshape(np_X.shape)
     dc_W = dc.array(np_W.flatten().tolist()).reshape(np_W.shape)
     dc_R = dc.array(np_R.flatten().tolist()).reshape(np_R.shape)
     dc_B = dc.array(np_B.flatten().tolist()).reshape(np_B.shape)
     dc_sequence_lens = dc.array(
         np_sequence_lens.flatten().tolist()).reshape(
             np_sequence_lens.shape)
     dc_initial_h = dc.array(np_initial_h.flatten().tolist()).reshape(
         np_initial_h.shape)
     dc_initial_c = dc.array(np_initial_c.flatten().tolist()).reshape(
         np_initial_c.shape)
     dc_P = dc.array(np_P.flatten().tolist()).reshape(np_P.shape)
     activation_alpha = [
         0.9860778314893995, 0.12417696210947016, 0.0006744261981547206,
         0.24339585920465567, 0.7498252461249489, 0.30754908604622977
     ]
     activation_beta = [
         0.1603792258866038, 0.1880417110347281, 0.6952466604231525,
         0.11767276043277997, 0.61860245840078, 0.6615465711832315
     ]
     activations = ['sigmoid', 'relu', 'sigmoid', 'tanh', 'relu', 'tanh']
     clip = 3.7019881776389996
     direction = "bidirectional"
     hidden_size = 18
     input_forget = 8
     rtr = np.load('swig/result/LSTM/test_LSTM_4/test_LSTM_4_Y.npy')
     dcr = dc.lstm(dc_X, dc_W, dc_R, dc_B, dc_sequence_lens, dc_initial_h,
                   dc_initial_c, dc_P)
     np.testing.assert_allclose(rtr.flatten(),
                                np.array(dcr[0].data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Exemplo n.º 23
0
 def test_LSTM_5(self):
     """
 input_shape: [2, 3, 10]
 weight_shape: [2, 20, 10]
 recurrence_weight_shape: [2, 20, 5]
 bias_shape: [2, 40]
 output_shape: [2, 2, 3, 5]
 """
     np_X = np.load('swig/result/LSTM/test_LSTM_5/test_LSTM_5_X.npy')
     np_W = np.load('swig/result/LSTM/test_LSTM_5/test_LSTM_5_W.npy')
     np_R = np.load('swig/result/LSTM/test_LSTM_5/test_LSTM_5_R.npy')
     np_B = np.load('swig/result/LSTM/test_LSTM_5/test_LSTM_5_B.npy')
     np_sequence_lens = np.load(
         'swig/result/LSTM/test_LSTM_5/test_LSTM_5_sequence_lens.npy')
     np_initial_h = np.load(
         'swig/result/LSTM/test_LSTM_5/test_LSTM_5_initial_h.npy')
     np_initial_c = np.load(
         'swig/result/LSTM/test_LSTM_5/test_LSTM_5_initial_c.npy')
     np_P = np.load('swig/result/LSTM/test_LSTM_5/test_LSTM_5_P.npy')
     dc_X = dc.array(np_X.flatten().tolist()).reshape(np_X.shape)
     dc_W = dc.array(np_W.flatten().tolist()).reshape(np_W.shape)
     dc_R = dc.array(np_R.flatten().tolist()).reshape(np_R.shape)
     dc_B = dc.array(np_B.flatten().tolist()).reshape(np_B.shape)
     dc_sequence_lens = dc.array(
         np_sequence_lens.flatten().tolist()).reshape(
             np_sequence_lens.shape)
     dc_initial_h = dc.array(np_initial_h.flatten().tolist()).reshape(
         np_initial_h.shape)
     dc_initial_c = dc.array(np_initial_c.flatten().tolist()).reshape(
         np_initial_c.shape)
     dc_P = dc.array(np_P.flatten().tolist()).reshape(np_P.shape)
     activation_alpha = [
         0.9958868560901981, 0.5615704868314114, 0.5054884381550756,
         0.5125119319409338, 0.18310275479264726, 0.4990119412451889
     ]
     activation_beta = [
         0.2876466600692591, 0.560778821439632, 0.2632346842213401,
         0.13121922832510213, 0.8822817678248556, 0.9880592276419286
     ]
     activations = ['tanh', 'relu', 'tanh', 'sigmoid', 'sigmoid', 'relu']
     clip = 6.117108798702516
     direction = "bidirectional"
     hidden_size = 5
     input_forget = 17
     rtr = np.load('swig/result/LSTM/test_LSTM_5/test_LSTM_5_Y.npy')
     dcr = dc.lstm(dc_X, dc_W, dc_R, dc_B, dc_sequence_lens, dc_initial_h,
                   dc_initial_c, dc_P)
     np.testing.assert_allclose(rtr.flatten(),
                                np.array(dcr[0].data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Exemplo n.º 24
0
 def test_LSTM_9(self):
     """
 input_shape: [1, 2, 9]
 weight_shape: [1, 52, 9]
 recurrence_weight_shape: [1, 52, 13]
 bias_shape: [1, 104]
 output_shape: [1, 1, 2, 13]
 """
     np_X = np.load('swig/result/LSTM/test_LSTM_9/test_LSTM_9_X.npy')
     np_W = np.load('swig/result/LSTM/test_LSTM_9/test_LSTM_9_W.npy')
     np_R = np.load('swig/result/LSTM/test_LSTM_9/test_LSTM_9_R.npy')
     np_B = np.load('swig/result/LSTM/test_LSTM_9/test_LSTM_9_B.npy')
     np_sequence_lens = np.load(
         'swig/result/LSTM/test_LSTM_9/test_LSTM_9_sequence_lens.npy')
     np_initial_h = np.load(
         'swig/result/LSTM/test_LSTM_9/test_LSTM_9_initial_h.npy')
     np_initial_c = np.load(
         'swig/result/LSTM/test_LSTM_9/test_LSTM_9_initial_c.npy')
     np_P = np.load('swig/result/LSTM/test_LSTM_9/test_LSTM_9_P.npy')
     dc_X = dc.array(np_X.flatten().tolist()).reshape(np_X.shape)
     dc_W = dc.array(np_W.flatten().tolist()).reshape(np_W.shape)
     dc_R = dc.array(np_R.flatten().tolist()).reshape(np_R.shape)
     dc_B = dc.array(np_B.flatten().tolist()).reshape(np_B.shape)
     dc_sequence_lens = dc.array(
         np_sequence_lens.flatten().tolist()).reshape(
             np_sequence_lens.shape)
     dc_initial_h = dc.array(np_initial_h.flatten().tolist()).reshape(
         np_initial_h.shape)
     dc_initial_c = dc.array(np_initial_c.flatten().tolist()).reshape(
         np_initial_c.shape)
     dc_P = dc.array(np_P.flatten().tolist()).reshape(np_P.shape)
     activation_alpha = [
         0.08447232888329703, 0.6786879671317316, 0.6558691737892577
     ]
     activation_beta = [
         0.7615097936520958, 0.5651098460911419, 0.2265325436094976
     ]
     activations = ['sigmoid', 'relu', 'tanh']
     clip = 6.4355391083683635
     direction = "forward"
     hidden_size = 13
     input_forget = 14
     rtr = np.load('swig/result/LSTM/test_LSTM_9/test_LSTM_9_Y.npy')
     dcr = dc.lstm(dc_X, dc_W, dc_R, dc_B, dc_sequence_lens, dc_initial_h,
                   dc_initial_c, dc_P)
     np.testing.assert_allclose(rtr.flatten(),
                                np.array(dcr[0].data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Exemplo n.º 25
0
 def test_LSTM_3(self):
     """
 input_shape: [8, 1, 4]
 weight_shape: [1, 56, 4]
 recurrence_weight_shape: [1, 56, 14]
 bias_shape: [1, 112]
 output_shape: [8, 1, 1, 14]
 """
     np_X = np.load('swig/result/LSTM/test_LSTM_3/test_LSTM_3_X.npy')
     np_W = np.load('swig/result/LSTM/test_LSTM_3/test_LSTM_3_W.npy')
     np_R = np.load('swig/result/LSTM/test_LSTM_3/test_LSTM_3_R.npy')
     np_B = np.load('swig/result/LSTM/test_LSTM_3/test_LSTM_3_B.npy')
     np_sequence_lens = np.load(
         'swig/result/LSTM/test_LSTM_3/test_LSTM_3_sequence_lens.npy')
     np_initial_h = np.load(
         'swig/result/LSTM/test_LSTM_3/test_LSTM_3_initial_h.npy')
     np_initial_c = np.load(
         'swig/result/LSTM/test_LSTM_3/test_LSTM_3_initial_c.npy')
     np_P = np.load('swig/result/LSTM/test_LSTM_3/test_LSTM_3_P.npy')
     dc_X = dc.array(np_X.flatten().tolist()).reshape(np_X.shape)
     dc_W = dc.array(np_W.flatten().tolist()).reshape(np_W.shape)
     dc_R = dc.array(np_R.flatten().tolist()).reshape(np_R.shape)
     dc_B = dc.array(np_B.flatten().tolist()).reshape(np_B.shape)
     dc_sequence_lens = dc.array(
         np_sequence_lens.flatten().tolist()).reshape(
             np_sequence_lens.shape)
     dc_initial_h = dc.array(np_initial_h.flatten().tolist()).reshape(
         np_initial_h.shape)
     dc_initial_c = dc.array(np_initial_c.flatten().tolist()).reshape(
         np_initial_c.shape)
     dc_P = dc.array(np_P.flatten().tolist()).reshape(np_P.shape)
     activation_alpha = [
         0.5353786525215217, 0.0047814145847226985, 0.17116077889292602
     ]
     activation_beta = [
         0.8724323449420001, 0.9207316192126214, 0.7391156087035118
     ]
     activations = ['relu', 'sigmoid', 'tanh']
     clip = 7.5397611403351
     direction = "reverse"
     hidden_size = 14
     input_forget = 14
     rtr = np.load('swig/result/LSTM/test_LSTM_3/test_LSTM_3_Y.npy')
     dcr = dc.lstm(dc_X, dc_W, dc_R, dc_B, dc_sequence_lens, dc_initial_h,
                   dc_initial_c, dc_P)
     np.testing.assert_allclose(rtr.flatten(),
                                np.array(dcr[0].data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Exemplo n.º 26
0
 def test_LSTM_6(self):
     """
 input_shape: [7, 5, 9]
 weight_shape: [1, 64, 9]
 recurrence_weight_shape: [1, 64, 16]
 bias_shape: [1, 128]
 output_shape: [7, 1, 5, 16]
 """
     np_X = np.load('swig/result/LSTM/test_LSTM_6/test_LSTM_6_X.npy')
     np_W = np.load('swig/result/LSTM/test_LSTM_6/test_LSTM_6_W.npy')
     np_R = np.load('swig/result/LSTM/test_LSTM_6/test_LSTM_6_R.npy')
     np_B = np.load('swig/result/LSTM/test_LSTM_6/test_LSTM_6_B.npy')
     np_sequence_lens = np.load(
         'swig/result/LSTM/test_LSTM_6/test_LSTM_6_sequence_lens.npy')
     np_initial_h = np.load(
         'swig/result/LSTM/test_LSTM_6/test_LSTM_6_initial_h.npy')
     np_initial_c = np.load(
         'swig/result/LSTM/test_LSTM_6/test_LSTM_6_initial_c.npy')
     np_P = np.load('swig/result/LSTM/test_LSTM_6/test_LSTM_6_P.npy')
     dc_X = dc.array(np_X.flatten().tolist()).reshape(np_X.shape)
     dc_W = dc.array(np_W.flatten().tolist()).reshape(np_W.shape)
     dc_R = dc.array(np_R.flatten().tolist()).reshape(np_R.shape)
     dc_B = dc.array(np_B.flatten().tolist()).reshape(np_B.shape)
     dc_sequence_lens = dc.array(
         np_sequence_lens.flatten().tolist()).reshape(
             np_sequence_lens.shape)
     dc_initial_h = dc.array(np_initial_h.flatten().tolist()).reshape(
         np_initial_h.shape)
     dc_initial_c = dc.array(np_initial_c.flatten().tolist()).reshape(
         np_initial_c.shape)
     dc_P = dc.array(np_P.flatten().tolist()).reshape(np_P.shape)
     activation_alpha = [
         0.1508855746391079, 0.4507448733258578, 0.41656131175216204
     ]
     activation_beta = [
         0.5657658415464043, 0.21611300965755376, 0.15922967506138452
     ]
     activations = ['tanh', 'relu', 'sigmoid']
     clip = 3.1767036746309287
     direction = "forward"
     hidden_size = 16
     input_forget = 14
     rtr = np.load('swig/result/LSTM/test_LSTM_6/test_LSTM_6_Y.npy')
     dcr = dc.lstm(dc_X, dc_W, dc_R, dc_B, dc_sequence_lens, dc_initial_h,
                   dc_initial_c, dc_P)
     np.testing.assert_allclose(rtr.flatten(),
                                np.array(dcr[0].data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Exemplo n.º 27
0
 def setUp(self):
     self.nullT = dc.array(0)
     self.zeros = dc.zeros(2, 3).asTypeInt()
     self.ones = dc.ones(2, 3).asTypeInt()
     self.f0_4 = dc.arange(5)
     self.f5_9 = dc.arange(10, 5)
     self.np_f0_4 = np.arange(5)
     self.np_f5_9 = np.arange(10, 5)
     self.i0_4 = self.f0_4.asTypeInt()
     self.i5_9 = self.f5_9.asTypeInt()
     self.np_i0_4 = self.np_f0_4.astype(np.int)
     self.np_i5_9 = self.np_f5_9.astype(np.int)
     self.b0_4 = self.f0_4.asTypeBool()
     self.b5_9 = self.f5_9.asTypeBool()
Exemplo n.º 28
0
    def setUp(self):
        self.num_directions = 1
        self.seq_length = 1
        self.input_size = 4
        self.batch_size = 3
        self.hidden_size = 5

        self.np_x = np.random.randn(self.seq_length * self.batch_size * self.input_size).astype(np.float32)
        self.dc_x = dc.array(list(self.np_x))

        self.np_w = np.random.randn(self.num_directions * 4 * self.hidden_size * self.input_size).astype(np.float32)
        self.dc_w = dc.array(list(self.np_w))

        self.np_r = np.random.randn(self.num_directions * 4 * self.hidden_size * self.hidden_size).astype(np.float32)
        self.dc_r = dc.array(list(self.np_r))

        self.np_b = np.random.randn(self.num_directions * 8 * self.hidden_size).astype(np.float32)
        self.dc_b = dc.array(list(self.np_b))

        self.np_h = np.random.randn(self.num_directions * self.batch_size * self.hidden_size).astype(np.float32)
        self.dc_h = dc.array(list(self.np_h))

        self.np_c = np.random.randn(self.num_directions * self.batch_size * self.hidden_size).astype(np.float32)
        self.dc_c = dc.array(list(self.np_c))

        self.np_p = np.random.randn(self.num_directions * 3 * self.hidden_size).astype(np.float32)
        self.dc_p = dc.array(list(self.np_p))





        self.np_x = np.reshape(self.np_x, (self.seq_length, self.batch_size, self.input_size))
        self.dc_x = dc.reshape(self.dc_x, (self.seq_length, self.batch_size, self.input_size))

        self.np_w = np.reshape(self.np_w, (self.num_directions, 4 * self.hidden_size, self.input_size))
        self.dc_w = dc.reshape(self.dc_w, (self.num_directions, 4 * self.hidden_size, self.input_size))

        self.np_r = np.reshape(self.np_r, (self.num_directions, 4 * self.hidden_size, self.hidden_size))
        self.dc_r = dc.reshape(self.dc_r, (self.num_directions, 4 * self.hidden_size, self.hidden_size))

        self.np_b = np.reshape(self.np_b, (self.num_directions, 8 * self.hidden_size))
        self.dc_b = dc.reshape(self.dc_b, (self.num_directions, 8 * self.hidden_size))
        
        self.np_h = np.reshape(self.np_h, (self.num_directions, self.batch_size, self.hidden_size))
        self.dc_h = dc.reshape(self.dc_h, (self.num_directions, self.batch_size, self.hidden_size))

        self.np_c = np.reshape(self.np_c, (self.num_directions, self.batch_size, self.hidden_size))
        self.dc_c = dc.reshape(self.dc_c, (self.num_directions, self.batch_size, self.hidden_size))

        self.np_p = np.reshape(self.np_p, (self.num_directions, 3 * self.hidden_size))
        self.dc_p = dc.reshape(self.dc_p, (self.num_directions, 3 * self.hidden_size))
Exemplo n.º 29
0
 def test_Slice3D (self):
     len   = np.cbrt(self.len).astype(int)
     np_a  = np.reshape(self.np_a, (len, len, len))
     # dc_a  = dc.reshape(self.dc_a, (len, len, len))
     dc_a  = dc.reshape(self.dc_a, (16, 16, 16))
     np_start  = np.random.randint(len/2)
     np_end    = np.random.randint(len/2 + 1, len)
     np_step   = np.random.randint(1, len-1)
     np_axes   = 0
     np_start2 = np.random.randint(len/2)
     np_end2   = np.random.randint(len/2 + 1, len)
     np_step2  = np.random.randint(1, len-1)
     np_axes2  = 1
     np_start3 = np.random.randint(len/2)
     np_end3   = np.random.randint(len/2 + 1, len)
     np_step3  = np.random.randint(1, len-1)
     np_axes3  = 2
     dc_start  = dc.array(3).asTypeInt()
     dc_end    = dc.array(3).asTypeInt()
     dc_axes   = dc.array(3).asTypeInt()
     dc_step   = dc.array(3).asTypeInt()
     dc_start[0] = np_start
     dc_end[0]   = np_end
     dc_axes[0]  = np_axes
     dc_step[0]  = np_step
     dc_start[1] = np_start2
     dc_end[1]   = np_end2
     dc_axes[1]  = np_axes2
     dc_step[1]  = np_step2
     dc_start[2] = np_start3
     dc_end[2]   = np_end3
     dc_axes[2]  = np_axes3
     dc_step[2]  = np_step3
     npr   = np_a[np_start:np_end:np_step, np_start2:np_end2:np_step2, np_start3:np_end3:np_step3]
     dcr   = dc.slice(dc_a, dc_start, dc_end, dc_axes, dc_step)
     np.testing.assert_allclose(npr.flatten(), np.array(dcr.data()).astype(np.float32),
             rtol=1e-3, atol=1e-3)
Exemplo n.º 30
0
def test_detailed():
    t_dc = dc.array([[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]])
    t_dc1 = dc.array([[21, 22], [23, 24], [26, 27]])
    t_dc[2]
    t_dc[2, 1]
    int(t_dc[2, 1])
    t_dc[2:3, :]
    t_dc[2]
    t_dc[2, :]
    t_dc[2:3, 1:2]
    t_dc[1, ::2]
    t_dc[1:2:1, 1:2]
    t_dc[1:2:1, ...]
    t_dc[..., 1]
    t_dc[..., ::-2]
    t_dc[1:2:-1, ::-2]
    t_dc[2:3, 1:2] = 30
    t_dc[2, 1] = 1
    t_dc[0:3, 0:2] = t_dc1
    t1 = dc.array(2, 3).asTypeFloat()
    t2 = dc.array(2, 3).asTypeInt()

    add = dc.add(t1, t1)
    add = t1 + t1