File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import ninetoothed
2+
3+
4+ def arrangement (* tensors , dim , block_size = None ):
5+ if block_size is None :
6+ block_size = ninetoothed .block_size ()
7+
8+ ndim = max (tensor .ndim for tensor in tensors )
9+
10+ assert all (tensor .ndim == ndim or tensor .ndim == 0 for tensor in tensors )
11+
12+ inner_block_shape = tuple (1 if i != dim else block_size for i in range (ndim ))
13+ outer_block_shape = tuple (1 if i != dim else - 1 for i in range (ndim ))
14+
15+ non_target_dims = tuple (i for i in range (ndim ) if i != dim )
16+
17+ def _arrange (tensor ):
18+ arranged = tensor .tile (inner_block_shape )
19+ arranged = arranged .tile (outer_block_shape )
20+ arranged .dtype = arranged .dtype .squeeze (non_target_dims )
21+ arranged .dtype .dtype = arranged .dtype .dtype .squeeze (non_target_dims )
22+
23+ return arranged
24+
25+ return tuple (_arrange (tensor ) if tensor .ndim != 0 else tensor for tensor in tensors )
You can’t perform that action at this time.
0 commit comments