libenv/libenv.py
def _check_arrays(
        arrays: Dict[str, np.ndarray], num_envs: int, dict_space: gym.spaces.Dict
    ) -> None:
        """
        Make sure each array in arrays matches the given dict_space
        """
        for name, space in dict_space.spaces.items():
            arr = arrays[name]
            assert isinstance(arr, np.ndarray)
            expected_shape = (num_envs,) + space.shape
            assert (
                arr.shape == expected_shape
            ), f"array is invalid shape expected={expected_shape} received={arr.shape}"
            assert (
                arr.dtype == space.dtype
            ), f"array has invalid dtype expected={space.dtype} received={arr.dtype}"
            if isinstance(space, gym.spaces.Box):
                # we only support single low/high values
                assert (
                    len(np.unique(space.low)) == 1 and len(np.unique(space.high)) == 1
                )
                low = np.min(space.low)
                high = np.max(space.high)
            elif isinstance(space, gym.spaces.Discrete):
                low = 0
                high = space.n - 1
            else:
                assert False, "unrecognized space type"
            assert np.min(arr) >= low, (
                '"%s" has values below space lower bound, %f < %f'
                % (name, np.min(arr), low)
            )
            assert np.max(arr) <= high, (
                '"%s" has values above space upper bound, %f > %f'
                % (name, np.max(arr), high)
            )

        Make sure each array in arrays matches the given dict_space
        
Make sure each array in arrays matches the given dict_space
Make sure each array in arrays matches the given dict_space
def _check_arrays(
        arrays: Dict[str, np.ndarray], num_envs: int, dict_space: gym.spaces.Dict
    ) -> None:
        for name, space in dict_space.spaces.items():
            arr = arrays[name]
            assert isinstance(arr, np.ndarray)
            expected_shape = (num_envs,) + space.shape
            assert (
                arr.shape == expected_shape
            ), f"array is invalid shape expected={expected_shape} received={arr.shape}"
            assert (
                arr.dtype == space.dtype
            ), f"array has invalid dtype expected={space.dtype} received={arr.dtype}"
            if isinstance(space, gym.spaces.Box):
                assert (
                    len(np.unique(space.low)) == 1 and len(np.unique(space.high)) == 1
                )
                low = np.min(space.low)
                high = np.max(space.high)
            elif isinstance(space, gym.spaces.Discrete):
                low = 0
                high = space.n - 1
            else:
                assert False, "unrecognized space type"
            assert np.min(arr) >= low, (
                '"%s" has values below space lower bound, %f < %f'
                % (name, np.min(arr), low)
            )
            assert np.max(arr) <= high, (
                '"%s" has values above space upper bound, %f > %f'
                % (name, np.max(arr), high)
            )
def _check_arrays ( arrays : Dict [ str , np . ndarray ] , num_envs : int , dict_space : gym . spaces . Dict ) -> None : for name , space in dict_space . spaces . items ( ) : arr = arrays [ name ] assert isinstance ( arr , np . ndarray ) expected_shape = ( num_envs , ) + space . shape assert ( arr . shape == expected_shape ) , f"array is invalid shape expected={expected_shape} received={arr.shape}" assert ( arr . dtype == space . dtype ) , f"array has invalid dtype expected={space.dtype} received={arr.dtype}" if isinstance ( space , gym . spaces . Box ) : assert ( len ( np . unique ( space . low ) ) == 1 and len ( np . unique ( space . high ) ) == 1 ) low = np . min ( space . low ) high = np . max ( space . high ) elif isinstance ( space , gym . spaces . Discrete ) : low = 0 high = space . n - 1 else : assert False , "unrecognized space type" assert np . min ( arr ) >= low , ( '"%s" has values below space lower bound, %f < %f' % ( name , np . min ( arr ) , low ) ) assert np . max ( arr ) <= high , ( '"%s" has values above space upper bound, %f > %f' % ( name , np . max ( arr ) , high ) )
Make sure each array in arrays matches the given dict_space
Make sure each array in arrays matches the given dict_space
"""
        Make sure each array in arrays matches the given dict_space
        """ # we only support single low/high values

arrays
Dict[str, np.ndarray]
num_envs
int
dict_space
gym.spaces.Dict