Partitions a tensor into pieces of sizes relative to sizes; e.g. a tensor with shape (24, 50, 50, 3) partitioned with partition(sizes = c(0.5, 0.5)) results in a list of two tensors of shape (12, 50, 50, 3).

Ranknames are respected for both inputs and return values.

partition(x, sizes = c(0.5, 0.5))

Arguments

x

the tidytensor to apply over.

sizes

relative sizes of partitions

Value

a list of tidytensors.

Details

Entries in sizes are treated as relative, so sizes = c(2, 1, 1) is equivalent to sizes = c(0.5, 0.25, 0.25). Non-integer parition boundaries are rounded down, and this may result in entries with shape (0, ...), but only when the size of the first rank is smaller than the number of partitions requested.

See also

Examples

# shape [100, 26, 26]
t <- as.tidytensor(array(rnorm(100 * 26 * 26), dim = c(100, 26, 26)))
ranknames(t) <- c("sample", "row", "col")
print(t)
#> # Rank 3 tensor, shape: (100, 26, 26), ranknames: sample, row, col
#> |  # Rank 2 tensor, shape: (26, 26)
#> |        1.56  -0.0928   -0.97   0.353    2.24  -0.632  ... 
#> |       0.999    -1.11   0.601   0.595   0.311   0.637  ... 
#> |       -1.05     1.62  -0.735  -0.824  -0.418   -1.29  ... 
#> |        1.14    0.356   -1.02   0.157  -0.273   -1.14  ... 
#> |       -1.52    0.292   -1.09   0.142    1.24  -0.439  ... 
#> |      -0.909    -1.98    -1.7  -0.998   0.678    1.06  ... 
#> |         ...      ...     ...     ...     ...     ...  ... 
#> |  # ...

partitions <- partition(t, c(0.2, 0.8))
print(partitions)
#> [[1]]
#> # Rank 3 tensor, shape: (20, 26, 26), ranknames: sample, row, col
#> |  # Rank 2 tensor, shape: (26, 26)
#> |        1.56  -0.0928   -0.97   0.353    2.24  -0.632  ... 
#> |       0.999    -1.11   0.601   0.595   0.311   0.637  ... 
#> |       -1.05     1.62  -0.735  -0.824  -0.418   -1.29  ... 
#> |        1.14    0.356   -1.02   0.157  -0.273   -1.14  ... 
#> |       -1.52    0.292   -1.09   0.142    1.24  -0.439  ... 
#> |      -0.909    -1.98    -1.7  -0.998   0.678    1.06  ... 
#> |         ...      ...     ...     ...     ...     ...  ... 
#> |  # ...
#> 
#> [[2]]
#> # Rank 3 tensor, shape: (80, 26, 26), ranknames: sample, row, col
#> |  # Rank 2 tensor, shape: (26, 26)
#> |       -1.28   1.06  0.701  -0.0469  -0.454   0.709  ... 
#> |       -2.22  0.717  0.269   -0.471  -0.631  -0.445  ... 
#> |         1.7  0.634  0.366     1.01  -0.671   0.324  ... 
#> |        1.48  0.376  0.232    0.923   0.719    1.25  ... 
#> |      -0.899  -2.05   1.11     2.34    1.46   0.301  ... 
#> |      -0.566   1.13  0.976   -0.569    2.58   0.767  ... 
#> |         ...    ...    ...      ...     ...     ...  ... 
#> |  # ...
#>