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

Method __init__

examples/model_selection/Trails/singa_pkg_code/tensor.py:90–124  ·  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

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