Internal change

PiperOrigin-RevId: 477585110
This commit is contained in:
MediaPipe Team
2022-09-28 16:47:33 -07:00
committed by Copybara-Service
parent 8c8a9cda5a
commit dcc5587483
4 changed files with 180 additions and 1 deletions
+12 -1
View File
@@ -90,7 +90,16 @@ class Tensor {
public:
// No resources are allocated here.
enum class ElementType { kNone, kFloat16, kFloat32, kUInt8, kInt8, kInt32 };
enum class ElementType {
kNone,
kFloat16,
kFloat32,
kUInt8,
kInt8,
kInt32,
// TODO: Update the inference runner to handle kTfLiteString.
kChar
};
struct Shape {
Shape() = default;
Shape(std::initializer_list<int> dimensions) : dims(dimensions) {}
@@ -319,6 +328,8 @@ class Tensor {
return 1;
case ElementType::kInt32:
return sizeof(int32_t);
case ElementType::kChar:
return sizeof(char);
}
}
int bytes() const { return shape_.num_elements() * element_size(); }
@@ -1,5 +1,8 @@
#include "mediapipe/framework/formats/tensor.h"
#include <cstring>
#include <string>
#include "mediapipe/framework/port/gmock.h"
#include "mediapipe/framework/port/gtest.h"
#if !MEDIAPIPE_DISABLE_GPU
@@ -23,6 +26,9 @@ TEST(General, TestDataTypes) {
Tensor t2(Tensor::ElementType::kFloat16, Tensor::Shape{4, 3, 2, 3});
EXPECT_EQ(t2.bytes(), t2.shape().num_elements() * 2);
Tensor t_char(Tensor::ElementType::kChar, Tensor::Shape{4});
EXPECT_EQ(t_char.bytes(), t_char.shape().num_elements() * sizeof(char));
}
TEST(Cpu, TestMemoryAllocation) {