|
11 | 11 | #include <gtest/gtest.h>
|
12 | 12 |
|
13 | 13 | #include <executorch/runtime/platform/runtime.h>
|
| 14 | +#include <executorch/test/utils/DeathTest.h> |
14 | 15 |
|
15 | 16 | using namespace ::executorch::extension;
|
16 | 17 | using namespace ::executorch::runtime;
|
@@ -113,6 +114,31 @@ TEST_F(TensorPtrMakerTest, CreateTensorUsingFromBlobWithStrides) {
|
113 | 114 | EXPECT_EQ(tensor->const_data_ptr<float>()[0], 3);
|
114 | 115 | }
|
115 | 116 |
|
| 117 | +TEST_F(TensorPtrMakerTest, CreateTensorUsingFromBlobWithLegalStrides) { |
| 118 | + float data[20] = {3}; |
| 119 | + auto tensor = from_blob(data, {1, 2, 2}, {10, 2, 1}); |
| 120 | + |
| 121 | + EXPECT_EQ(tensor->dim(), 3); |
| 122 | + EXPECT_EQ(tensor->size(0), 1); |
| 123 | + EXPECT_EQ(tensor->size(1), 2); |
| 124 | + EXPECT_EQ(tensor->size(2), 2); |
| 125 | + |
| 126 | + // recalculated stride[0]t o 2 to meet ET's requirement while maintain the |
| 127 | + // same behavior as original tensor since size[0] == 1 |
| 128 | + EXPECT_EQ(tensor->strides()[0], 4); |
| 129 | + EXPECT_EQ(tensor->strides()[1], 2); |
| 130 | + EXPECT_EQ(tensor->strides()[2], 1); |
| 131 | + EXPECT_EQ(tensor->const_data_ptr<float>(), data); |
| 132 | + EXPECT_EQ(tensor->const_data_ptr<float>()[0], 3); |
| 133 | +} |
| 134 | + |
| 135 | +TEST_F(TensorPtrMakerTest, FailedCreateTensorUsingFromBlobWithIllegalStrides) { |
| 136 | + float data[20] = {3}; |
| 137 | + ET_EXPECT_DEATH( |
| 138 | + from_blob(data, {2, 2, 2}, {10, 2, 1}), |
| 139 | + "invalid strides for dim 0: 10!= 4 while its size is 2 != 1"); |
| 140 | +} |
| 141 | + |
116 | 142 | TEST_F(TensorPtrMakerTest, TensorMakerConversionOperator) {
|
117 | 143 | float data[20] = {2};
|
118 | 144 | TensorPtr tensor =
|
|
0 commit comments