8000 Missing `prod` function `torch.prod` or `a.prod()` where a is Tensor · Issue #1223 · dotnet/TorchSharp · GitHub
[go: up one dir, main page]

Skip to content
Missing prod function torch.prod or a.prod() where a is Tensor #1223
@haytham2597

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

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

      0