Skip to content

Clarify usage of sum inside macros #4144

@joaquimg

Description

@joaquimg

The sum inside macros does not need the init for empty collections:

julia> @expression(m, sum(2 for i in 1:0))
0.0

julia> sum(2 for i in 1:0)
ERROR: ArgumentError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer

However, AI insists in:

julia> @expression(m, sum(2 for i in 1:0), init = AffExp(0.0))
0.0

We should clarify in macros docs / getting started / performance / good practices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions