minor bug of transpose?
- Dominant language
- C++
- Stars
- 3.4k
- Forks
- 701
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I experienced the following behaviour of transpose operator:
```
import dynet as dy
mod = dy.Model()
px = mod.add_parameters((128,1))
ix = dy.parameter(px)
ix_mean = dy.mean_dim(ix, {0}, True)
ix_mean_t = dy.transpose(ix_mean)
```
I got the following error:
```
Traceback (most recent call last):
File "", line 1, in
File "_dynet.pyx", line 3124, in _dynet.transpose
File "_dynet.pyx", line 3139, in _dynet.transpose
ValueError: Dimensions passed to transpose (2) must be equal to dimensions in input tensor (1)
```
I understand that ix_mean in this case has dimension (1,1) and transpose should work (though it does nothing).
I think the dim_forward function of transpose operator should be corrected as follows:
```
Dim Transpose::dim_forward(const vector& xs) const {
DYNET_ARG_CHECK(xs.size() == 1, "Bad arguments to Transpose: " << xs);
DYNET_ARG_CHECK(xs[0].nd == dims.size() || xs[0].num_nonone_dims() == 1 || xs[0].nd == 1, "Dimensions passed to transpose (" << dims.size() << ") must be equal to dimensions in input tensor (" << xs[0].nd << ')');
Dim ret(xs[0]);
ret.nd = dims.size();
for(size_t i = 0; i < dims.size(); ++i)
ret.d[i] = xs[0][dims[i]];
return ret;
}
```
How do you think? I will do a PR? Thanks!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.