dotnet / TorchSharp

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

Missing tensor slicing methods #199

Closed gbaydin closed 3 years ago

gbaydin commented 3 years ago

Hi, I've been trying to locate the libtorch tensor indexing/slicing API in TorchSharp: https://pytorch.org/cppdocs/notes/tensor_indexing.html

If I haven't missed it, I think it needs to be added to libtorchsharp native code and to the C# part. This issue is to keep track of this.

The closest available method TorchSharp has is index_select here https://github.com/xamarin/TorchSharp/blob/f456b0d1c162b6b7b4e7947df61fff3fea984d7d/src/Native/LibTorchSharp/THSTensor.cpp#L526 It's possible to use this in combination with other methods to achive various slicings, but it's not ideal due to the number of operations needed to achieve slicing ops that can be done in a single call.

More information about a use case where this is needed is here: https://github.com/DiffSharp/DiffSharp/issues/277

dsyme commented 3 years ago

Yes this needs to be added, thanks!

dsyme commented 3 years ago

This is added, there is now Index and IndexPut