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

torch.repeatTensor() doesn't work with non-contiguous Tensor #59

Closed
Atcold opened this issue Jul 31, 2014 · 5 comments · Fixed by #67
Closed

torch.repeatTensor() doesn't work with non-contiguous Tensor #59

Atcold opened this issue Jul 31, 2014 · 5 comments · Fixed by #67
Labels

Comments

@Atcold
Copy link
Contributor

Atcold commented Jul 31, 2014

Let's sat I have a column from an image which I'd like to replicate horizontally. Only the first two row are computed correctly.

> = l
(1,.,.) = 
  0.6902
  0.6863
  0.6863
  0.6510
  0.6392

(2,.,.) = 
  0.6627
  0.6510
  0.6314
  0.5922
  0.5882

(3,.,.) = 
  0.6157
  0.5922
  0.5882
  0.5765
  0.5725
[torch.DoubleTensor of dimension 3x5x1]

> = l:repeatTensor(1,1,2)
(1,.,.) = 
  0.6902  0.6902
  0.6863  0.6863
  0.6627  0.6627
  0.6588  0.6588
  0.6471  0.6471

(2,.,.) = 
  0.6314  0.6314
  0.6157  0.6157
  0.6000  0.6000
  0.5765  0.5765
  0.5686  0.5686

(3,.,.) = 
  0.5569  0.5569
  0.5451  0.5451
  0.5176  0.5176
  0.5176  0.5176
  0.4980  0.4980
[torch.DoubleTensor of dimension 3x5x2]
@soumith
Copy link
Member

soumith commented Jul 31, 2014

is the matrix here contiguous? Can you post a code snippet to reproduce the issue?

@Atcold
Copy link
Contributor Author

Atcold commented Jul 31, 2014

I cropped the first column of an image, therefore no, data are not contiguous.

require 'image'
lena = image.lena()
lenaColumn = lena[{ {},{1,5},{1} }]
= lenaColumn
= lenaColumn:repeatTensor(1,1,2)

which outputs

(1,.,.) = 
  0.7569
  0.7686
  0.7804
  0.7843
  0.7843

(2,.,.) = 
  0.4353
  0.4471
  0.4510
  0.4549
  0.4549

(3,.,.) = 
  0.2902
  0.3020
  0.3059
  0.3137
  0.3216
[torch.DoubleTensor of dimension 3x5x1]


(1,.,.) = 
  0.7569  0.7569
  0.7765  0.7765
  0.7647  0.7647
  0.7647  0.7647
  0.7843  0.7843

(2,.,.) = 
  0.7882  0.7882
  0.7804  0.7804
  0.7922  0.7922
  0.7725  0.7725
  0.7765  0.7765

(3,.,.) = 
  0.7686  0.7686
  0.7529  0.7529
  0.7529  0.7529
  0.7569  0.7569
  0.7451  0.7451
[torch.DoubleTensor of dimension 3x5x2]

@nicholas-leonard
Copy link
Member

Yeah its definitely a problem of contiguity. When the input is contiguous, repeatTensor works.
Maybe we should just as an assert(tensor:isContiguous()) for now. Also, while we are in this function, we should probably allow passing a result tensor as is the case for most methods (allows for reusing memory).

@Atcold Atcold changed the title torch.repeatTensor() doesn't work with matrixes torch.repeatTensor() doesn't work with non-contiguous Tensor Jul 31, 2014
@soumith soumith added the bug label Aug 1, 2014
@soumith soumith reopened this Oct 17, 2014
@soumith
Copy link
Member

soumith commented Oct 17, 2014

closed via c19c892

@soumith soumith closed this as completed Oct 17, 2014
@Atcold
Copy link
Contributor Author

Atcold commented Oct 17, 2014

Thank you!

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

Successfully merging a pull request may close this issue.

3 participants