Skip to content

Conversation

@li-roy
Copy link
Contributor

@li-roy li-roy commented Mar 14, 2018

Closes #5601.

@goldsborough
Copy link
Contributor

@pytorchbot retest this please

@li-roy
Copy link
Contributor Author

li-roy commented Mar 15, 2018

@pytorchbot retest this please

namespace at { namespace native {

Tensor bilinear(const Tensor& input1, const Tensor& input2, const Tensor& weight, const Tensor& bias) {
auto b_input1 = input1.unsqueeze(-2).unsqueeze(-2);

This comment was marked as off-topic.

Shape:
- Input: :math:`(N, \text{in1_features})`, :math:`(N, \text{in2_features})`
- Output: :math:`(N, \text{out_features})`
where :math:`*` means any number of additional dimensions. All but the last

This comment was marked as off-topic.

auto b_input2 = input2.unsqueeze(-2).unsqueeze(-1);

auto output = at::matmul(at::matmul(b_input1, weight), b_input2);
output = output.squeeze(-1).squeeze(-2).sum(-1);

This comment was marked as off-topic.


Tensor bilinear(const Tensor& input1, const Tensor& input2, const Tensor& weight, const Tensor& bias) {
if (input1.dim() != input2.dim()) {
throw std::runtime_error("Inputs should have the same number of dimensions");

This comment was marked as off-topic.

}
for (int64_t i = 0; i < input1.dim() - 1; i++) {
if (input1.size(i) != input2.size(i)) {
throw std::runtime_error("Batch dimensions of inputs do not match");

This comment was marked as off-topic.

if (input1.dim() != input2.dim()) {
throw std::runtime_error("Inputs should have the same number of dimensions");
}
AT_ASSERT(input1.dim() == input2.dim(), "bilinear(): input dimensions do not match: got %d and %d",

This comment was marked as off-topic.

throw std::runtime_error("Bias sizes does not match weight size");
AT_ASSERT(input1.size(i) == input2.size(i),
"bilinear(): input batch dimensions do not match at dim %d: got %d and %d",
i, input1.size(i), input2.size(i));

This comment was marked as off-topic.

@li-roy
Copy link
Contributor Author

li-roy commented Mar 17, 2018

@pytorchbot retest this please

Copy link
Contributor

@zou3519 zou3519 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇          🥇 🥇 🥇 🥇    🥇 🥇 🥇       🥇 🥇🥇 🥇 🥇 
🥇          🥇                 🥇          🥇    🥇   🥇 
🥇          🥇     🥇 🥇      🥇           🥇    🥇   🥇 
🥇          🥇        🥇       🥇          🥇    🥇   🥇 
🥇 🥇 🥇    🥇 🥇 🥇 🥇      🥇          🥇    🥇   🥇 

@soumith soumith merged commit 1dcad08 into pytorch:master Mar 17, 2018
@soumith
Copy link
Contributor

soumith commented Mar 17, 2018

I like richard's enthusiasm :D

@li-roy li-roy deleted the bilinear branch April 19, 2018 17:39
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

Successfully merging this pull request may close these issues.

4 participants