dantro.mixins.numeric module

This module implements mixin classes which provide numeric interfaces for containers

class dantro.mixins.numeric.UnaryOperationsMixin[source]

Bases: object

This Mixin class implements the methods needed for unary operations.

It leaves out those that expect that return values are of a certain type, e.g. __complex__, __int__, …

__neg__()[source]

Make negative

Returns

A new object with negative elements

__pos__()[source]

Make positive

Returns

A new object with negative elements

__abs__()[source]

Absolute value

Returns

A new object with the absolute value of the elements

__invert__()[source]

Inverse value

Returns

A new object with the inverted values of the elements

__round__()[source]

Rounds number to nearest integer

Returns

A new object as rounded number to nearest integer

__ceil__()[source]

Smallest integer

Returns

A new object containing the smallest integer

__floor__()[source]

Largest integer

Returns

A new object containing the largest element

__trunc__()[source]

Truncated to the nearest integer toward 0

Returns

A new object containing the truncated element

class dantro.mixins.numeric.NumbersMixin[source]

Bases: dantro.mixins.numeric.UnaryOperationsMixin

This mixin implements the methods needed for calculating with numbers.

__add__(other)[source]

Add two objects

Returns

A new object containing the summed data

__sub__(other)[source]

Subtract two objects

Returns

A new object containing the subtracted data

__mul__(other)[source]

Multiply two objects

Returns

A object containing the multiplied data

__truediv__(other)[source]

Divide two objects

Returns

A new object containing the divided data

__floordiv__(other)[source]

Floor divide two objects

Returns

A new object containing the floor divided data

__mod__(other)[source]

Calculate the modulo of two objects

Returns

A new object containing the summed data

__divmod__(other)[source]

Calculate the floor division and modulo of two objects

Returns

A new object containing the floor divided data and its modulo

__pow__(other)[source]

Calculate the self data to the power of other data

Returns

A new object containing the result

__iadd__(other)[source]

Add two objects

Returns

Self with modified data

__isub__(other)[source]

Subtract two objects

Returns

Self with modified data

__imul__(other)[source]

Multiply two objects

Returns

Self with modified data

__itruediv__(other)[source]

Divide two objects

Returns

Self with modified data

__ifloordiv__(other)[source]

Floor divide two objects

Returns

Self with modified data

__imod__(other)[source]

Calculate the modulo of two objects

Returns

Self with modified data

__ipow__(other)[source]

Calculate the self data to the power of other data

Returns

Self with modified data

__abs__()

Absolute value

Returns

A new object with the absolute value of the elements

__ceil__()

Smallest integer

Returns

A new object containing the smallest integer

__floor__()

Largest integer

Returns

A new object containing the largest element

__invert__()

Inverse value

Returns

A new object with the inverted values of the elements

__neg__()

Make negative

Returns

A new object with negative elements

__pos__()

Make positive

Returns

A new object with negative elements

__round__()

Rounds number to nearest integer

Returns

A new object as rounded number to nearest integer

__trunc__()

Truncated to the nearest integer toward 0

Returns

A new object containing the truncated element

class dantro.mixins.numeric.ComparisonMixin[source]

Bases: object

This Mixin implements functions to compare objects

__eq__(other)[source]

Equality

__ne__(other)[source]

Inequality

__lt__(other)[source]

Less than

__le__(other)[source]

Less than or equal

__gt__(other)[source]

Greater than

__ge__(other)[source]

Greater than or equal

__bool__()[source]

Truth value

dantro.mixins.numeric.get_data(obj)[source]

Get the data of obj depending on whether it is part of dantro or not.

Parameters

obj – The object to check

Returns

Either the .data attribute of a dantro-based object or otherwise the

object itself.

dantro.mixins.numeric.apply_func_to_copy(obj, func, other=None)[source]

Apply a given function to a copy for all datatypes

Returns

An object with the data on which the function was applied

dantro.mixins.numeric.apply_func_inplace(obj, func, other=None)[source]

Apply a given function inplace for all datatypes

Returns

An object with the data on which the function was applied