Speed

Toy Cells vs Captured Cells

Compare the handful of cells drawn in a notebook preview against the full rectangular grid captured inside a tensor.

The problem

A textbook diagram displays a table of four rows and two columns so your eye can scan every entry at once. Real feature matrices keep the same two-dimensional layout, yet neither dimension stays at single digits. Suppose we compare three table shapes [N,D][N, D]: a toy table [4, 2], a small clinic study [50, 12], and a modest sensor log [250, 40].

If a notebook preview window displays at most preview_rows⋅2\mathrm{preview\_rows} \cdot 2 cells, how many feature cells exist in the captured tensor, and how many remain unseen outside that preview box? Answering requires counting all N⋅DN \cdot D rectangular grid entries and clamping unseen counts at 00 whenever the preview window is larger than a tiny table.

Work through the numbers

Multiply row count by column count for each shape. Shape [4, 2] holds 4⋅2=84 \cdot 2 = 8 cells. Shape [50, 12] holds 50⋅12=60050 \cdot 12 = 600 cells. Shape [250, 40] holds 250⋅40=10,000250 \cdot 40 = 10{,}000 cells. Growing rows from 44 to 250250 (62.5×62.5\times) while growing columns from 22 to 4040 (20×20\times) multiplies cell count by 62.5⋅20=1,25062.5 \cdot 20 = 1{,}250, turning 88 numbers into 10,00010{,}000.

Now compare each tensor against a default 4×24 \times 2 preview window of 4⋅2=84 \cdot 2 = 8 cells. For [4, 2], 8−8=08 - 8 = 0 unshown cells: paper shows the entire dataset. For [50, 12], 600−8=592600 - 8 = 592 unshown cells. For [250, 40], 10,000−8=9,99210{,}000 - 8 = 9{,}992 unshown cells, meaning 99.92%99.92\% of the matrix sits outside the printed box.

Check the boundary when the preview window exceeds a tiny table. At preview_rows =10= 10, the 10×210 \times 2 window holds up to 2020 cells. Since 8−20=−128 - 20 = -12 is not a valid count of hidden entries, max⁡(0,N⋅D−2⋅preview_rows)\max(0, N \cdot D - 2 \cdot \mathrm{preview\_rows}) reports [8, 0] for [4, 2], alongside [600, 580] and [10000, 9980].

The live model

Each horizontal bar pair shows total captured cells in blue and unshown cells in amber on a shared scale across the three table shapes. At preview_rows =4= 4, the [250, 40] bar pair reaches [10000, 9992] while the [4, 2] toy table sits near zero at [8, 0]. Drag preview_rows down to 22 to leave 44 unshown cells in [4, 2], or up to 1010 to see [600, 580] and [10000, 9980].

Paired bars for shapes [4, 2], [50, 12], and [250, 40] showing captured vs unshown cells [8, 0], [600, 592], and [10000, 9992] at preview_rows 4.
let preview_rows = scene.parameter("preview_rows", 4.0, 2.0, 10.0, 2.0);
let rows = input.select(1, 0);
let cols = input.select(1, 1);
let total = rows * cols;
let shown = preview_rows * 2.0;
let hidden = (total - shown).clamp(0.0, 1000000000.0);
let cols_out = torch.list().add(total.unsqueeze(1)).add(hidden.unsqueeze(1));
let answer = torch.cat(cols_out, 1);
out.set("captured_and_unshown", answer);
{
  "captured_and_unshown": [
    [
      8,
      0
    ],
    [
      600,
      592
    ],
    [
      10000,
      9992
    ]
  ]
}
Watch the parameter change

Your turn

For each [rows, columns] row in input, answer must return the two-column pair [captured_cells, unshown_cells] against a two-column preview window of height preview_rows. On the visible fixture at preview_rows =4= 4, the expected 3×23 \times 2 result is [[8, 0], [600, 592], [10000, 9992]]. Check varies both table dimensions and preview_rows across unseen inputs, including cases where the preview window holds more cells than the first table.

Starter bars using row-plus-column sums [6, 0], [62, 54], and [290, 282] instead of rectangular cell products.
let preview_rows = scene.parameter("preview_rows", 4.0, 2.0, 10.0, 2.0);
let rows = input.select(1, 0);
let cols = input.select(1, 1);
let total = rows + cols;
let shown = preview_rows * 2.0;
let hidden = (total - shown).clamp(0.0, 1000000000.0);
let cols_out = torch.list().add(total.unsqueeze(1)).add(hidden.unsqueeze(1));
let answer = torch.cat(cols_out, 1);
out.set("captured_and_unshown", answer);
{
  "captured_and_unshown": [
    [
      6,
      0
    ],
    [
      62,
      54
    ],
    [
      290,
      282
    ]
  ]
}

Compute total rectangular grid cells and clamped unshown cells for each [rows, columns] shape instead of adding rows and columns. Check tests larger preview windows and unseen table shapes.

Read the result carefully

Spot-checking the first four rows and two columns confirms column units and catches gross parsing blunders, yet it inspects almost none of a 10,000-cell table. A corrupted sensor value in row 180 or a constant feature in column 31 will never appear in a fixed top-left preview.

That gap explains why tensor reductions such as column mins, column maxes, missing-value sums, and shape assertions replace visual scanning as soon as dimensions leave single digits. Summary statistics inspect every captured cell systematically without printing ten thousand numbers.

Recap

  • An N×DN \times D feature matrix captures N⋅DN \cdot D scalar cells, so scaling both axes multiplies storage rather than adding to it.
  • Unshown cell count equals max⁡(0,N⋅D−preview_cells)\max(0, N \cdot D - \mathrm{preview\_cells}), flooring at 00 when the preview window exceeds the table.
  • Top-left table previews verify layout on a handful of cells but cannot substitute for full-tensor reductions over unseen rows and columns.