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)
def test_MatMul2D (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)
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)
def test_multiply(a, b): c = dc.matmul(a, b)
import os, sys sys.path.append(os.path.abspath('.')) import dnnc as dc t1 = dc.array(2, 3) t2 = dc.array(3, 2) mul = dc.matmul(t1, t2) #print ("multiplication : " , mul.to_string()) add = dc.add(t1, t1) #print ("addition : " , add.to_string()) t3 = dc.array(2, 3, 4) #print("old shape", t1.shape()) new_shape = dc.ivec([2, 12]) t3.reshape(new_shape) #print("new shape", t1.shape()) #t4 = dc.thresholded_relu(t1); #print("relu", t4.to_string()) #replace first few values in tensor with new values. data = dc.fvec([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]]) #print(arr2D) arrRand = dc.random(2, 3)