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

Missing prod function torch.prod or a.prod() where a is Tensor #1223

Closed
haytham2597 opened this issue Feb 7, 2024 · 1 comment
Closed

Missing prod function torch.prod or a.prod() where a is Tensor #1223

haytham2597 opened this issue Feb 7, 2024 · 1 comment

Comments

@haytham2597
Copy link

Hi, i notice that in TorchSharp is missing the torch.prod(input, dim, keepdim=False)
Including in THSTensor.cpp missing the prod function but have cumprod or cartesian_prod that is not i need

I created this but performance may be bad and this snippet code miss dim parameter

 public static double Product<T>(this IEnumerator<T> enumer)
 {
     double result=1;
     using (enumer)
         while (enumer.MoveNext())
             if(enumer.Current != null)
                 result *= Convert.ToDouble(enumer.Current);
     return result;
 }
 
 public static double Prod(this torch.Tensor tensor)
 {
     if (tensor.is_floating_point())
     {
         if (tensor.dtype == torch.ScalarType.Float32)
             return tensor.data<float>().GetEnumerator().Product();
         if (tensor.dtype == torch.ScalarType.Float64)
             return tensor.data<double>().GetEnumerator().Product();
     }
     if (tensor.dtype == torch.ScalarType.Int64)
         return tensor.data<long>().GetEnumerator().Product();
     return tensor.data<int>().GetEnumerator().Product();
 }
@haytham2597 haytham2597 changed the title Missing Prod in torch.prod or a.prod() where a is Tensor Missing prod function torch.prod or a.prod() where a is Tensor Feb 7, 2024
@NiklasGustafsson
Copy link
Contributor

@haytham2597 -- thank you for catching that. It's quite the omission. :-)

NiklasGustafsson added a commit to NiklasGustafsson/TorchSharp that referenced this issue Feb 7, 2024
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