|
1 | 1 | // Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
2 | 2 | // SPDX-License-Identifier: MIT
|
3 |
| -// Copyright (c) 2018 - 2020 Daniil Goncharov <[email protected]>. |
| 3 | +// Copyright (c) 2018 - 2024 Daniil Goncharov <[email protected]>. |
4 | 4 | //
|
5 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 | 6 | // of this software and associated documentation files (the "Software"), to deal
|
@@ -36,6 +36,10 @@ static void DeallocateBuffer(void* data, size_t) {
|
36 | 36 | std::free(data);
|
37 | 37 | }
|
38 | 38 |
|
| 39 | +static void Deallocator(void*, size_t, void*) { |
| 40 | + //std::free(data); |
| 41 | +} |
| 42 | + |
39 | 43 | static TF_Buffer* ReadBufferFromFile(const char* file) {
|
40 | 44 | std::ifstream f(file, std::ios::binary);
|
41 | 45 | SCOPE_EXIT{ f.close(); };
|
@@ -68,13 +72,15 @@ static TF_Buffer* ReadBufferFromFile(const char* file) {
|
68 | 72 | return buf;
|
69 | 73 | }
|
70 | 74 |
|
71 |
| -TF_Tensor* ScalarStringTensor(const char* str, TF_Status* status) { |
| 75 | +TF_Tensor* ScalarStringTensor(const char* str, TF_Status*) { |
72 | 76 | auto str_len = std::strlen(str);
|
73 |
| - auto nbytes = 8 + TF_StringEncodedSize(str_len); // 8 extra bytes - for start_offset. |
74 |
| - auto tensor = TF_AllocateTensor(TF_STRING, nullptr, 0, nbytes); |
75 |
| - auto data = static_cast<char*>(TF_TensorData(tensor)); |
76 |
| - std::memset(data, 0, 8); |
77 |
| - TF_StringEncode(str, str_len, data + 8, nbytes - 8, status); |
| 77 | + TF_TString tstring[1]; |
| 78 | + TF_TString_Init(&tstring[0]); |
| 79 | + TF_TString_Copy(&tstring[0], str, str_len); |
| 80 | + int64_t dims[] = { 1,1 }; |
| 81 | + int num_dims = 1; |
| 82 | + TF_Tensor* tensor = TF_NewTensor(TF_STRING, dims, num_dims, &tstring[0], sizeof(tstring), &Deallocator, nullptr); |
| 83 | + |
78 | 84 | return tensor;
|
79 | 85 | }
|
80 | 86 |
|
|
0 commit comments