Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewFunctional only accepts functions with func(torch.Tensor) torch.Tensor type #117

Open
QiJune opened this issue Aug 13, 2020 · 1 comment

Comments

@QiJune
Copy link
Collaborator

QiJune commented Aug 13, 2020

NewFunctional only accepts functions with func(torch.Tensor) torch.Tensor type.

We could write the following codes:

nn.NewFunctional(torch.Tanh)

However, LeakyRelu takes two input parameters.

func LeakyRelu(t Tensor, negativeSlope float64) Tensor {
	return t.LeakyRelu(negativeSlope)
}

We could not write the following codes directly.

nn.NewFunctional(torch.LeakyRelu(0.2))

Maybe we should borrow more features from the functional programming language, like currying in Haskell.

torch.LeakyRelu(0.2) will return a function with func(torch.Tensor) torch.Tensor type. Then, it will work well with NewFunctional.

There is also a project maxsz/curry which provides a way to support currying in Go.

@shendiaomo
Copy link
Collaborator

shendiaomo commented Aug 13, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants