Esempio n. 1
0
 def test_copy_deep(self):
     a = rand_tensor((2, 3, 4), inds='abc', tags='t0')
     b = rand_tensor((2, 3, 4), inds='abd', tags='t1')
     tn1 = TensorNetwork((a, b))
     tn2 = tn1.copy(deep=True)
     # check can modify tensor structure
     tn2['t1'].modify(inds=('a', 'b', 'X'))
     assert tn1['t1'] is not tn2['t1']
     assert tn2['t1'].inds == ('a', 'b', 'X')
     assert tn1['t1'].inds == ('a', 'b', 'd')
     # and that data is not the same
     assert tn1['t1'].data is not tn2['t1'].data
     tn2['t1'].data[:] /= 2
     assert_allclose(tn1['t1'].data / 2, tn2['t1'].data)
Esempio n. 2
0
 def test_copy(self):
     a = rand_tensor((2, 3, 4), inds='abc', tags='t0')
     b = rand_tensor((2, 3, 4), inds='abd', tags='t1')
     tn1 = TensorNetwork((a, b))
     tn2 = tn1.copy()
     # check can modify tensor structure
     tn2['t1'].inds = ('a', 'b', 'X')
     assert tn1['t1'] is not tn2['t1']
     assert tn2['t1'].inds == ('a', 'b', 'X')
     assert tn1['t1'].inds == ('a', 'b', 'd')
     # but that data remains the same
     assert tn1['t1'].data is tn2['t1'].data
     tn2['t1'].data /= 2
     assert_allclose(tn1['t1'].data, tn2['t1'].data)