Returns the product of all elements in the x tensor.

tch_prod(x, dim = NULL, keepdim = FALSE, dtype = NULL)

Arguments

x

tensor object

dim

the dimension to reduce

keepdim

wether to keep or not the dim

dtype

the desired data type of returned tensor. If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. Default: NULL.

Examples

x <- tch_randn(c(2,2)) tch_prod(x)
#> tensor #> 0.219726 #> [ Variable[CPUFloatType]{} ]
tch_prod(x, 0)
#> tensor #> 1.8724 #> 0.1173 #> [ Variable[CPUFloatType]{2} ]
tch_prod(x, 1, TRUE)
#> tensor #> 2.7288 #> 0.0805 #> [ Variable[CPUFloatType]{2,1} ]
tch_prod(x, 1, TRUE, "double")
#> tensor #> 2.7288 #> 0.0805 #> [ Variable[CPUDoubleType]{2,1} ]