MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / sam3_load_ref_f32_data

Function sam3_load_ref_f32_data

sam3.cpp:12559–12598  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12557}
12558
12559static bool sam3_load_ref_f32_data(const std::string& path,
12560 std::vector<float>& data,
12561 int expected_numel = -1) {
12562 std::ifstream shape_f(path + ".shape");
12563 if (!shape_f) {
12564 fprintf(stderr, "%s: missing %s.shape\n", __func__, path.c_str());
12565 return false;
12566 }
12567
12568 int64_t numel = 1;
12569 std::string line;
12570 std::getline(shape_f, line);
12571 size_t pos = 0;
12572 while (pos < line.size()) {
12573 size_t end = line.find(',', pos);
12574 if (end == std::string::npos) {
12575 end = line.size();
12576 }
12577 if (end > pos) {
12578 numel *= std::stoll(line.substr(pos, end - pos));
12579 }
12580 pos = end + 1;
12581 }
12582
12583 if (expected_numel >= 0 && numel != expected_numel) {
12584 fprintf(stderr, "%s: %s expected %d elements, got %lld\n",
12585 __func__, path.c_str(), expected_numel, (long long)numel);
12586 return false;
12587 }
12588
12589 std::ifstream data_f(path + ".bin", std::ios::binary);
12590 if (!data_f) {
12591 fprintf(stderr, "%s: missing %s.bin\n", __func__, path.c_str());
12592 return false;
12593 }
12594
12595 data.resize((size_t)numel);
12596 data_f.read(reinterpret_cast<char*>(data.data()), numel * sizeof(float));
12597 return data_f.good() || data_f.eof();
12598}
12599
12600static std::vector<float> sam3_reorder_nchw_to_ggml_dwh(const std::vector<float>& src,
12601 int channels,

Calls

no outgoing calls

Tested by

no test coverage detected