EExponQuay
Workflows

Coding workflows · Stable log-sum-exp aggregation

03
Built around your work

A concrete starting point

Aggregate up to 1000 log-values from minus 1e300 through 1e300 by shifting their maximum before exponentiation. Check empty input, repeated large values and very negative values, returning negative infinity only for empty input and rejecting Boolean, non-finite or out-of-range items.

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.

Stable log-sum-exp aggregation

A concrete starting point
from math import exp, fsum, log, inf

def log_sum_exp(values):
    if type(values) not in (list, tuple) or len(values) > 1000:
        raise ValueError("values.container")
    values = tuple(values)
    if len(values) > 1000 or any(
        type(v) not in (int, float) or not -1e300 <= v <= 1e300 for v in values
    ):
        raise ValueError("values.range")
    if not values:
        return -inf
    peak = max(values)
    return peak + log(fsum(exp(v - peak) for v in values))

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 ↗