Container#
- class ivy.data_classes.container.container.Container(dict_in=None, queues=None, queue_load_sizes=None, container_combine_method='list_join', queue_timeout=None, print_limit=10, key_length_limit=None, print_indent=4, print_line_spacing=0, ivyh=None, default_key_color='green', keyword_color_dict=None, rebuild_child_containers=False, types_to_iteratively_nest=None, alphabetical_keys=True, dynamic_backend=None, **kwargs)[source]#
Bases:
_ContainerWithActivations
,_ContainerWithConversions
,_ContainerWithCreation
,_ContainerWithDataTypes
,_ContainerWithDevice
,_ContainerWithElementwise
,_ContainerWithGeneral
,_ContainerWithGradients
,_ContainerWithImage
,_ContainerWithLayers
,_ContainerWithLinearAlgebra
,_ContainerWithLosses
,_ContainerWithManipulation
,_ContainerWithNorms
,_ContainerWithRandom
,_ContainerWithSearching
,_ContainerWithSet
,_ContainerWithSorting
,_ContainerWithStatistical
,_ContainerWithUtility
,_ContainerWithActivationExperimental
,_ContainerWithConversionExperimental
,_ContainerWithCreationExperimental
,_ContainerWithData_typeExperimental
,_ContainerWithDeviceExperimental
,_ContainerWithElementWiseExperimental
,_ContainerWithGeneralExperimental
,_ContainerWithGradientsExperimental
,_ContainerWithImageExperimental
,_ContainerWithLayersExperimental
,_ContainerWithLinearAlgebraExperimental
,_ContainerWithManipulationExperimental
,_ContainerWithNormsExperimental
,_ContainerWithRandomExperimental
,_ContainerWithSearchingExperimental
,_ContainerWithSetExperimental
,_ContainerWithSortingExperimental
,_ContainerWithStatisticalExperimental
,_ContainerWithUtilityExperimental
- __abs__()[source]#
ivy.Container special method for the abs operator, calling
operator.abs
for each of the corresponding leaves of the two containers.- Parameters:
self – input Container. Should have leaves with numeric data type.
- Returns:
ret – A container containing the element-wise results.
Examples
With
ivy.Container
instances:>>> x = ivy.Container(a=ivy.array([1, -2, 3]), ... b=ivy.array([-1, 0, 5])) >>> y = abs(x) >>> print(y) { a: ivy.array([1, 2, 3]), b: ivy.array([1, 0, 5]) }
- __add__(other)[source]#
ivy.Container special method for the add operator, calling
operator.add
for each of the corresponding leaves of the two containers.- Parameters:
self – first input container. Should have a numeric data type.
other – second input array or container. Must be compatible with
self
(see broadcasting). Should have a numeric data type.
- Returns:
ret – a container containing the element-wise sums. The returned array must have a data type determined by type-promotion.
Examples
With
Number
instances at the leaves:>>> x = ivy.Container(a=1, b=2) >>> y = ivy.Container(a=3, b=4) >>> z = x + y >>> print(z) { a: 4, b: 6 }
With
ivy.Array
instances at the leaves:>>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([5, 6, 7])) >>> z = x + y >>> print(z) { a: ivy.array([5, 7, 9]), b: ivy.array([7, 9, 11]) }
With a mix of
ivy.Container
andivy.Array
instances:>>> x = ivy.Container(a=ivy.array([[4.], [5.], [6.]]), ... b=ivy.array([[5.], [6.], [7.]])) >>> y = ivy.array([[1.1, 2.3, -3.6]]) >>> z = x + y >>> print(z) { a: ivy.array([[5.1, 6.3, 0.4], [6.1, 7.3, 1.4], [7.1, 8.3, 2.4]]), b: ivy.array([[6.1, 7.3, 1.4], [7.1, 8.3, 2.4], [8.1, 9.3, 3.4]]) }
- __eq__(other)[source]#
ivy.Container special method for the equal operator, calling
operator.eq
for each of the corresponding leaves of the two containers.- Parameters:
self – first input Container. May have any data type.
other – second input Container. Must be compatible with x1 (with Broadcasting). May have any data type.
- Returns:
ret – A container containing the element-wise results. Any returned array inside must have a data type of bool.
Examples
With
ivy.Container
instances:>>> x1 = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([1, 3, 5])) >>> x2 = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([1, 4, 5])) >>> y = x1 == x2 >>> print(y) { a: ivy.array([True, True, True]), b: ivy.array([True, False, True]) }
>>> x1 = ivy.Container(a=ivy.array([1.0, 2.0, 3.0]), ... b=ivy.array([1, 4, 5])) >>> x2 = ivy.Container(a=ivy.array([1, 3, 3.0]), ... b=ivy.array([1.0, 4.0, 5.0])) >>> y = x1 == x2 >>> print(y) { a: ivy.array([True, False, True]), b: ivy.array([True, True, True]) }
>>> x1 = ivy.Container(a=ivy.array([1.0, 2.0, 3.0]), ... b=ivy.array([1, 4, 5])) >>> x2 = ivy.Container(a=ivy.array([1, 2, 3.0]), ... b=ivy.array([1.0, 4.0, 5.0])) >>> y = x1 == x2 >>> print(y) { a: ivy.array([True, True, True]), b: ivy.array([True, True, True]) }
- __ge__(other)[source]#
ivy.Container special method for the greater_equal operator, calling
operator.ge
for each of the corresponding leaves of the two containers.- Parameters:
self – first input Container. May have any data type.
other – second input Container. Must be compatible with x1 (with Broadcasting). May have any data type.
- Returns:
ret – A container containing the element-wise results. Any returned array inside must have a data type of bool.
Examples
With
ivy.Container
instances:>>> x = ivy.Container(a=ivy.array([4, 5, 6]),b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 5, 3]),b=ivy.array([5, 3, 7])) >>> z = x >= y >>> print(z) { a:ivy.array([True,True,True]), b:ivy.array([False,True,False]) }
- __gt__(other)[source]#
ivy.Container special method for the greater operator, calling
operator.gt
for each of the corresponding leaves of the two containers.- Parameters:
self – first input Container. May have any data type.
other – second input Container. Must be compatible with x1 (with Broadcasting). May have any data type.
- Returns:
ret – A container containing the element-wise results. Any returned array inside must have a data type of bool.
Examples
With
ivy.Container
instances:>>> x = ivy.Container(a=ivy.array([4, 5, 6]),b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 5, 3]),b=ivy.array([5, 3, 7])) >>> z = x > y >>> print(z) { a:ivy.array([True,False,True]), b:ivy.array([False,False,False]) }
- __init__(dict_in=None, queues=None, queue_load_sizes=None, container_combine_method='list_join', queue_timeout=None, print_limit=10, key_length_limit=None, print_indent=4, print_line_spacing=0, ivyh=None, default_key_color='green', keyword_color_dict=None, rebuild_child_containers=False, types_to_iteratively_nest=None, alphabetical_keys=True, dynamic_backend=None, **kwargs)[source]#
Initialize container object from input dict representation.
- Parameters:
dict_in – the dictionary the container should wrap around. Default is
None
.queues – Sequence of multiprocessing queues, each of which returns containers. This enables the current container to be passed around asynchronously while waiting for data. Default is
None
.queue_load_sizes – Size of leading dimension of the containers returned by each queue. Default is
None
.container_combine_method – The method to use for combining containers arriving from different queues. Default is ivy.Container.cont_list_join
queue_timeout – The timeout when waiting for containers to arrive from the queues. Default is global.
print_limit – The total array size limit when printing the container. Default is 10.
key_length_limit – The maximum key length when printing the container. Default is
None
.print_indent – The number of whitespaces to use for indenting when printing the container. Default is 4.
print_line_spacing – The number of extra newlines to use between keys when printing the container. Default is
0
.ivyh – Handle to ivy module to use for the calculations. Default is
None
, which results in the global ivy.default_key_color – The default key color for printing the container to the terminal. Default is ‘green’.
keyword_color_dict – A dict mapping keywords to their termcolor color codes for printing the container. (Default value = None)
rebuild_child_containers – Whether to rebuild container found in dict_in with these constructor params. Default is
False
, in which case the original container are kept as are.types_to_iteratively_nest – The data types to nest iteratively in the dict structure, each type must be iterable. Default is
None
.alphabetical_keys – Whether to sort the container keys alphabetically, or preserve the dict order. Default is
True
.kwargs – keyword arguments for dict creation. Default is
None
.
- __le__(other)[source]#
ivy.Container special method for the less_equal operator, calling
operator.le
for each of the corresponding leaves of the two containers.- Parameters:
self – first input Container. May have any data type.
other – second input Container. Must be compatible with x1 (with Broadcasting). May have any data type.
- Returns:
ret – A container containing the element-wise results. Any returned array inside must have a data type of bool.
Examples
With
ivy.Container
instances:>>> x = ivy.Container(a=ivy.array([4, 5, 6]),b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 5, 3]),b=ivy.array([5, 3, 7])) >>> z = x <= y >>> print(z) { a: ivy.array([False, True, False]), b: ivy.array([True, True, True]) }
- __lt__(other)[source]#
ivy.Container special method for the less operator, calling
operator.lt
for each of the corresponding leaves of the two containers.- Parameters:
self – first input Container. May have any data type.
other – second input Container. Must be compatible with x1 (with Broadcasting). May have any data type.
- Returns:
ret – A container containing the element-wise results. Any returned array inside must have a data type of bool.
Examples
With
ivy.Container
instances:>>> x = ivy.Container(a=ivy.array([4, 5, 6]),b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 5, 3]),b=ivy.array([5, 3, 7])) >>> z = x < y >>> print(z) { a: ivy.array([False, False, False]), b: ivy.array([True, False, True]) }
- __ne__(other)[source]#
ivy.Container special method for the not_equal operator, calling
operator.ne
for each of the corresponding leaves of the two containers.- Parameters:
self – first input Container. May have any data type.
other – second input Container. Must be compatible with x1 (with Broadcasting). May have any data type.
- Returns:
ret – A container containing the element-wise results. Any returned array inside must have a data type of bool.
Examples
With
ivy.Container
instances:>>> x1 = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([1, 3, 5])) >>> x2 = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([1, 4, 5])) >>> y = x1 != x2 >>> print(y) { a: ivy.array([False, False, False]), b: ivy.array([False, True, False]) }
>>> x1 = ivy.Container(a=ivy.array([1.0, 2.0, 3.0]), ... b=ivy.array([1, 4, 5])) >>> x2 = ivy.Container(a=ivy.array([1, 3, 3.0]), ... b=ivy.array([1.0, 4.0, 5.0])) >>> y = x1 != x2 >>> print(y) { a: ivy.array([False, True, False]), b: ivy.array([False, False, False]) }
>>> x1 = ivy.Container(a=ivy.array([1.0, 2.0, 3.0]), ... b=ivy.array([1, 4, 5])) >>> x2 = ivy.Container(a=ivy.array([1, 2, 3.0]), ... b=ivy.array([1.0, 4.0, 5.0])) >>> y = x1 != x2 >>> print(y) { a: ivy.array([False, False, False]), b: ivy.array([False, False, False]) }
- __pow__(power)[source]#
ivy.Container special method for the power operator, calling
operator.pow
for each of the corresponding leaves of the two containers.- Parameters:
self – input container. Should have a numeric data type.
power – input array or container of powers. Must be compatible with
self
(see broadcasting). Should have a numeric data type.
- Returns:
ret – a container containing the element-wise sums. The returned array must have a data type determined by type-promotion.
Examples
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0, 1]), b=ivy.array([2, 3])) >>> y = x ** 2 >>> print(y) { a: ivy.array([0, 1]), b: ivy.array([4, 9]) } >>> x = ivy.Container(a=ivy.array([0, 1.2]), b=ivy.array([2.2, 3.])) >>> y = x ** 3.1 >>> print(y) { a: ivy.array([0., 1.75979435]), b: ivy.array([11.52153397, 30.13532257]) }
- __radd__(other)[source]#
ivy.Container reverse special method for the add operator, calling
operator.add
for each of the corresponding leaves of the two containers.- Parameters:
self – first input container. Should have a numeric data type.
other – second input array or container. Must be compatible with
self
(see broadcasting). Should have a numeric data type.
- Returns:
ret – a container containing the element-wise sums. The returned array must have a data type determined by type-promotion.
Examples
>>> x = 1 >>> y = ivy.Container(a=3, b=4) >>> z = x + y >>> print(z) { a: 4, b: 5 }
- __rrshift__(other)[source]#
ivy.Container reverse special method for the right shift operator, calling
operator.rshift
for each of the corresponding leaves of the two containers.- Parameters:
self – first input container. Should have an integer data type.
other – second input array or container. Must be compatible with
self
(see broadcasting). Should have an integer data type. Each element must be greater than or equal to0
.
- Returns:
ret – a container containing the element-wise results. The returned array must have a data type determined by type-promotion.
Examples
>>> a = 64 >>> b = ivy.Container(a = ivy.array([0, 1, 2]), ... b = ivy.array([3, 4, 5])) >>> y = a >> b >>> print(y) { a: ivy.array([64, 32, 16]), b: ivy.array([8, 4, 2]) }
- __rshift__(other)[source]#
ivy.Container special method for the right shift operator, calling
operator.rshift
for each of the corresponding leaves of the two containers.- Parameters:
self – first input container. Should have an integer data type.
other – second input array or container. Must be compatible with
self
(see broadcasting). Should have an integer data type. Each element must be greater than or equal to0
.
- Returns:
ret – a container containing the element-wise results. The returned array must have a data type determined by type-promotion.
Examples
With
Number
instances at the leaves:>>> x = ivy.Container(a=128, b=43) >>> y = ivy.Container(a=5, b=3) >>> z = x >> y >>> print(z) { a: 4, b: 5 }
With
ivy.Array
instances at the leaves:>>> x = ivy.Container(a=ivy.array([16, 40, 120]), ... b=ivy.array([15, 45, 143])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([0, 3, 4])) >>> z = x >> y >>> print(z) { a: ivy.array([8, 10, 15]), b: ivy.array([15, 5, 8]) }
With a mix of
ivy.Container
andivy.Array
instances:>>> x = ivy.Container(a=ivy.array([16, 40, 120]), ... b=ivy.array([15, 45, 143])) >>> y = ivy.array([1, 2, 3]) >>> z = x >> y >>> print(z) { a: ivy.array([8, 10, 15]), b: ivy.array([7, 11, 17]) }
- __rsub__(other)[source]#
ivy.Container reverse special method for the subtract operator, calling
operator.sub
for each of the corresponding leaves of the two containers.- Parameters:
self – first input container. Should have a numeric data type.
other – second input array or container. Must be compatible with
self
(see broadcasting). Should have a numeric data type.
- Returns:
ret – a container containing the element-wise differences. The returned array must have a data type determined by type-promotion.
Examples
>>> x = 1 >>> y = ivy.Container(a=3, b=4) >>> z = x - y >>> print(z) { a: -2, b: -3 }
- __sub__(other)[source]#
ivy.Container special method for the subtract operator, calling
operator.sub
for each of the corresponding leaves of the two containers.- Parameters:
self – first input container. Should have a numeric data type.
other – second input array or container. Must be compatible with
self
(see broadcasting). Should have a numeric data type.
- Returns:
ret – a container containing the element-wise differences. The returned array must have a data type determined by type-promotion.
Examples
With
Number
instances at the leaves:>>> x = ivy.Container(a=1, b=2) >>> y = ivy.Container(a=3, b=4) >>> z = x - y >>> print(z) { a: -2, b: -2 }
With
ivy.Array
instances at the leaves:>>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([4, 3, 2])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([6, 5, 4])) >>> z = x - y >>> print(z) { a: ivy.array([-3, -3, -3]), b: ivy.array([-2, -2, -2]) }
With a mix of
ivy.Container
andivy.Array
instances:>>> x = ivy.Container(a=ivy.array([[4.], [5.], [6.]]), ... b=ivy.array([[5.], [6.], [7.]])) >>> y = ivy.array([[1.1, 2.3, -3.6]]) >>> z = x - y >>> print(z) { a: ivy.array([[2.9, 1.7, 7.6], [3.9, 2.7, 8.6], [4.9, 3.7, 9.6]]), b: ivy.array([[3.9, 2.7, 8.6], [4.9, 3.7, 9.6], [5.9, 4.7, 10.6]]) }
- __truediv__(other)[source]#
ivy.Container special method for the divide operator, calling
operator.truediv
for each of the corresponding leaves of the two containers.- Parameters:
self – first input container. Should have a numeric data type.
other – second input array or container. Must be compatible with
self
(see broadcasting). Should have a numeric data type.
- Returns:
ret – a container containing the element-wise differences. The returned array must have a data type determined by type-promotion.
Examples
With
Number
instances at the leaves:>>> x = ivy.Container(a=1, b=2) >>> y = ivy.Container(a=5, b=4) >>> z = x / y >>> print(z) { a: 0.2, b: 0.5 }
With
ivy.Array
instances at the leaves:>>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([4, 3, 2])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([6, 5, 4])) >>> z = x / y >>> print(z) { a: ivy.array([0.25, 0.40000001, 0.5]), b: ivy.array([0.66666669, 0.60000002, 0.5]) }
- __xor__(other)[source]#
ivy.Container special method for the ge operator, calling
operator.ge
for each of the corresponding leaves of the two containers.- Parameters:
self – first input Container.
other – second input Container. Arrays inside must be compatible with
x1
(see broadcasting). Should have an integer or boolean data type.
- Returns:
ret – a container containing the element-wise results. Any returned arrays inside must have a data type determined by type-promotion.
Examples
With
ivy.Container
instances:>>> x = ivy.Container(a=ivy.array([89]), b=ivy.array([2])) >>> y = ivy.Container(a=ivy.array([12]), b=ivy.array([3])) >>> z = x ^ y >>> print(z) { a: ivy.array([85]), b: ivy.array([1]) }
This should have hopefully given you an overview of the container submodule, if you have any questions, please feel free to reach out on our discord in the container channel or in the container forum!