Skip to content

Commit

Permalink
Add defined() to caffe2::Tensor (pytorch#16125)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#16125

Add defined() method to check whether the Tensor is defined.

Reviewed By: ezyang

Differential Revision: D13719222

fbshipit-source-id: ff8efef2159ed1026bd16acaea40c768a1e20a47
  • Loading branch information
jerryzh168 authored and facebook-github-bot committed Jan 18, 2019
1 parent b9b160d commit da578b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions caffe2/core/blob_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,11 @@ TEST(TensorTest, Tensor64BitDimension) {
EXPECT_EQ(tensor.numel(), large_number * 100);
}

TEST(TensorTest, UndefinedTensor) {
Tensor x;
EXPECT_FALSE(x.defined());
}

TEST(TensorDeathTest, CannotCastDownLargeDims) {
int64_t large_number =
static_cast<int64_t>(std::numeric_limits<int>::max()) + 1;
Expand Down
4 changes: 4 additions & 0 deletions caffe2/core/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ class CAFFE2_API Tensor final {
return impl_;
}

bool defined() const {
return impl_;
}

/**
* Returns a const raw void* pointer of the underlying storage. mutable_data()
* or raw_mutable_data() must have been called prior to this function call.
Expand Down

0 comments on commit da578b7

Please sign in to comment.