Container

class ivy.Container(dict_in=None)[source]

Bases: dict

__init__(dict_in=None)[source]

Initialize container object from input dict representation.

at_key_chain(key_chain)[source]

Query container object at a specified key-chain

Returns

sub-container or value at specified key chain

static concat(containers, dim)[source]

Concatenate containers together along the specified dimension.

Parameters
  • containers (sequence of Container objects) – containers to concatenate

  • dim (int) – dimension along which to concatenate

Returns

Concatenated containers

copy()[source]

Create a copy of this container.

Returns

A copy of the container

dtype()[source]

Return container, with all entries replaced with their data types.

Returns

New datatype container

expand_dims(axis)[source]

Expand dims of all sub-arrays of container object.

Parameters

axis (int) – Axis along which to expand dimensions of the sub-arrays.

Returns

Container object at with all sub-array dimensions expanded along the axis.

static from_disk(h5_obj_or_filepath, slice_obj=slice(None, None, None))[source]

Load container object from disk, as an h5py file, at the specified filepath.

Parameters
  • h5_obj_or_filepath (str or h5 obj) – Filepath where the container object is saved to disk, or h5 object.

  • slice_obj (slice or sequence of slices) – slice object to slice all h5 elements.

Returns

Container loaded from disk

static h5_file_size(h5_obj_or_filepath)[source]

Get file size of h5 file contents.

Parameters

h5_obj_or_filepath (str or h5 obj) – Filepath where the container object is saved to disk, or h5 object.

Returns

Size of h5 file contents, and batch size.

static list_join(containers)[source]

Join containers of lists together along the specified dimension.

Parameters

containers (sequence of Container objects) – containers to list join

Returns

List joined containers, with each entry being a list of arrays

static list_stack(containers, dim)[source]

List stack containers together along the specified dimension.

Parameters
  • containers (sequence of Container objects) – containers to list stack

  • dim (int) – dimension along which to list stack

Returns

Stacked containers, with each entry being a list of arrays

map(func, key_chain='')[source]

Apply function to all array values of container

Parameters
  • func (python function) – Function to apply to each container entry

  • key_chain (str) – Chain of keys for this dict entry

prune_empty()[source]

Recursively prunes empty keys from the container dict structure. Returns None if the entire container is empty.

Returns

Container with empty keys pruned.

prune_key_chain(key_chain)[source]

Recursively prune chain of keys, specified as ‘key1/key2/key3/…’

Returns

Container with keys in key chain pruned.

shuffle(seed_value=None)[source]

Shuffle entries in all sub-arrays, such that they are still aligned along axis 0.

Parameters

seed_value (int) – random seed to use for array shuffling

static shuffle_h5_file(h5_obj_or_filepath, seed_value=0)[source]

Shuffle entries in all datasets of h5 file, such that they are still aligned along axis 0.

Parameters
  • h5_obj_or_filepath (str or h5 obj) – Filepath where the container object is saved to disk, or h5 object.

  • seed_value (int) – random seed to use for array shuffling

property size
slice(slice_obj)[source]

Get slice of container object.

Parameters

slice_obj (slice or sequence of slices) – slice object to slice all container elements.

Returns

Container object at desired slice.

to_dict()[source]

Return nested pure dict representation of container object.

Returns

Container as nested dict.

to_disk(h5_obj_or_filepath, starting_index=0, mode='a', max_batch_size=None)[source]

Save container object to disk, as an h5py file, at the specified filepath.

Parameters
  • h5_obj_or_filepath (str or h5 object) – Filepath for where to save the container to disk, or h5 object.

  • starting_index (int) – Batch index for which to start writing to file, if it already exists

  • mode (str) – H5 read/write mode for writing to disk, [‘r’, ‘r+’, ‘w’, ‘w-‘, ‘a’], default is ‘a’.

  • max_batch_size (int) – Maximum batch size for the container on disk, this is useful if later appending to file.

to_flat_list()[source]

Return flat list representation of container object.

Returns

Container as flat list.

to_iterator()[source]

Return iterator for traversing through the nested elements of container object.

Returns

Iterator for the container elements.

to_list()[source]

Return nested list representation of container object.

Returns

Container as nested list.

to_random()[source]

Return new container, with all entries having same shape and type, but random values

unstack(dim, dim_size)[source]

Unstack containers along specified dimension.

Parameters
  • dim (int) – Dimensions along which to unstack.

  • dim_size (int) – Size of the dimension to unstack.

Returns

List of containers, unstacked along the specified dimension.

with_entries_as_lists()[source]

Return container object, with each array entry in the container cast to a list


Supported Frameworks:

empty jax_logo empty tf_logo empty pytorch_logo empty mxnet_logo empty numpy_logo empty