Skip to content

Commit

Permalink
Resize initializer list overload for thpp::Tensor
Browse files Browse the repository at this point in the history
Summary: Overload thpp::Tensor::resize method with initializer list arguments.

Test Plan:
$ fbconfig fbcode/admarket/adreview/utils/image
$ fbmake --fast opt
$ fbconfig deeplearning/projects/imagenet/
$ fbmake --fast opt
$ fbconfig deeplearning/torch
$ fbmake --fast opt

Reviewed By: [email protected], [email protected]

Subscribers: cpalow, juancarabina, mt-diffs@

FB internal diff: D1655650

Signature: t1:1655650:1415048908:0e3b9058d9c0560e6cb11ddc41359c902b07b879
  • Loading branch information
urikz authored and soumith committed Dec 31, 2014
1 parent e507aac commit c614ba2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions thpp/Tensor-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ void Tensor<T>::squeeze(const Tensor& src, int dim) {
Ops::_squeeze1d(t_, src.mut(), dim);
}

template <class T>
void Tensor<T>::resize(std::initializer_list<long> sizes,
std::initializer_list<long> strides) {
resize(LongStorage(sizes.begin(), sizes.end()),
LongStorage(strides.begin(), strides.end()));
}

template <class T>
void Tensor<T>::resize(LongStorage sizes, LongStorage strides) {
Ops::_resize(t_, sizes.th(), strides.th());
Expand Down
3 changes: 3 additions & 0 deletions thpp/Tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ class Tensor {
void squeeze(const Tensor& src, int dim);
void squeeze(int dim) { squeeze(*this, dim); }

void resize(
std::initializer_list<long> sizes,
std::initializer_list<long> strides = std::initializer_list<long>());
void resize(LongStorage newSizes, LongStorage newStrides = LongStorage());
void resize(LongRange newSizes, LongRange newStrides = LongRange());
void resizeAs(const Tensor& src);
Expand Down

0 comments on commit c614ba2

Please sign in to comment.