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.i0_4 = self.f0_4.asTypeInt()
     self.i5_9 = self.f5_9.asTypeInt()
     self.b0_4 = self.f0_4.asTypeBool()
     self.b5_9 = self.f5_9.asTypeBool()
    def setUp(self):

        self.np_bool_0_4 = np.arange(5).astype(np.bool)
        self.np_bool_5_9 = np.arange(5, 10).astype(np.bool)

        self.np_int_0_4 = np.arange(5).astype(np.int)
        self.np_int_5_9 = np.arange(5, 10).astype(np.int)

        self.np_float_0_4 = np.arange(5).astype(np.float)
        self.np_float_5_9 = np.arange(5, 10).astype(np.float)

        self.np_double_0_4 = np.arange(5).astype(np.double)
        self.np_double_5_9 = np.arange(5, 10).astype(np.double)

        self.dc_bool_0_4 = dc.arange(5).asTypeBool()
        self.dc_bool_5_9 = dc.arange(5, 10).asTypeBool()

        self.dc_int_0_4 = dc.arange(5).asTypeInt()
        self.dc_int_5_9 = dc.arange(5, 10).asTypeInt()

        self.dc_float_0_4 = dc.arange(5).asTypeFloat()
        self.dc_float_5_9 = dc.arange(5, 10).asTypeFloat()

        self.dc_double_0_4 = dc.arange(5).asTypeDouble()
        self.dc_double_5_9 = dc.arange(5, 10).asTypeDouble()
Example #3
0
    def test_data(self):

        # confirm type as class tuple.
        a = dc.zeros(2, 3).astype('int')
        adata = a.data()
        assert type(adata) == type((1, ))

        # load new data
        new_data_list = [10, 11, 12, 13, 14, 15]
        a.load(dc.ivec(new_data_list))
        assert a[0] == 10

        # load one element with flat index
        a[0] = 777
        assert a[0] == 777

        # reshape, fetch and load with multi indices
        a = dc.arange(12).astype('int')
        a.reshape(dc.lvec([2, 2, 3]))
        assert a[0, 1, 1] == 4

        a[1, 1, 1] = 200
        assert a[1, 1, 1] == 200

        # negative test
        try:
            # This throws ValueError
            print(a[0, 0, 9, 9, 9])
        except ValueError as e:
            assert e
Example #4
0
    def test_create(self):

        # null tensor test
        a = dc.array(0)
        assert a.isnull() == True
        assert a.empty() == True

        # test assignment is shallow copy of memory
        b = a
        assert a.sameas(b) == True
        assert a.identifier() == b.identifier()

        # tensor without initiliaztion
        a = dc.array(2, 3, 4, 5)
        assert a.length() == 120

        # tensor random initiliaztion
        a = dc.random(2, 3, 4, 5)
        assert a.length() == 120

        # tensor without initiliaztion
        a = dc.empty(2, 3, 4, 5)
        assert a.length() == 120

        # zero tensor
        a = dc.zeros(2, 3, 4, 5)
        assert np.array(list(a.data())).sum().astype(np.int) == 0

        # one tensor
        a = dc.ones(2, 3, 4, 5)
        assert np.array(list(a.data())).sum().astype(np.int) == 120

        # tensor from python list
        l1D = [1, 3, 5]
        a = dc.array(l1D).astype('int')
        np.testing.assert_equal(np.array(l1D), np.array(list(a.data())))

        # tensor from python list of lists
        l2D = [[1, 3, 5], [2, 4, 6]]
        a = dc.array(l2D).astype('int')
        assert a.rank() == 2
        assert a.shape() == (2, 3)
        np.testing.assert_equal(np.array(l2D).flatten(), \
                np.array(list(a.data())))

        # copy tensor
        b = a.copy()
        assert a.sameas(b) == False
        assert a.identifier() != b.identifier()

        # arange
        a = dc.arange(10)
        assert a.length() == 10

        # add start and step
        a = dc.arange(10, 5, 3).astype('int')
        assert a.data() == (5, 8)

        # swap start and stop.
        a = dc.arange(5, 10, 3).astype('int')
        assert a.data() == (5, 8)
Example #5
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);
#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)


def test_multiply(a,b):
    c = dc.multiply(a, b)
    #print(c)


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