From 45f12ba19761024d335407793ffb8d4823b28149 Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Tue, 15 Apr 2025 00:51:40 +0300 Subject: Started doing 207 --- libprakpp/include/praktable.hpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'libprakpp/include/praktable.hpp') diff --git a/libprakpp/include/praktable.hpp b/libprakpp/include/praktable.hpp index f00e7b9..1870ec6 100644 --- a/libprakpp/include/praktable.hpp +++ b/libprakpp/include/praktable.hpp @@ -222,6 +222,14 @@ public: return data.at(names.size() * row + column); } + const dtype & SUBSCR_OPRTR (const std::string &column, size_t row) const noexcept(false) { + size_t i = index(column); + return data.at(names.size() * row + index(column)); + } + + const dtype & SUBSCR_OPRTR (size_t column, size_t row) const { + return data.at(names.size() * row + column); + } // prints a table. defaults to using std::cout, but any std::ostream can be passed in it. void print(std::ostream &stream = std::cout) const { stream << "columns: " << columns << ", rows: " << rows << std::endl; @@ -493,7 +501,7 @@ public: // returns an std::pair with coefficients A and B in that order std::pair, prak::pvalue> - least_squares_linear(std::string x, std::string y, std::optional sigma, std::optional sigma_fixed) + least_squares_linear(std::string x, std::string y, std::optional sigma, std::optional sigma_fixed) const noexcept(false) { if (sigma.has_value() == sigma_fixed.has_value()) throw std::invalid_argument("sigma and sigma_fixed can't both have (no) value"); @@ -501,9 +509,9 @@ public: prak::vector _y(rows); prak::vector _s(rows); - std::copy(begin(x), end(x), _x.begin()); - std::copy(begin(y), end(y), _y.begin()); - if (sigma.has_value()) std::copy(begin(*sigma), end(*sigma), _s.begin()); + std::copy(cbegin(x), cend(x), _x.begin()); + std::copy(cbegin(y), cend(y), _y.begin()); + if (sigma.has_value()) std::copy(cbegin(*sigma), cend(*sigma), _s.begin()); else _s = prak::vector(rows, static_cast(*sigma_fixed)); std::pair, prak::pvalue> ret; @@ -512,31 +520,31 @@ public: } // calculate an average of the column - dtype col_avg(const std::string &column) { + dtype col_avg(const std::string &column) const { dtype accum = dtype{}; - for (auto it = begin(column); it != end(column); ++it) + for (auto it = cbegin(column); it != cend(column); ++it) accum += *it; return accum / rows; } - dtype col_max(const std::string &column) { + dtype col_max(const std::string &column) const { dtype max = dtype{}; - for (auto it = begin(column); it != end(column); ++it) + for (auto it = cbegin(column); it != cend(column); ++it) max = max < *it ? *it : max; return max; } - dtype col_min(const std::string &column) { + dtype col_min(const std::string &column) const { dtype min = dtype{}; - for (auto it = begin(column); it != end(column); ++it) + for (auto it = cbegin(column); it != cend(column); ++it) min = min > *it ? *it : min; return min; } // calculate standard deviation of the column - dtype col_stddev(const std::string &column) { + dtype col_stddev(const std::string &column) const { dtype accum = dtype{}; dtype avg = col_avg(column); - for (auto it = begin(column); it != end(column); ++it) + for (auto it = cbegin(column); it != cend(column); ++it) accum += (*it - avg)*(*it - avg); return std::sqrt(accum / rows); } -- cgit v1.2.3-70-g09d2