}
bool Tensor::SharesBufferWith(const Tensor& b) const {
- CHECK_NE(nullptr, buf_);
- CHECK_NE(nullptr, b.buf_);
- return buf_->root_buffer() == b.buf_->root_buffer();
+ return buf_ != nullptr && b.buf_ != nullptr &&
+ buf_->root_buffer() == b.buf_->root_buffer();
}
string Tensor::DebugString() const {
void DeallocateRaw(void* ptr) override {}
};
+TEST(Tensor, SharesBufferWith) {
+ Tensor a_empty;
+ Tensor b_empty;
+ Tensor a(DT_FLOAT, TensorShape({1}));
+ Tensor b(DT_FLOAT, TensorShape({1}));
+ Tensor copy(a);
+ EXPECT_FALSE(a_empty.SharesBufferWith(a_empty));
+ EXPECT_FALSE(a_empty.SharesBufferWith(b_empty));
+ EXPECT_FALSE(a_empty.SharesBufferWith(a));
+ EXPECT_FALSE(a_empty.SharesBufferWith(copy));
+ EXPECT_TRUE(a.SharesBufferWith(a));
+ EXPECT_FALSE(a.SharesBufferWith(b));
+ EXPECT_TRUE(a.SharesBufferWith(copy));
+}
+
TEST(Tensor, FailureToAllocate) {
TensorShape shape({1});
DummyCPUAllocator allocator;