dotnet / TorchSharp

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

Slicing and indexing #166

Closed AndersGarpebring closed 4 years ago

AndersGarpebring commented 4 years ago

I'm looking for a tensor library that can do slicing and indexing. The c++ libtorch can do that very well but I see that it is not included in this package. Would it be possible to add? I tried to do it my self but for some reason the torch::indexing namespace is missing. Is it some old version of libtorch that is used in torchsharp so this namespace is missing?

dsyme commented 4 years ago

We have not needed that namespace yet - indeed I will take a look as it may be of use in DiffSharp (the main library using this package at the moment)

dsyme commented 4 years ago

(DiffSharp implements slicing and indexing but through its own code iteratively reducing to Torch's Squeeze and IndexSelect

https://github.com/DiffSharp/DiffSharp/blob/dev/src/DiffSharp.Backends.Torch/Torch.RawTensor.fs#L98)

dsyme commented 4 years ago

cc @gbaydin

dsyme commented 4 years ago

@AndersGarpebring You're welcome to contribute this support, it would be a great addition

AndersGarpebring commented 4 years ago

@dsyme Thank you for the fast response. I've looked around a bit and it seems like the slicing functionality that I was looking for was introduced in libtorch around version 1.4. Torchsharp is using version 1.1. Are there any plans to update the version used?

gbaydin commented 4 years ago

@dsyme Thank you for the fast response. I've looked around a bit and it seems like the slicing functionality that I was looking for was introduced in libtorch around version 1.4. Torchsharp is using version 1.1. Are there any plans to update the version used?

@AndersGarpebring as far as I know TorchSharp is currently based on libtorch 1.5.0. You can see this in the readme https://github.com/xamarin/TorchSharp/blob/master/README.md and libtorch nuget packages https://www.nuget.org/packages/libtorch-cpu/

AndersGarpebring commented 4 years ago

@gbaydin I downloaded the version from here and then it contains some code I interpreted as version 1.1. And indeed it is missing files that are available in 1.5.

The include path I found was: ...\GitHub\TorchSharp\bin\obj\AnyCPU.Debug\LibTorch.Redist\libtorch-win-shared-with-deps-1.1.0\libtorch\include

AndersGarpebring commented 4 years ago

I found the issue with version 1.1. I had an old fork on my system that I had forgotten about. In the later version the indexing methods are available in libtorch.

dsyme commented 4 years ago

OK, thanks, closing this issue