surrogate.cpp

本文通过C++实现了一个简单的代理模式案例,展示了如何通过代理类间接操作实际对象,以达到解耦合的目的。代码中包括Vehicle基类及其派生类VehicleSurrogate和Automobile的具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

刚刚看完"C++沉思录" "Ruminations on C++"第5章,按照代理的思想,把代码放在这儿,以便以后查看

 

 

 

/home/ubuntu/miniforge3/envs/isaac/lib/python3.8/site-packages/torch/functional.py:507: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3549.) return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined] Traceback (most recent call last): File "legged_gym/scripts/train.py", line 18, in <module> train(args) File "legged_gym/scripts/train.py", line 14, in train ppo_runner.learn(num_learning_iterations=train_cfg.runner.max_iterations, init_at_random_ep_len=train_cfg.runner.init_at_random_ep_len) File "/home/ubuntu/ws/HoST/rsl_rl/rsl_rl/runners/on_policy_runner.py", line 135, in learn mean_value_loss, mean_surrogate_loss = self.alg.update() File "/home/ubuntu/ws/HoST/rsl_rl/rsl_rl/algorithms/ppo.py", line 190, in update value_smooth_loss = torch.square(torch.norm(value_batch - self.actor_critic.evaluate(mix_obs_batch), dim=-1)).mean() File "/home/ubuntu/ws/HoST/rsl_rl/rsl_rl/modules/actor_critic.py", line 133, in evaluate values = torch.concat([critic(critic_observations) for critic in self.critics], dim=-1) File "/home/ubuntu/ws/HoST/rsl_rl/rsl_rl/modules/actor_critic.py", line 133, in <listcomp> values = torch.concat([critic(critic_observations) for critic in self.critics], dim=-1) File "/home/ubuntu/miniforge3/envs/isaac/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/ubuntu/miniforge3/envs/isaac/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(*args, **kwargs) File "/home/ubuntu/miniforge3/envs/isaac/lib/python3.8/site-packages/torch/nn/modules/container.py", line 217, in forward input = module(input) File "/home/ubuntu/miniforge3/envs/isaac/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/ubuntu/miniforge3/envs/isaac/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(*args, **kwargs) File "/home/ubuntu/miniforge3/envs/isaac/lib/python3.8/site-packages/torch/nn/modules/activation.py", line 514, in forward return F.elu(input, self.alpha, self.inplace) File "/home/ubuntu/miniforge3/envs/isaac/lib/python3.8/site-packages/torch/nn/functional.py", line 1564, in elu result = torch._C._nn.elu(input, alpha) torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 98.00 MiB. GPU 0 has a total capacity of 7.74 GiB of which 27.81 MiB is free. Process 1771 has 94.00 MiB memory in use. Including non-PyTorch memory, this process has 7.22 GiB memory in use. Of the allocated memory 2.64 GiB is allocated by PyTorch, and 24.85 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)
06-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值