From 615f2efaa5fc09710a785586f494c36a8ed043cb Mon Sep 17 00:00:00 2001 From: Simone Balducci Date: Fri, 7 Feb 2025 10:20:28 +0100 Subject: [PATCH] Add unique `read_csv` in utility --- benchmark/profiling/read_csv.hpp | 46 ------------------- .../CLUEstering/utility}/read_csv.hpp | 11 +---- 2 files changed, 2 insertions(+), 55 deletions(-) delete mode 100644 benchmark/profiling/read_csv.hpp rename {benchmark/dataset_size => include/CLUEstering/utility}/read_csv.hpp (85%) diff --git a/benchmark/profiling/read_csv.hpp b/benchmark/profiling/read_csv.hpp deleted file mode 100644 index e2a28dbb..00000000 --- a/benchmark/profiling/read_csv.hpp +++ /dev/null @@ -1,46 +0,0 @@ - -#ifndef read_csv_hpp -#define read_csv_hpp - -#include -#include -#include -#include -#include - -#include "CLUEstering/DataFormats/alpaka/AlpakaVecArray.hpp" - -using clue::VecArray; - -template -std::vector read_csv(const std::string& file_path) { - std::fstream file(file_path); - if (!file.is_open()) { - throw std::runtime_error("Could not open file: " + file_path); - } - auto n_points = std::count( - std::istreambuf_iterator(file), std::istreambuf_iterator(), '\n'); - - std::vector coords((NDim + 1) * n_points); - - // discard the header - std::string buffer; - getline(file, buffer); - auto point_id = 0; - while (getline(file, buffer)) { - std::stringstream buffer_stream(buffer); - std::string value; - - for (size_t dim = 0; dim <= NDim; ++dim) { - getline(buffer_stream, value, ','); - coords[point_id + dim * n_points] = static_cast(std::stod(value)); - } - ++point_id; - } - - file.close(); - - return coords; -} - -#endif diff --git a/benchmark/dataset_size/read_csv.hpp b/include/CLUEstering/utility/read_csv.hpp similarity index 85% rename from benchmark/dataset_size/read_csv.hpp rename to include/CLUEstering/utility/read_csv.hpp index e2a28dbb..89fb8870 100644 --- a/benchmark/dataset_size/read_csv.hpp +++ b/include/CLUEstering/utility/read_csv.hpp @@ -1,17 +1,11 @@ -#ifndef read_csv_hpp -#define read_csv_hpp +#pragma once #include #include #include -#include #include -#include "CLUEstering/DataFormats/alpaka/AlpakaVecArray.hpp" - -using clue::VecArray; - template std::vector read_csv(const std::string& file_path) { std::fstream file(file_path); @@ -20,9 +14,9 @@ std::vector read_csv(const std::string& file_path) { } auto n_points = std::count( std::istreambuf_iterator(file), std::istreambuf_iterator(), '\n'); - std::vector coords((NDim + 1) * n_points); + file = std::fstream(file_path); // discard the header std::string buffer; getline(file, buffer); @@ -43,4 +37,3 @@ std::vector read_csv(const std::string& file_path) { return coords; } -#endif