burn_rl/transition_buffer/
slice_access.rs1use burn_core::prelude::*;
2
3pub trait SliceAccess<B: Backend>: Clone + Sized {
12 fn zeros_like(sample: &Self, capacity: usize, device: &B::Device) -> Self;
15
16 fn select(self, dim: usize, indices: Tensor<B, 1, Int>) -> Self;
18
19 fn slice_assign_inplace(&mut self, index: usize, value: Self);
21}
22
23impl<B: Backend> SliceAccess<B> for Tensor<B, 2> {
24 fn zeros_like(sample: &Self, capacity: usize, device: &B::Device) -> Self {
25 let feature_dim = sample.dims()[1];
26 Tensor::zeros([capacity, feature_dim], device)
27 }
28
29 fn select(self, dim: usize, indices: Tensor<B, 1, Int>) -> Self {
30 Tensor::select(self, dim, indices)
31 }
32
33 fn slice_assign_inplace(&mut self, index: usize, value: Self) {
34 self.inplace(|t| t.slice_assign(index..index + 1, value));
35 }
36}