diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt index 493d90d2f..1ed0414de 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt @@ -6,55 +6,55 @@ package space.kscience.kmath.operations /** - * Returns the sum of all elements in the iterable in this [Ring]. + * Returns the sum of all elements in the iterable in this [Group]. * * @receiver the algebra that provides addition. * @param data the iterable to sum up. * @return the sum. */ -public fun Ring.sum(data: Iterable): T = data.fold(zero) { left, right -> +public fun Group.sum(data: Iterable): T = data.fold(zero) { left, right -> add(left, right) } //TODO replace by sumOf with multi-receivers /** - * Returns the sum of all elements in the sequence in this [Ring]. + * Returns the sum of all elements in the sequence in this [Group]. * * @receiver the algebra that provides addition. * @param data the sequence to sum up. * @return the sum. */ -public fun Ring.sum(data: Sequence): T = data.fold(zero) { left, right -> +public fun Group.sum(data: Sequence): T = data.fold(zero) { left, right -> add(left, right) } /** - * Returns an average value of elements in the iterable in this [Ring]. + * Returns an average value of elements in the iterable in this [Group]. * * @receiver the algebra that provides addition and division. * @param data the iterable to find average. * @return the average value. * @author Iaroslav Postovalov */ -public fun S.average(data: Iterable): T where S : Ring, S : ScaleOperations = +public fun S.average(data: Iterable): T where S : Group, S : ScaleOperations = sum(data) / data.count() /** - * Returns an average value of elements in the sequence in this [Ring]. + * Returns an average value of elements in the sequence in this [Group]. * * @receiver the algebra that provides addition and division. * @param data the sequence to find average. * @return the average value. * @author Iaroslav Postovalov */ -public fun S.average(data: Sequence): T where S : Ring, S : ScaleOperations = +public fun S.average(data: Sequence): T where S : Group, S : ScaleOperations = sum(data) / data.count() /** * Absolute of the comparable [value] */ -public fun > Ring.abs(value: T): T = if (value > zero) value else -value +public fun > Group.abs(value: T): T = if (value > zero) value else -value /** * Returns the sum of all elements in the iterable in provided space. @@ -63,7 +63,7 @@ public fun > Ring.abs(value: T): T = if (value > zero) valu * @param group the algebra that provides addition. * @return the sum. */ -public fun Iterable.sumWith(group: Ring): T = group.sum(this) +public fun Iterable.sumWith(group: Group): T = group.sum(this) /** * Returns the sum of all elements in the sequence in provided space. @@ -72,27 +72,27 @@ public fun Iterable.sumWith(group: Ring): T = group.sum(this) * @param group the algebra that provides addition. * @return the sum. */ -public fun Sequence.sumWith(group: Ring): T = group.sum(this) +public fun Sequence.sumWith(group: Group): T = group.sum(this) /** - * Returns an average value of elements in the iterable in this [Ring]. + * Returns an average value of elements in the iterable in this [Group]. * * @receiver the iterable to find average. * @param space the algebra that provides addition and division. * @return the average value. * @author Iaroslav Postovalov */ -public fun Iterable.averageWith(space: S): T where S : Ring, S : ScaleOperations = +public fun Iterable.averageWith(space: S): T where S : Group, S : ScaleOperations = space.average(this) /** - * Returns an average value of elements in the sequence in this [Ring]. + * Returns an average value of elements in the sequence in this [Group]. * * @receiver the sequence to find average. * @param space the algebra that provides addition and division. * @return the average value. * @author Iaroslav Postovalov */ -public fun Sequence.averageWith(space: S): T where S : Ring, S : ScaleOperations = +public fun Sequence.averageWith(space: S): T where S : Group, S : ScaleOperations = space.average(this)