in tt_embeddings_ops.py [0:0]
def _auto_shape(n: int, d: int = 3) -> List[int]:
def _to_list(x: Dict[int, int]) -> List[int]:
res = []
for k, v in x.items():
res += [k] * v
return res
p = _to_list(factorint(n))
if len(p) < d:
p = p + [1] * (d - len(p))
def _roundrobin(*iterables):
pending = len(iterables)
nexts = cycle(iter(it).__next__ for it in iterables)
while pending:
try:
for next in nexts:
yield next()
except StopIteration:
pending -= 1
nexts = cycle(islice(nexts, pending))
def prepr(x: List[int]) -> Tuple:
x = sorted(np.prod(_) for _ in x)
N = len(x)
xf, xl = x[: N // 2], x[N // 2 :]
return tuple(_roundrobin(xf, xl))
raw_factors = multiset_partitions(p, d)
clean_factors = [prepr(f) for f in raw_factors]
factors = list(set(clean_factors))
# pyre-fixme[16]
weights = [entropy(f) for f in factors]
i = np.argmax(weights)
return list(factors[i])