From b8d5cb18ec6f7b12b77c43550129997cdc675e88 Mon Sep 17 00:00:00 2001 From: Andrew D Smith Date: Sun, 10 Aug 2025 17:48:59 -0700 Subject: [PATCH 1/2] src/radmeth/radmeth.cpp: fixing things that got messed up in previous commit --- src/radmeth/radmeth.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/radmeth/radmeth.cpp b/src/radmeth/radmeth.cpp index e4a89aa3..97ea9ad7 100644 --- a/src/radmeth/radmeth.cpp +++ b/src/radmeth/radmeth.cpp @@ -37,20 +37,25 @@ #include struct file_progress { - double one_hundred_over_filesize{}; + double one_thousand_over_filesize{}; std::size_t prev_offset{}; explicit file_progress(const std::string &filename) : - one_hundred_over_filesize{100.0 / std::filesystem::file_size(filename)} {} + one_thousand_over_filesize{1000.0 / std::filesystem::file_size(filename)} {} void operator()(std::ifstream &in) { const std::size_t curr_offset = - in.eof() ? 100 : in.tellg() * one_hundred_over_filesize; + in.eof() ? 1000 : in.tellg() * one_thousand_over_filesize; if (curr_offset <= prev_offset) return; - std::cerr << "\r[progress: " << std::setw(3) << curr_offset - << (curr_offset == 100 ? "%]\n" : "%]"); - prev_offset = (curr_offset == 100) ? std::numeric_limits::max() - : curr_offset; + std::ios old_state(nullptr); + old_state.copyfmt(std::cerr); + std::cerr << "\r[progress: " << std::setw(5) << std::fixed + << std::setprecision(1) << (curr_offset / 10.0) + << (curr_offset == 1000 ? "%]\n" : "%]"); + std::cerr.copyfmt(old_state); + prev_offset = (curr_offset == 1000) + ? std::numeric_limits::max() + : curr_offset; } }; @@ -162,6 +167,9 @@ drop_idx(const std::vector &v, const std::size_t idx_to_drop) { return u; } +/// ADS: this function is not currently used, as the threads do not operate in +/// "chunks" +/* static inline void get_chunk_bounds(const std::uint32_t n_elements, const std::uint32_t n_chunks, std::vector> &chunks) { @@ -175,6 +183,7 @@ get_chunk_bounds(const std::uint32_t n_elements, const std::uint32_t n_chunks, block_start = block_end; } } +*/ static void radmeth(const bool show_progress, const bool more_na_info, @@ -224,7 +233,7 @@ that the design matrix and the proportion table are correctly formatted. std::vector alt_models(n_threads, alt_model); std::vector null_models(n_threads, null_model); - std::vector> chunks(n_threads); + // std::vector> chunks(n_threads); // Iterate over rows in the file and do llr test on proportions from // each. Do this in sets of rows to avoid having to spawn too many threads. @@ -235,15 +244,21 @@ that the design matrix and the proportion table are correctly formatted. if (n_lines == 0) break; - get_chunk_bounds(n_lines, n_threads, chunks); + /// ADS: chunks not used + // get_chunk_bounds(n_lines, n_threads, chunks); std::vector threads; for (auto thread_id = 0u; thread_id < n_threads; ++thread_id) { threads.emplace_back([&, thread_id] { - const auto &[chunk_beg, chunk_end] = chunks[thread_id]; + /// ADS: chunks not used + // const auto &[chunk_beg, chunk_end] = chunks[thread_id]; auto &t_alt_model = alt_models[thread_id]; auto &t_null_model = null_models[thread_id]; - for (auto b = chunk_beg; b != chunk_end; ++b) { + /// ADS: chunks not used + // for (auto b = chunk_beg; b != chunk_end; ++b) { + for (auto b = 0u; b < n_lines; ++b) { + if (b % n_threads != thread_id) + continue; t_alt_model.props.parse(lines[b]); if (t_alt_model.props_size() != n_samples) throw std::runtime_error("found row with wrong number of columns"); From 0204135f231c2054c56f888b97562ade99fadd29 Mon Sep 17 00:00:00 2001 From: Andrew D Smith Date: Sun, 10 Aug 2025 17:49:12 -0700 Subject: [PATCH 2/2] src/radmeth/radmeth_optimize.cpp: fixing things that got messed up in previous commit --- src/radmeth/radmeth_optimize.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/radmeth/radmeth_optimize.cpp b/src/radmeth/radmeth_optimize.cpp index 5d103c6f..4839c229 100644 --- a/src/radmeth/radmeth_optimize.cpp +++ b/src/radmeth/radmeth_optimize.cpp @@ -168,6 +168,7 @@ static void neg_gradient(const gsl_vector *params, void *object, gsl_vector *output) { auto reg = static_cast(object); gradient(params, *reg, output); + gsl_vector_scale(output, -1.0); } static void