File size: 912 Bytes
db3c893
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "utils.hpp"
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <iomanip>

void check_cuda(cudaError_t st, const char* msg) {
    if (st != cudaSuccess) {
        std::cerr << "[CUDA ERROR] " << msg << ": " << cudaGetErrorString(st) << "\n";
        std::exit(1);
    }
}

void write_submission_csv(const std::string& path,
                          const std::vector<std::string>& ids,
                          const std::vector<float>& probabilities) {
    std::ofstream ofs(path);
    if (!ofs.is_open()) {
        throw std::runtime_error("Cannot open submission file: " + path);
    }
    ofs << "id,label\n";
    ofs << std::fixed << std::setprecision(8);
    for (size_t i = 0; i < ids.size(); ++i) {
        ofs << ids[i] << "," << probabilities[i] << "\n";
    }
    ofs.close();
    std::cout << "[INFO] Submission saved to: " << path << " (" << ids.size() << " rows)\n";
}