MCPcopy Create free account
hub / github.com/apache/singa / __init__

Method __init__

python/singa/tensor.py:91–125  ·  view source on GitHub ↗
(self,
                 shape=(),
                 device=None,
                 dtype=float32,
                 data=None,
                 requires_grad=True,
                 stores_grad=False,
                 creator=None,
                 name=None)

Source from the content-addressed store, hash-verified

89 tensor_count = 0
90
91 def __init__(self,
92 shape=(),
93 device=None,
94 dtype=float32,
95 data=None,
96 requires_grad=True,
97 stores_grad=False,
98 creator=None,
99 name=None):
100 if device is None:
101 device = get_default_device()
102 if isinstance(data, np.ndarray):
103 self.data = CTensor(list(data.shape), device, dtype)
104 copy_from_numpy(self.data, data)
105 elif isinstance(data, CTensor):
106 self.data = data
107 assert data.device().id() == device.id(), 'not the same device'
108 else:
109 self.data = CTensor(list(shape), device, dtype)
110
111 self.shape = tuple(self.data.shape())
112 self.device = device
113 self.dtype = self.data.data_type()
114 self.requires_grad = requires_grad
115 self.stores_grad = stores_grad
116 if name is None:
117 self.name = 'Dummy#{}'.format(Tensor.tensor_count)
118 Tensor.tensor_count += 1
119 else:
120 self.name = name
121 if creator is None:
122 from . import autograd
123 self.creator = autograd.Dummy(self, name)
124 else:
125 self.creator = creator
126
127 def __getitem__(self, keys):
128 if type(keys) != tuple:

Callers

nothing calls this directly

Calls 7

get_default_deviceFunction · 0.85
deviceMethod · 0.80
shapeMethod · 0.80
data_typeMethod · 0.80
copy_from_numpyFunction · 0.70
tupleFunction · 0.50
idMethod · 0.45

Tested by

no test coverage detected