mani_skill.utils.common ======================= .. py:module:: mani_skill.utils.common .. autoapi-nested-parse:: Common utilities often reused for internal code and task building for users. Functions --------- .. autoapisummary:: mani_skill.utils.common._batch mani_skill.utils.common._to_numpy mani_skill.utils.common._unbatch mani_skill.utils.common.append_dict_array mani_skill.utils.common.batch mani_skill.utils.common.compute_angle_between mani_skill.utils.common.dict_merge mani_skill.utils.common.flatten_dict_keys mani_skill.utils.common.flatten_state_dict mani_skill.utils.common.index_dict_array mani_skill.utils.common.merge_dicts mani_skill.utils.common.normalize_vector mani_skill.utils.common.np_compute_angle_between mani_skill.utils.common.np_normalize_vector mani_skill.utils.common.quat_diff_rad mani_skill.utils.common.to_cpu_tensor mani_skill.utils.common.to_numpy mani_skill.utils.common.to_tensor mani_skill.utils.common.torch_clone_dict mani_skill.utils.common.unbatch Module Contents --------------- .. py:function:: _batch(array) .. py:function:: _to_numpy(array) .. py:function:: _unbatch(array) .. py:function:: append_dict_array(x1, x2) Append `x2` in front of `x1` and returns the result. Tries to do this in place if possible. Assumes both `x1, x2` have the same dictionary structure if they are dictionaries. They may also both be lists/sequences in which case this is just appending like normal .. py:function:: batch(*args) Adds one dimension in front of everything. If given a dictionary, every leaf in the dictionary has a new dimension. If given a tuple, returns the same tuple with each element batched .. py:function:: compute_angle_between(x1, x2) Compute angle (radian) between two torch tensors .. py:function:: dict_merge(dct, merge_dct) In place recursive merge of `merge_dct` into `dct` .. py:function:: flatten_dict_keys(d, prefix='') Flatten a dict by expanding its keys recursively. .. py:function:: flatten_state_dict(state_dict, use_torch=False, device = None) Flatten a dictionary containing states recursively. Expects all data to be either torch or numpy :param state_dict: a dictionary containing scalars or 1-dim vectors. :param use_torch: Whether to convert the data to torch tensors. :type use_torch: bool :raises AssertionError: If a value of @state_dict is an ndarray with ndim > 2. :returns: flattened states. :rtype: np.ndarray | torch.Tensor .. rubric:: Notes The input is recommended to be ordered (e.g. dict). However, since python 3.7, dictionary order is guaranteed to be insertion order. .. py:function:: index_dict_array(x1, idx, inplace=True) Indexes every array in x1 with slice and returns result. .. py:function:: merge_dicts(ds, asarray=False) Merge multiple dicts with the same keys to a single one. .. py:function:: normalize_vector(x, eps=1e-06) normalizes a given torch tensor x and if the norm is less than eps, set the norm to 0 .. py:function:: np_compute_angle_between(x1, x2) Compute angle (radian) between two numpy arrays .. py:function:: np_normalize_vector(x, eps=1e-06) normalizes a given numpy array x and if the norm is less than eps, set the norm to 0 .. py:function:: quat_diff_rad(a, b) Get the difference in radians between two quaternions. :param a: first quaternion, shape (N, 4) :param b: second quaternion, shape (N, 4) :returns: Difference in radians, shape (N,) .. py:function:: to_cpu_tensor(array) Maps any given sequence to a torch tensor on the CPU. .. py:function:: to_numpy(array, dtype=None) .. py:function:: to_tensor(array, device = None) Maps any given sequence to a torch tensor on the CPU/GPU. If physx gpu is not enabled then we use CPU, otherwise GPU, unless specified by the device argument :param array: The data to map to a tensor :param device: The device to put the tensor on. By default this is None and to_tensor will put the device on the GPU if physx is enabled and CPU otherwise .. py:function:: torch_clone_dict(data) Recursively clones all torch tensors in a dictionary. If the input was a torch tensor, it will return a clone of the tensor. .. py:function:: unbatch(*args)