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

Method __getitem__

python/singa/tensor.py:127–157  ·  view source on GitHub ↗
(self, keys)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

cloneMethod · 0.95
typeFunction · 0.85

Tested by

no test coverage detected