Skip to content

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

Closed

Description

@haytham2597

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();
 }

Activity

  1. 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[/+] on Feb 7, 2024
  2. NiklasGustafsson commented on Feb 7, 2024

    @NiklasGustafsson

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

  3. added a commit that references this issue on Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions