Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions runtime/core/exec_aten/testing_util/tensor_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ bool data_is_close(
size_t numel,
double rtol,
double atol) {
ET_CHECK_MSG(
numel == 0 || (a != nullptr && b != nullptr),
"Pointers must not be null when numel > 0: numel %zu, a 0x%p, b 0x%p",
numel,
a,
b);
if (a == b) {
return true;
}
for (size_t i = 0; i < numel; i++) {
const auto ai = a[i];
const auto bi = b[i];
Expand Down
19 changes: 19 additions & 0 deletions runtime/core/exec_aten/testing_util/test/tensor_util_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using namespace ::testing;
using exec_aten::ScalarType;
using exec_aten::Tensor;
using exec_aten::TensorImpl;
using exec_aten::TensorList;
using executorch::runtime::testing::IsCloseTo;
using executorch::runtime::testing::IsDataCloseTo;
Expand Down Expand Up @@ -826,4 +827,22 @@ TEST(TensorUtilTest, TensorStreamBool) {
"ETensor(sizes={2, 2}, dtype=Bool, data={1, 0, 1, 0})");
}

TEST(TensorTest, TestZeroShapeTensorEquality) {
TensorImpl::SizesType sizes[2] = {2, 2};
TensorImpl::StridesType strides[2] = {2, 1};
TensorImpl::DimOrderType dim_order[2] = {0, 1};

TensorImpl t1(ScalarType::Float, 2, sizes, nullptr, dim_order, strides);
TensorImpl t2(ScalarType::Float, 2, sizes, nullptr, dim_order, strides);

ET_EXPECT_DEATH({ EXPECT_TENSOR_EQ(Tensor(&t1), Tensor(&t2)); }, "");

float data[] = {1.0, 2.0, 3.0, 4.0};

t1.set_data(data);
t2.set_data(data);

EXPECT_TENSOR_EQ(Tensor(&t1), Tensor(&t2));
}

#endif // !USE_ATEN_LIB
Loading