| 1297 | } |
| 1298 | |
| 1299 | bool test_embedding_from_file() { |
| 1300 | CactusGraph graph; |
| 1301 | |
| 1302 | std::vector<__fp16> embeddings_data = { |
| 1303 | 1.0f, 5.0f, 9.0f, |
| 1304 | 2.0f, 6.0f, 10.0f, |
| 1305 | 3.0f, 7.0f, 11.0f, |
| 1306 | 4.0f, 8.0f, 12.0f |
| 1307 | }; |
| 1308 | |
| 1309 | size_t temp_embeddings = graph.input({4, 3}, Precision::FP16); |
| 1310 | graph.set_input(temp_embeddings, embeddings_data.data(), Precision::FP16); |
| 1311 | |
| 1312 | const std::string temp_file = "test_embedding.bin"; |
| 1313 | GraphFile::save_node(graph, temp_embeddings, temp_file); |
| 1314 | |
| 1315 | graph.hard_reset(); |
| 1316 | |
| 1317 | size_t indices = graph.input({3}, Precision::INT8); |
| 1318 | size_t embedded = graph.embedding(temp_file, indices); |
| 1319 | |
| 1320 | std::vector<int8_t> idx_data = {2, 0, 3}; |
| 1321 | graph.set_input(indices, idx_data.data(), Precision::INT8); |
| 1322 | graph.execute(); |
| 1323 | |
| 1324 | std::vector<__fp16> expected = { |
| 1325 | 3.0f, 7.0f, 11.0f, |
| 1326 | 1.0f, 5.0f, 9.0f, |
| 1327 | 4.0f, 8.0f, 12.0f |
| 1328 | }; |
| 1329 | |
| 1330 | __fp16* output = static_cast<__fp16*>(graph.get_output(embedded)); |
| 1331 | bool passed = true; |
| 1332 | for (size_t i = 0; i < expected.size(); i++) { |
| 1333 | if (std::abs(static_cast<float>(output[i]) - static_cast<float>(expected[i])) > 0.01f) { |
| 1334 | passed = false; |
| 1335 | break; |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | std::remove(temp_file.c_str()); |
| 1340 | |
| 1341 | return passed; |
| 1342 | } |
| 1343 | |
| 1344 | bool test_stft() { |
| 1345 | const size_t N = 2, C_in = 1, L = 8, K = 4, stride = 2, num_fft_bins = 2; |
no test coverage detected