MCPcopy Create free account
hub / github.com/alibaba/MNN / loadData

Function loadData

tools/cpp/testModelWithDescribe.cpp:49–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49int loadData(const std::string name, void* ptr, int size, halide_type_t dtype) {
50 std::ifstream stream(name.c_str());
51 if (stream.fail()) {
52 return -1;
53 }
54 switch (dtype.code) {
55 case halide_type_float: {
56 auto data = static_cast<float*>(ptr);
57 for (int i = 0; i < size; ++i) {
58 double temp = 0.0f;
59 stream >> temp;
60 data[i] = temp;
61 }
62 } break;
63 case halide_type_int: {
64 MNN_ASSERT(dtype.bits == 32);
65 auto data = static_cast<int32_t*>(ptr);
66 for (int i = 0; i < size; ++i) {
67 int temp = 0;
68 stream >> temp;
69 data[i] = temp;
70 }
71 } break;
72 case halide_type_uint: {
73 MNN_ASSERT(dtype.bits == 8);
74 auto data = static_cast<uint8_t*>(ptr);
75 for (int i = 0; i < size; ++i) {
76 int temp = 0;
77 stream >> temp;
78 data[i] = temp;
79 }
80 } break;
81 default: {
82 stream.close();
83 return -1;
84 }
85 }
86
87 stream.close();
88 return 0;
89}
90
91MNN::Tensor* createTensor(const MNN::Tensor* shape, const std::string name) {
92 auto result = new MNN::Tensor(shape, shape->getDimensionType());

Callers 2

createTensorFunction · 0.85
createVarFunction · 0.85

Calls 2

c_strMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected