libenv/libenv.py
def _get_spaces(self, c_name: Any) -> gym.spaces.Dict:
        """
        Get a c space and convert to a gym space
        """
        count = self._c_lib.libenv_get_spaces(self._c_env, c_name, self._ffi.NULL)
        if count == 0:
            return gym.spaces.Dict([])

        c_spaces = self._ffi.new("struct libenv_space[%d]" % count)
        self._c_lib.libenv_get_spaces(self._c_env, c_name, c_spaces)

        # convert to gym spaces
        spaces = []
        for i in range(count):
            c_space = c_spaces[i]

            name = self._ffi.string(c_space.name).decode("utf8")
            shape = []
            for j in range(c_space.ndim):
                shape.append(c_space.shape[j])

            if c_space.dtype == self._c_lib.LIBENV_DTYPE_UINT8:
                dtype = np.dtype("uint8")
                low = c_space.low.uint8
                high = c_space.high.uint8
            elif c_space.dtype == self._c_lib.LIBENV_DTYPE_INT32:
                dtype = np.dtype("int32")
                low = c_space.low.int32
                high = c_space.high.int32
            elif c_space.dtype == self._c_lib.LIBENV_DTYPE_FLOAT32:
                dtype = np.dtype("float32")
                low = c_space.low.float32
                high = c_space.high.float32
            else:
                assert False, "unknown dtype"

            if c_space.type == self._c_lib.LIBENV_SPACE_TYPE_BOX:
                space = gym.spaces.Box(shape=shape, low=low, high=high, dtype=dtype)
            elif c_space.type == self._c_lib.LIBENV_SPACE_TYPE_DISCRETE:
                assert shape == [1], "discrete space must have scalar shape"
                assert low == 0 and high > 0, "discrete low/high bounds are incorrect"
                space = gym.spaces.Discrete(n=high + 1)
                space.dtype = dtype
            else:
                assert False, "unknown space type"
            spaces.append((name, space))
        # c spaces are aways a single-layer Dict space
        return gym.spaces.Dict(spaces)

        Get a c space and convert to a gym space
        
Get a c space and convert to a gym space
Get a c space and convert to a gym space
def _get_spaces(self, c_name: Any) -> gym.spaces.Dict:
        count = self._c_lib.libenv_get_spaces(self._c_env, c_name, self._ffi.NULL)
        if count == 0:
            return gym.spaces.Dict([])
        c_spaces = self._ffi.new("struct libenv_space[%d]" % count)
        self._c_lib.libenv_get_spaces(self._c_env, c_name, c_spaces)
        spaces = []
        for i in range(count):
            c_space = c_spaces[i]
            name = self._ffi.string(c_space.name).decode("utf8")
            shape = []
            for j in range(c_space.ndim):
                shape.append(c_space.shape[j])
            if c_space.dtype == self._c_lib.LIBENV_DTYPE_UINT8:
                dtype = np.dtype("uint8")
                low = c_space.low.uint8
                high = c_space.high.uint8
            elif c_space.dtype == self._c_lib.LIBENV_DTYPE_INT32:
                dtype = np.dtype("int32")
                low = c_space.low.int32
                high = c_space.high.int32
            elif c_space.dtype == self._c_lib.LIBENV_DTYPE_FLOAT32:
                dtype = np.dtype("float32")
                low = c_space.low.float32
                high = c_space.high.float32
            else:
                assert False, "unknown dtype"
            if c_space.type == self._c_lib.LIBENV_SPACE_TYPE_BOX:
                space = gym.spaces.Box(shape=shape, low=low, high=high, dtype=dtype)
            elif c_space.type == self._c_lib.LIBENV_SPACE_TYPE_DISCRETE:
                assert shape == [1], "discrete space must have scalar shape"
                assert low == 0 and high > 0, "discrete low/high bounds are incorrect"
                space = gym.spaces.Discrete(n=high + 1)
                space.dtype = dtype
            else:
                assert False, "unknown space type"
            spaces.append((name, space))
        return gym.spaces.Dict(spaces)
def _get_spaces ( self , c_name : Any ) -> gym . spaces . Dict : count = self . _c_lib . libenv_get_spaces ( self . _c_env , c_name , self . _ffi . NULL ) if count == 0 : return gym . spaces . Dict ( [ ] ) c_spaces = self . _ffi . new ( "struct libenv_space[%d]" % count ) self . _c_lib . libenv_get_spaces ( self . _c_env , c_name , c_spaces ) spaces = [ ] for i in range ( count ) : c_space = c_spaces [ i ] name = self . _ffi . string ( c_space . name ) . decode ( "utf8" ) shape = [ ] for j in range ( c_space . ndim ) : shape . append ( c_space . shape [ j ] ) if c_space . dtype == self . _c_lib . LIBENV_DTYPE_UINT8 : dtype = np . dtype ( "uint8" ) low = c_space . low . uint8 high = c_space . high . uint8 elif c_space . dtype == self . _c_lib . LIBENV_DTYPE_INT32 : dtype = np . dtype ( "int32" ) low = c_space . low . int32 high = c_space . high . int32 elif c_space . dtype == self . _c_lib . LIBENV_DTYPE_FLOAT32 : dtype = np . dtype ( "float32" ) low = c_space . low . float32 high = c_space . high . float32 else : assert False , "unknown dtype" if c_space . type == self . _c_lib . LIBENV_SPACE_TYPE_BOX : space = gym . spaces . Box ( shape = shape , low = low , high = high , dtype = dtype ) elif c_space . type == self . _c_lib . LIBENV_SPACE_TYPE_DISCRETE : assert shape == [ 1 ] , "discrete space must have scalar shape" assert low == 0 and high > 0 , "discrete low/high bounds are incorrect" space = gym . spaces . Discrete ( n = high + 1 ) space . dtype = dtype else : assert False , "unknown space type" spaces . append ( ( name , space ) ) return gym . spaces . Dict ( spaces )
Get a c space and convert to a gym space
Get a c space and convert to a gym space
"""
        Get a c space and convert to a gym space
        """ # convert to gym spaces
 # c spaces are aways a single-layer Dict space

self
c_name
Any