Caffe2 - Python API
A deep learning, cross platform ML framework
utils.py
1 from torch._six import container_abcs
2 from itertools import repeat
3 
4 
5 def _ntuple(n):
6  def parse(x):
7  if isinstance(x, container_abcs.Iterable):
8  return x
9  return tuple(repeat(x, n))
10  return parse
11 
12 _single = _ntuple(1)
13 _pair = _ntuple(2)
14 _triple = _ntuple(3)
15 _quadruple = _ntuple(4)
16 
17 
18 def _list_with_default(out_size, defaults):
19  if isinstance(out_size, int):
20  return out_size
21  if len(defaults) <= len(out_size):
22  raise ValueError('Input dimension should be at least {}'.format(len(out_size) + 1))
23  return [v if v is not None else d for v, d in zip(out_size, defaults[-len(out_size):])]