sum¶
- sum(array: PolyArray[_Dim], axis: None = None) Poly¶
- sum(array: PolyArray[_Dim], axis: int | tuple[int, ...]) Poly | PolyArray[Dim]
- sum(arg: Sequence[Poly | float] | Iterator[Poly | float]) Poly
- sum(
- arg: Sequence[Constraint | ConstraintList] | Iterator[Constraint | ConstraintList],
- sum(stop: int, func: Callable[[int], Poly]) Poly
- sum(start: int, stop: int, func: Callable[[int], Poly]) Poly
- sum(start: int, stop: int, step: int, func: Callable[[int], Poly]) Poly
- sum(sequence: Sequence[_T], func: Callable[[_T], Poly]) Poly
- sum(iterable: Iterable[_T], func: Callable[[_T], Poly]) Poly
- sum(iterator: Iterator[_T], func: Callable[[_T], Poly]) Poly
- sum(iterable: Iterable, /, start: object = 0) Any
Sum elements of a polynomial array, sequence, or iterator. Sum a sequence or iterator efficiently. Sum a sequence or iterator of constraints. Deprecated overload of
sum(). Map each element and sum the mapped values.When the argument is a
PolyArray, this function is equivalent to thesum()method ofPolyArray. IfaxisisNone, all elements are summed and aPolyis returned. Ifaxisis specified, reduction is applied along that axis and aPolyArrayorPolyis returned depending on the result shape.When the argument elements are
Poly,Constraint, orConstraintList, this function behaves like Python's built-insum()but uses an algorithm that reduces intermediate growth during accumulation. In this context, built-insum()can show \(O(n^2)\)-like behavior, while this function is typically closer to \(O(n)\). Here, \(n\) denotes the total number of terms in aPolyor the total number of elements in aConstraintList.The overload that takes
start,stop,funchas been deprecated since Amplify v1.0.0 and will be removed in a future release. Useamplify.sum(iterable, func)instead.If a sequence (iterable or iterator) and a function are provided, this function maps each element to a polynomial and sums the mapped polynomials.
Overload 1.
- Args:
array (amplify.PolyArray[_Dim]): Array, sequence, or iterator whose elements the function adds.
axis (None): Axis or axes to reduce. If
None, sum all elements. Defaults toNone.
- Returns:
amplify.Poly: Summed polynomial or polynomial array.
- Raises:
ValueError: If
axisis out of bounds or invalid.
Overload 2.
- Args:
array (amplify.PolyArray[_Dim]): Array, sequence, or iterator whose elements the function adds.
axis (int | tuple[int, ...]): Axis or axes to reduce. If
None, sum all elements.
- Returns:
amplify.Poly | amplify.PolyArray[Dim]: Summed polynomial or polynomial array.
- Raises:
ValueError: If
axisis out of bounds or invalid.
Overload 3.
- Args:
arg (collections.abc.Sequence[amplify.Poly | float] | collections.abc.Iterator[amplify.Poly | float]): Input sequence or iterator to sum.
- Returns:
amplify.Poly: Summed result.
Overload 4.
- Args:
arg (collections.abc.Sequence[amplify.Constraint | amplify.ConstraintList] | collections.abc.Iterator[amplify.Constraint | amplify.ConstraintList]): Input sequence or iterator to sum.
- Returns:
amplify.ConstraintList: Sum of all elements.
Overload 5.
- Args:
stop (int)
func (collections.abc.Callable[[int], amplify.Poly])
- Returns:
amplify.Poly:
Overload 6.
- Args:
start (int)
stop (int)
func (collections.abc.Callable[[int], amplify.Poly])
- Returns:
amplify.Poly:
Overload 7.
- Args:
start (int)
stop (int)
step (int)
func (collections.abc.Callable[[int], amplify.Poly])
- Returns:
amplify.Poly:
Overload 8.
- Args:
sequence (collections.abc.Sequence[_T]): Sequence or iterator of elements to map and sum.
func (collections.abc.Callable[[_T], Poly]): Mapping function applied to each element.
- Returns:
amplify.Poly: Sum of mapped elements.
Overload 9.
- Args:
iterable (collections.abc.Iterable[_T]): Sequence or iterator of elements to map and sum.
func (collections.abc.Callable[[_T], Poly]): Mapping function applied to each element.
- Returns:
amplify.Poly: Sum of mapped elements.
Overload 10.
- Args:
iterator (collections.abc.Iterator[_T]): Sequence or iterator of elements to map and sum.
func (collections.abc.Callable[[_T], Poly]): Mapping function applied to each element.
- Returns:
amplify.Poly: Sum of mapped elements.
Overload 11.
- Args:
iterable (Iterable)
start (object): Defaults to
0.
- Returns:
typing.Any: