Guess the shape of the output of the expression.
(
self,
)
| 444 | return nrowsinbuf |
| 445 | |
| 446 | def _guess_shape( |
| 447 | self, |
| 448 | ) -> tuple[list[tuple[int, int]], int] | tuple[tuple, None]: |
| 449 | """Guess the shape of the output of the expression.""" |
| 450 | # First, compute the maximum dimension of inputs and maindim |
| 451 | # (if it exists) |
| 452 | maxndim = 0 |
| 453 | maindims = [] |
| 454 | for val in self.values: |
| 455 | # Get the minimum of the lengths |
| 456 | if len(val.shape) > maxndim: |
| 457 | maxndim = len(val.shape) |
| 458 | if hasattr(val, "maindim"): |
| 459 | maindims.append(val.maindim) |
| 460 | if maxndim == 0: |
| 461 | self._single_row_out = out = self._compiled_expr(*self.values) |
| 462 | return (), None |
| 463 | if maindims and [maindims[0]] * len(maindims) == maindims: |
| 464 | # If all maindims detected are the same, use this as maindim |
| 465 | maindim = maindims[0] |
| 466 | else: |
| 467 | # If not, the main dimension will be the default one |
| 468 | maindim = 0 |
| 469 | |
| 470 | # The slices parameter for inputs |
| 471 | slices = (slice(None),) * maindim + (0,) |
| 472 | |
| 473 | # Now, collect the values in first row of arrays with maximum dims |
| 474 | vals = [] |
| 475 | lens = [] |
| 476 | for val in self.values: |
| 477 | shape = val.shape |
| 478 | # Warning: don't use len(val) below or it will raise an |
| 479 | # `Overflow` error on 32-bit platforms for large enough arrays. |
| 480 | if shape != () and shape[maindim] == 0: |
| 481 | vals.append(val[:]) |
| 482 | lens.append(0) |
| 483 | elif len(shape) < maxndim: |
| 484 | vals.append(val) |
| 485 | else: |
| 486 | vals.append(val.__getitem__(slices)) |
| 487 | lens.append(shape[maindim]) |
| 488 | minlen = min(lens) |
| 489 | self._single_row_out = out = self._compiled_expr(*vals) |
| 490 | shape = list(out.shape) |
| 491 | if minlen > 0: |
| 492 | shape.insert(maindim, minlen) |
| 493 | return shape, maindim |
| 494 | |
| 495 | def _get_info( |
| 496 | self, shape: list[int], maindim: int | None, itermode: bool = False |
no test coverage detected