Make Tensor::Move() forward quantization parameters.

PiperOrigin-RevId: 509951145
This commit is contained in:
MediaPipe Team 2023-02-15 15:38:11 -08:00 committed by Copybara-Service
parent 796a96d842
commit 3d4ed305bc
2 changed files with 7 additions and 1 deletions

View File

@ -399,6 +399,7 @@ void Tensor::Move(Tensor* src) {
valid_ = src->valid_; valid_ = src->valid_;
src->valid_ = kValidNone; src->valid_ = kValidNone;
shape_ = src->shape(); shape_ = src->shape();
quantization_parameters_ = src->quantization_parameters();
element_type_ = src->element_type(); element_type_ = src->element_type();
src->element_type_ = ElementType::kNone; // Mark as invalidated. src->element_type_ = ElementType::kNone; // Mark as invalidated.
cpu_buffer_ = src->cpu_buffer_; cpu_buffer_ = src->cpu_buffer_;

View File

@ -42,7 +42,8 @@ TEST(Cpu, TestMemoryAllocation) {
} }
TEST(Cpu, TestTensorMove) { TEST(Cpu, TestTensorMove) {
Tensor t1(Tensor::ElementType::kFloat32, Tensor::Shape{4, 3, 2, 3}); Tensor t1(Tensor::ElementType::kFloat32, Tensor::Shape{4, 3, 2, 3},
Tensor::QuantizationParameters(0.5, 127));
void* p1 = t1.GetCpuWriteView().buffer<float>(); void* p1 = t1.GetCpuWriteView().buffer<float>();
EXPECT_NE(p1, nullptr); EXPECT_NE(p1, nullptr);
Tensor t2(std::move(t1)); Tensor t2(std::move(t1));
@ -50,6 +51,10 @@ TEST(Cpu, TestTensorMove) {
EXPECT_EQ(t1.bytes(), 0); // NOLINT EXPECT_EQ(t1.bytes(), 0); // NOLINT
void* p2 = t2.GetCpuWriteView().buffer<float>(); void* p2 = t2.GetCpuWriteView().buffer<float>();
EXPECT_EQ(p1, p2); EXPECT_EQ(p1, p2);
EXPECT_EQ(t1.quantization_parameters().scale,
t2.quantization_parameters().scale);
EXPECT_EQ(t1.quantization_parameters().zero_point,
t2.quantization_parameters().zero_point);
} }
TEST(Cpu, TestViewMove) { TEST(Cpu, TestViewMove) {