dotnet / TorchSharp

A .NET library that provides access to the library that powers PyTorch.
MIT License
1.34k stars 173 forks source link

Ranges implementation #1266

Open Sprinzl opened 5 months ago

Sprinzl commented 5 months ago

Hello, Hope this not an error with my code... So I really like to use ranges. Lets assume tensor of 3 dimensions. I can do x[some tensor] .... I can do x[x<=2] .... I can do x[..int,..,..] ..... What I cannot do is x[..,some tensor,..] ... where some tensor are indices or booleans. Is where any way to implement this. Would be really cool because this often appears in pythonic code...

Thanks

shaltielshmid commented 5 months ago

Implicit casting could be a cool feature, for now you can work around it by doing:

var indexed = x[..,TensorIndex.Tensor(some_tensor),..];
yueyinqiu commented 3 months ago

@shaltielshmid So are we facing any problems when implementing the implicit cast (since nobody did it before)?

shaltielshmid commented 3 months ago

I haven't gotten up to it yet, but feel free to go ahead :)