SShapeEstuary
Workflows

Coding workflows · Tensor broadcast shapes

03
Built around your work

A concrete starting point

Infer a shared tensor shape by comparing trailing dimensions and expanding unit axes. Check scalar shapes and zero-sized axes with unit dimensions, rejecting incompatible, negative or fractional dimensions.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Tensor broadcast shapes

A concrete starting point
from itertools import zip_longest

def broadcast_shape(a, b):
    a, b = tuple(a), tuple(b)
    if any(type(d) is not int or d < 0 for d in a + b):
        raise ValueError("dimension.invalid")
    result = []
    for left, right in zip_longest(reversed(a), reversed(b), fillvalue=1):
        if left == right or right == 1:
            result.append(left)
        elif left == 1:
            result.append(right)
        else:
            raise ValueError("shape.incompatible")
    return tuple(reversed(result))

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗