Example #1
0
File: MatMul.py Project: yyht/deepC
 def testMatMul1D(self):
     npr = np.matmul(self.np_a, self.np_b)
     dcr = dc.matmul(self.dc_a, self.dc_b)
     np.testing.assert_allclose(npr,
                                np.array(dcr.data()[0]).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Example #2
0
File: MatMul.py Project: yyht/deepC
 def testMatMul2D(self):
     np_a = np.reshape(self.np_a, (3, 4))
     np_b = np.reshape(self.np_b, (4, 3))
     dc_a = dc.reshape(self.dc_a, (3, 4))
     dc_b = dc.reshape(self.dc_b, (4, 3))
     npr = np.matmul(np_a, np_b)
     dcr = dc.matmul(dc_a, dc_b)
     np.testing.assert_allclose(npr.flatten(),
                                np.array(dcr.data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Example #3
0
def test_multiply(a, b):
    c = dc.matmul(a, b)
Example #4
0
def test_non_binary():

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

    mul = dc.matmul(t1, t2)
    #print ("multiplication : " , mul.to_string())

    t3 = dc.array(2, 3, 4)
    #print("old shape", t1.shape())
    new_shape = dc.vectorSizeT([2, 12])
    t3.reshape(new_shape)
    t3.reshape(4, 6)
    t3.reshape((4, 6))
    t3.reshape([4, 6])
    #print("new shape", t1.shape())

    py_list = list(t3)
    # convert tensor to python list
    py_tuple = tuple(t3)
    # convert tensor to python tuple
    np_ary = t3.numpy()
    # convert to numpy array

    #t4 = dc.thresholded_relu(t1);
    #print("relu", t4.to_string())

    #replace first few values in tensor with new values.
    data = dc.vectorFloat([1.0, 2.0, 3.0, 4.0])
    t3.load(data)
    #print(t3.to_string())

    arr = dc.array([1, 2])
    #print(arr)
    arr2D = dc.array([[1, 2], [10, 20]]).asTypeInt()
    #print(arr2D)
    arrRand = dc.random(2, 3)
    #print(arrRand)
    empty = dc.empty(3, 2)
    #print(empty)
    zeros = dc.zeros(2, 2)
    #print(zeros);
    ones = dc.ones(2, 2)
    #print(ones)
    ranges = dc.arange(15, 3, 2)
    #print(ranges)

    dc.reshape(arr2D, (1, 4))

    #3D MatMul Test1
    a = dc.array(2, 2, 2)
    b = dc.array(2, 2, 2)
    adata = dc.vectorFloat([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0])
    bdata = dc.vectorFloat([8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0])
    a.load(adata)
    b.load(bdata)
    test_multiply(a, b)

    #3D MatMul Test2
    a = dc.array(2, 2, 3)
    b = dc.array(2, 3, 2)
    adata = dc.vectorFloat(
        [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0])
    bdata = dc.vectorFloat(
        [12.0, 11.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0])
    a.load(adata)
    b.load(bdata)
    test_multiply(a, b)
Example #5
0
    def MatMul3D (self):
        dc_a = dc.reshape(self.dc_a, (self.N, self.N))
        dc_b = dc.reshape(self.dc_b, (self.N, self.N))

        dcr = dc.matmul(dc_a, dc_b);