Open QiJune opened 4 years ago
This needs more discussion. At the moment we can use a lambda for this purpose:
nn.NewFunctional(
func (in torch.Tensor) torch.Tensor {
return torch.LeakyRelu(in, 0.2)
})
With the help of Go+ lambda syntax sugar, this will be clear to write.
NewFunctional
only accepts functions withfunc(torch.Tensor) torch.Tensor
type.We could write the following codes:
However,
LeakyRelu
takes two input parameters.We could not write the following codes directly.
Maybe we should borrow more features from the functional programming language, like currying in Haskell.
torch.LeakyRelu(0.2)
will return a function withfunc(torch.Tensor) torch.Tensor
type. Then, it will work well withNewFunctional
.There is also a project maxsz/curry which provides a way to support currying in Go.