torch / torch7

http://torch.ch
Other
8.99k stars 2.38k forks source link

Suggestion: torch.Tensor:copy(tensor, [resizeAs]) #112

Open nicholas-leonard opened 9 years ago

nicholas-leonard commented 9 years ago

Basically, we could substitute a:copyAs(b) for a:resizeAs(b):copy(b).

soumith commented 9 years ago

it is not clear with copyAs as to what the "As" is doing. i would not think that copyAs means resizeAs + copy.

nicholas-leonard commented 9 years ago

Yeah but it is shorter than a:copyResizeAs(b).

We could also just modify the existing copy interface to include a [resizeAs] flag that default to false. So then we would have a very elegant : a:copy(b, true).

I know its a small fix. Its just that the a:resizeAs(b):copy(b) pattern is so common. Its also kind of counter-intuitive since most other methods a:add(b,c), a:cmul(b,c), etc. automatically resize the result tensor. Although I do understand the necessity of requiring an explicit resize before a copy.