| 536 | |
| 537 | template <typename T> |
| 538 | void ConstantTailTest(int64 length, int64 tail_length, bool as_field) { |
| 539 | using TensorProtoHelper = tensor::internal::TensorProtoHelper<T>; |
| 540 | using FieldType = typename TensorProtoHelper::FieldType; |
| 541 | const float kMinCompressionRatio = 2.0; |
| 542 | const int64 kMinSize = 64; |
| 543 | TensorProto tensor_proto = |
| 544 | as_field ? CreateAsProtoField<T>(length, tail_length) |
| 545 | : CreateAsProtoTensorContent<T>(length, tail_length); |
| 546 | TensorProto original_tensor_proto = tensor_proto; |
| 547 | int64 original_size = |
| 548 | length * (as_field ? (is_complex<T>::value ? 2 : 1) * sizeof(FieldType) |
| 549 | : sizeof(T)); |
| 550 | int64 size_as_tensor_content = length * sizeof(T); |
| 551 | int64 size_as_field = std::min(length, (length - tail_length + 1)) * |
| 552 | (is_complex<T>::value ? 2 : 1) * sizeof(FieldType); |
| 553 | bool will_compress = std::min(size_as_tensor_content, size_as_field) <= |
| 554 | static_cast<int64>(original_size / kMinCompressionRatio); |
| 555 | |
| 556 | EXPECT_EQ(tensor::CompressTensorProtoInPlace(kMinSize, kMinCompressionRatio, |
| 557 | &tensor_proto), |
| 558 | will_compress); |
| 559 | if (will_compress) { |
| 560 | if (size_as_tensor_content < size_as_field) { |
| 561 | EXPECT_EQ(TensorProtoHelper::NumValues(tensor_proto), 0); |
| 562 | EXPECT_FALSE(tensor_proto.tensor_content().empty()); |
| 563 | } else { |
| 564 | EXPECT_LE(TensorProtoHelper::NumValues(tensor_proto), |
| 565 | (length - tail_length + 1)); |
| 566 | EXPECT_TRUE(tensor_proto.tensor_content().empty()); |
| 567 | } |
| 568 | } |
| 569 | CompareTensorValues<T>(tensor_proto, original_tensor_proto); |
| 570 | } |
| 571 | |
| 572 | TEST(TensorProtoUtil, CompressTensorProtoConstantTail) { |
| 573 | const int kLength = 64; |
nothing calls this directly
no test coverage detected