Esempio n. 1
0
 def test_Add1D_int_float(self):
     npr = np.add(self.np_int_a, self.np_float_b)
     dcr = dc.add(self.dc_int_a, self.dc_float_b)
     np.testing.assert_allclose(npr,
                                np.array(dcr.data()),
                                rtol=1e-3,
                                atol=1e-3)
Esempio n. 2
0
 def test_Add1D(self):
     npr = np.add(self.np_a, self.np_b)
     dcr = dc.add(self.dc_a, self.dc_b)
     np.testing.assert_allclose(npr,
                                np.array(dcr.data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Esempio n. 3
0
 def test_Add1D_double_bool(self):
     npr = np.add(self.np_double_a, self.np_bool_b)
     dcr = dc.add(self.dc_double_a, self.dc_bool_b)
     np.testing.assert_allclose(npr,
                                np.array(dcr.data()),
                                rtol=1e-3,
                                atol=1e-3)
Esempio n. 4
0
 def test_Add4D_double_double(self):
     np_double_a = np.reshape(self.np_double_a, (4, 2, 2, 3))
     np_double_b = np.reshape(self.np_double_b, (4, 2, 2, 3))
     dc_double_a = dc.reshape(self.dc_double_a, (4, 2, 2, 3))
     dc_double_b = dc.reshape(self.dc_double_b, (4, 2, 2, 3))
     npr = np.add(np_double_a, np_double_b)
     dcr = dc.add(dc_double_a, dc_double_b)
     np.testing.assert_allclose(npr.flatten(),
                                np.array(dcr.data()),
                                rtol=1e-3,
                                atol=1e-3)
Esempio n. 5
0
 def test_Add3D_float_float(self):
     np_float_a = np.reshape(self.np_float_a, (4, 4, 3))
     np_float_b = np.reshape(self.np_float_b, (4, 4, 3))
     dc_float_a = dc.reshape(self.dc_float_a, (4, 4, 3))
     dc_float_b = dc.reshape(self.dc_float_b, (4, 4, 3))
     npr = np.add(np_float_a, np_float_b)
     dcr = dc.add(dc_float_a, dc_float_b)
     np.testing.assert_allclose(npr.flatten(),
                                np.array(dcr.data()),
                                rtol=1e-3,
                                atol=1e-3)
Esempio n. 6
0
 def test_Add2D_int_int(self):
     np_int_a = np.reshape(self.np_int_a, (6, 8))
     np_int_b = np.reshape(self.np_int_b, (6, 8))
     dc_int_a = dc.reshape(self.dc_int_a, (6, 8))
     dc_int_b = dc.reshape(self.dc_int_b, (6, 8))
     npr = np.add(np_int_a, np_int_b)
     dcr = dc.add(dc_int_a, dc_int_b)
     np.testing.assert_allclose(npr.flatten(),
                                np.array(dcr.data()),
                                rtol=1e-3,
                                atol=1e-3)
Esempio n. 7
0
 def test_Add(self):
     dc_a = dc.reshape(self.dc_a, (5, 4))
     dc_b = dc.reshape(self.dc_b, (2, 5, 4))
     np_a = np.reshape(self.np_a, (5, 4))
     np_b = np.reshape(self.np_b, (2, 5, 4))
     npr = np.add(np_a, np_b)
     dcr = dc.add(dc_a, dc_b)
     np.testing.assert_allclose(npr.flatten(),
                                np.array(dcr.data()).astype(np.float32),
                                rtol=1e-3,
                                atol=1e-3)
Esempio n. 8
0
 def test_error_message(self):
     dc_a = dc.reshape(self.dc_a, (2, 5, 2))
     dc_b = dc.reshape(self.dc_b, (4, 5, 2))
     np_a = np.reshape(self.np_a, (2, 5, 2))
     np_b = np.reshape(self.np_b, (4, 5, 2))
     try:
         np_sum = np.add(np_a, np_b)
     except:
         type, val, tb = sys.exc_info()
         np_err = val.__str__()
         assert (np_err[0:65] == self.err[0:65]
                 ), "ASSERT FAILED for numpy error message"
     try:
         dc_sum = dc.add(dc_a, dc_b)
     except:
         type, val, tb = sys.exc_info()
         dc_err = val.__str__()
         assert (dc_err[0:65] == self.err[0:65]
                 ), "ASSERT FAILED for dc error message"
         assert (dc_err[0:65] == np_err[0:65]
                 ), "ASSERT FAILED for matching numpy and dc error message"
Esempio n. 9
0
import os, sys
sys.path.append(os.path.abspath('.'))

import dnnc
t1 = dnnc.make_tensor(2, 3)
t2 = dnnc.make_tensor(3, 2)

mul = dnnc.multiply(t1, t2)
#print ("multiplication : " , mul.to_string())
add = dnnc.add(t1, t1)
#print ("addition : " , add.to_string())

t3 = dnnc.make_tensor(2, 3, 4)
#print("old shape", t1.shape())
new_shape = dnnc.ivec([2, 12])
t3.reshape(new_shape)
#print("new shape", t1.shape())

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

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


def test_multiply(a, b):
    c = dnnc.multiply(a, b)
    #print(c.to_string())
Esempio n. 10
0
import os,sys
sys.path.append(os.path.abspath('.'));

import dnnc as dc
t1=dc.make_tensor(2,3)
t2=dc.make_tensor(3,2)

mul = dc.multiply(t1,t2)
#print ("multiplication : " , mul.to_string())
add = dc.add(t1,t1)
#print ("addition : " , add.to_string())

t3 = dc.make_tensor(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);