-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
136 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::{backend::Backend, BasicOps, Tensor, TensorKind}; | ||
|
||
pub(crate) fn repeat_with_slice_assign< | ||
B: Backend, | ||
const D: usize, | ||
K: TensorKind<B> + BasicOps<B>, | ||
>( | ||
tensor: Tensor<B, D, K>, | ||
dim: usize, | ||
times: usize, | ||
) -> Tensor<B, D, K> { | ||
let mut shape = tensor.shape(); | ||
let device = tensor.device(); | ||
|
||
let original_dim_length = shape.dims[dim]; | ||
shape.dims[dim] *= times; | ||
|
||
let mut tensor_output = Tensor::empty(shape.clone(), &device); | ||
|
||
let mut i = 0; | ||
let indices_select_all = [0; D].map(|_| { | ||
i += 1; | ||
0..shape.dims[i - 1] | ||
}); | ||
|
||
let mut output_index = 0; | ||
for _ in 0..times { | ||
let mut indices = indices_select_all.clone(); | ||
indices[dim] = output_index..output_index + original_dim_length; | ||
output_index += original_dim_length; | ||
|
||
tensor_output = tensor_output.slice_assign(indices, tensor.clone()); | ||
} | ||
|
||
tensor_output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters