sum¶
- sum(array: PolyArray[_Dim], axis: Literal[None] = None) Poly¶
- sum(array: PolyArray[Dim1], axis: int | tuple[int]) Poly
- sum(array: PolyArray[Dim2], axis: tuple[int, int]) Poly
- sum(array: PolyArray[Dim2], axis: int | tuple[int]) PolyArray[Dim1]
- sum(array: PolyArray[Dim3], axis: tuple[int, int, int]) Poly
- sum(array: PolyArray[Dim3], axis: tuple[int, int]) PolyArray[Dim1]
- sum(array: PolyArray[Dim3], axis: int | tuple[int]) PolyArray[Dim2]
- sum(array: PolyArray[Dim4], axis: tuple[int, int, int, int]) Poly
- sum(array: PolyArray[Dim4], axis: tuple[int, int, int]) PolyArray[Dim1]
- sum(array: PolyArray[Dim4], axis: tuple[int, int]) PolyArray[Dim2]
- sum(array: PolyArray[Dim4], axis: int | tuple[int]) PolyArray[Dim3]
- sum(array: PolyArray[_Dim], axis: tuple[()]) PolyArray[_Dim]
- 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 sum sum sum sum sum sum sum sum sum sum sum Sum a sequence or iterator efficiently. Sum a sequence or iterator of constraints. Deprecated overload of
sum(). sum sum Map each element and sum the mapped values. sum sum sumWhen 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
axis (typing.Literal[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[Dim1])
axis (int | tuple[int])
- Returns:
amplify.Poly:
Overload 3.
- Args:
array (amplify.PolyArray[Dim2])
axis (tuple[int, int])
- Returns:
amplify.Poly:
Overload 4.
- Args:
array (amplify.PolyArray[Dim2])
axis (int | tuple[int])
- Returns:
amplify.PolyArray[Dim1]:
Overload 5.
- Args:
array (amplify.PolyArray[Dim3])
axis (tuple[int, int, int])
- Returns:
amplify.Poly:
Overload 6.
- Args:
array (amplify.PolyArray[Dim3])
axis (tuple[int, int])
- Returns:
amplify.PolyArray[Dim1]:
Overload 7.
- Args:
array (amplify.PolyArray[Dim3])
axis (int | tuple[int])
- Returns:
amplify.PolyArray[Dim2]:
Overload 8.
- Args:
array (amplify.PolyArray[Dim4])
axis (tuple[int, int, int, int])
- Returns:
amplify.Poly:
Overload 9.
- Args:
array (amplify.PolyArray[Dim4])
axis (tuple[int, int, int])
- Returns:
amplify.PolyArray[Dim1]:
Overload 10.
- Args:
array (amplify.PolyArray[Dim4])
axis (tuple[int, int])
- Returns:
amplify.PolyArray[Dim2]:
Overload 11.
- Args:
array (amplify.PolyArray[Dim4])
axis (int | tuple[int])
- Returns:
amplify.PolyArray[Dim3]:
Overload 12.
- Args:
array (amplify.PolyArray[_Dim])
axis (tuple[()])
- Returns:
amplify.PolyArray[_Dim]:
Overload 13.
- Args:
array (amplify.PolyArray[Dim]): array
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 14.
- 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 15.
- 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 16.
- Args:
stop (int)
func (collections.abc.Callable[[int], amplify.Poly])
- Returns:
amplify.Poly:
Overload 17.
- Args:
start (int)
stop (int)
func (collections.abc.Callable[[int], amplify.Poly])
- Returns:
amplify.Poly:
Overload 18.
- Args:
start (int)
stop (int)
step (int)
func (collections.abc.Callable[[int], amplify.Poly])
- Returns:
amplify.Poly:
Overload 19.
- Args:
sequence (Sequence[_T]): Sequence or iterator of elements to map and sum.
func (Callable[[_T], Poly]): Mapping function applied to each element.
- Returns:
amplify.Poly: Sum of mapped elements.
Overload 20.
- Args:
iterable (Iterable[_T]): Sequence or iterator of elements to map and sum.
func (Callable[[_T], Poly]): Mapping function applied to each element.
- Returns:
amplify.Poly: Sum of mapped elements.
Overload 21.
- Args:
iterator (Iterator[_T]): Sequence or iterator of elements to map and sum.
func (Callable[[_T], Poly]): Mapping function applied to each element.
- Returns:
amplify.Poly: Sum of mapped elements.
Overload 22.
- Args:
iterable (Iterable)
start (object): Defaults to
0.
- Returns:
typing.Any: