MCPcopy Create free account
hub / github.com/pytorch/executorch / TensorRepSetList

Class TensorRepSetList

backends/vulkan/utils.py:1218–1259  ·  view source on GitHub ↗

This class is a wrapper around a list of TensorRepSet instances that automatically applies a "broadcasting" mechanism. The broadcasting mechanism allows for a single underlying TensorRepSet to be used for multiple tensors.

Source from the content-addressed store, hash-verified

1216
1217
1218class TensorRepSetList:
1219 """
1220 This class is a wrapper around a list of TensorRepSet instances that automatically
1221 applies a "broadcasting" mechanism. The broadcasting mechanism allows for a single
1222 underlying TensorRepSet to be used for multiple tensors.
1223 """
1224
1225 def __init__(
1226 self,
1227 tensor_repsets: Union[TensorRepSet, List[TensorRepSet]],
1228 ):
1229 self.vals: List[TensorRepSet] = (
1230 tensor_repsets if isinstance(tensor_repsets, list) else [tensor_repsets]
1231 )
1232
1233 def __len__(self):
1234 return len(self.vals)
1235
1236 def __getitem__(self, idx: int) -> TensorRepSet:
1237 if idx > 0 and len(self) == 1:
1238 return self.vals[0]
1239 if idx >= len(self.vals):
1240 return set()
1241 return self.vals[idx]
1242
1243 def __setitem__(self, idx: int, val: TensorRepSet) -> None:
1244 if idx > 0 and len(self.vals) == 1:
1245 self.vals[0] = val
1246 else:
1247 self.vals[idx] = val
1248
1249 def __str__(self) -> str:
1250 return f"[{', '.join(str(ts) for ts in self.vals)}]"
1251
1252 def append(self, val: TensorRepSet) -> None:
1253 return self.vals.append(val)
1254
1255 def any_is_empty(self) -> bool:
1256 if len(self.vals) == 0:
1257 return True
1258
1259 return any(tensor_repr.is_empty() for tensor_repr in self.vals)
1260
1261
1262class OpRepSets:

Callers 15

test_setitem_singleMethod · 0.90
test_setitem_multiMethod · 0.90
test_appendMethod · 0.90
test_strMethod · 0.90
_make_unary_opMethod · 0.90
_make_binary_opMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_setitem_singleMethod · 0.72
test_setitem_multiMethod · 0.72
test_appendMethod · 0.72
test_strMethod · 0.72
_make_unary_opMethod · 0.72
_make_binary_opMethod · 0.72