TorchSharp icon indicating copy to clipboard operation
TorchSharp copied to clipboard

Request to add `torch.histogramdd` (multi-dimensional histogram) in TorchSharp

Open ncguilbeault opened this issue 11 months ago • 0 comments

Overview

Hello and thank you for all the work that goes into TorchSharp — it has been a very useful tool for us!

I recently needed to compute an N-D histogram from a Tensor object. In PyTorch, this is provided by torch.histogramdd (introduced in 1.11 and still present in the latest 2.7): https://pytorch.org/docs/stable/generated/torch.histogramdd.html

In TorchSharp, the method signature was added 2 years ago but remains as only a stub which throws a NotImplementedException: https://github.com/dotnet/TorchSharp/blob/75eab9ff095de96454d6dbf053e6429acdd6bb84/src/TorchSharp/Tensor/torch.OtherOperations.cs#L468

Why is it useful?

Building N-D histograms from tensor data is quite powerful. For instance, this is useful for calculating occupancy grids over multiple dimensions, computing information loss, color image histograms, etc. Currently, to do this with TorchSharp requires work-arounds using other libraries or manual implementation. It could also benefit from running on the same hardware and minimizing unnecessary CPU-GPU transfers.

Feasibility

The native function already ships with LibTorch (ATen/ops/histogramdd.h), so perhaps only the C++/CLI binding and C# wrapper is needed? If possible, it would be great to have this added into an upcoming release.

If it's any help, I'm happy to take a first pass at a PR for this. Please let me know if there are design constraints or coding conventions I should follow before I start.

ncguilbeault avatar May 15 '25 21:05 ncguilbeault