-
Notifications
You must be signed in to change notification settings - Fork 204
Closed
Description
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
Labels
No labels