Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: range access of 3-d Tensor. #152

Closed
0h-n0 opened this issue Feb 6, 2020 · 1 comment
Closed

Bug: range access of 3-d Tensor. #152

0h-n0 opened this issue Feb 6, 2020 · 1 comment

Comments

@0h-n0
Copy link

0h-n0 commented Feb 6, 2020

Hi, thank you for developing a wonderful crate.
I found a bug in range access to 3 dimension tensor. The following code is minimal reproduce code. When I access the tensor with index, i can get a correct answer. However, when I access the tensor with range, the first item is completely wrong.

extern crate tch;                                                                                                                          
                                                                                                                                           
use tch::IndexOp;                                                                                                                          
                                                                                                                                           
fn main() {                                                                                                                                
    let x: Vec<i64> = (0..24).collect();                                                                                                   
    println!("{:?}", &x);                                                                                                                  
    let x = tch::Tensor::of_slice(&x).view((2, 3, 4));                                                                                     
    println!("{:?}", x.i((0, 0, 0)));                                                                                                      
    println!("{:?}", x.i((0..2, 0, 0)));                                                                                                   
}   

the result is here,

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]                                                     
[0]                                                                                                                                        
[93848231074208, 16] 
@LaurentMazare
Copy link
Owner

Thanks for reporting this, I just pushed a fix that should hopefully solve this issue.
Interestingly this was caused by a dangling pointer in the C++ layer which is a good argument for using rust rather than C++ as the borrow checker would easily have spotted the problem (commit link in case you're curious).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants