Unstacks the variable without needing an index. Unlike `_unstack_once`, this function requires the existing dimension to contain the full product of the new dimensions.
(self, dim: Mapping[Any, int], old_dim: Hashable)
| 1560 | return result |
| 1561 | |
| 1562 | def _unstack_once_full(self, dim: Mapping[Any, int], old_dim: Hashable) -> Self: |
| 1563 | """ |
| 1564 | Unstacks the variable without needing an index. |
| 1565 | |
| 1566 | Unlike `_unstack_once`, this function requires the existing dimension to |
| 1567 | contain the full product of the new dimensions. |
| 1568 | """ |
| 1569 | new_dim_names = tuple(dim.keys()) |
| 1570 | new_dim_sizes = tuple(dim.values()) |
| 1571 | |
| 1572 | if old_dim not in self.dims: |
| 1573 | raise ValueError(f"invalid existing dimension: {old_dim}") |
| 1574 | |
| 1575 | if set(new_dim_names).intersection(self.dims): |
| 1576 | raise ValueError( |
| 1577 | "cannot create a new dimension with the same " |
| 1578 | "name as an existing dimension" |
| 1579 | ) |
| 1580 | |
| 1581 | if math.prod(new_dim_sizes) != self.sizes[old_dim]: |
| 1582 | raise ValueError( |
| 1583 | "the product of the new dimension sizes must " |
| 1584 | "equal the size of the old dimension" |
| 1585 | ) |
| 1586 | |
| 1587 | other_dims = [d for d in self.dims if d != old_dim] |
| 1588 | dim_order = other_dims + [old_dim] |
| 1589 | reordered = self.transpose(*dim_order) |
| 1590 | |
| 1591 | new_shape = reordered.shape[: len(other_dims)] + new_dim_sizes |
| 1592 | new_data = duck_array_ops.reshape(reordered.data, new_shape) |
| 1593 | new_dims = reordered.dims[: len(other_dims)] + new_dim_names |
| 1594 | |
| 1595 | return type(self)( |
| 1596 | new_dims, new_data, self._attrs, self._encoding, fastpath=True |
| 1597 | ) |
| 1598 | |
| 1599 | def _unstack_once( |
| 1600 | self, |