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

Method __getitem__

examples/model_selection/Trails/singa_pkg_code/tensor.py:126–156  ·  view source on GitHub ↗
(self, keys)

Source from the content-addressed store, hash-verified

124 self.creator = creator
125
126 def __getitem__(self, keys):
127 if type(keys) != tuple:
128 keys = (keys,)
129
130 ret = self.clone()
131 axis_index = 0
132 for key in keys:
133 if type(key) == int:
134 key += self.shape[axis_index] if key < 0 else 0
135
136 if not (key >= 0 and key < self.shape[axis_index]):
137 raise ValueError("Invalid Index")
138
139 ret.data = singa.SliceOn(ret.data, key, key + 1, axis_index)
140 elif type(key) == slice:
141 start = key.start if key.start else 0
142 end = key.stop if key.stop else self.shape[axis_index]
143
144 start += self.shape[axis_index] if start < 0 else 0
145 end += self.shape[axis_index] if end < 0 else 0
146
147 if not (start >= 0 and start < end and
148 end <= self.shape[axis_index]):
149 raise ValueError("Invalid Index")
150
151 ret.data = singa.SliceOn(ret.data, start, end, axis_index)
152 else:
153 raise ValueError("Invalid Index")
154 axis_index += 1
155
156 return ret
157
158 def is_dummy(self):
159 ''&#x27;

Callers

nothing calls this directly

Calls 2

cloneMethod · 0.95
typeFunction · 0.85

Tested by

no test coverage detected