#pragma once #include #include #include "SparseVector.h" #include "FullRow.h" namespace MbD { template class SparseRow : public SparseVector { public: SparseRow(){} SparseRow(int n) : SparseVector(n) {} SparseRow(std::initializer_list> list) : SparseVector{ list } {} SparseRow(std::initializer_list> list) : SparseVector{ list } {} std::shared_ptr> timesconditionedWithTol(double scaling, double tol); std::shared_ptr> conditionedWithTol(double tol); void atiplusFullRow(int j, std::shared_ptr> fullRow); void atiplusFullRowtimes(int j, std::shared_ptr> fullRow, double factor); }; using SpRowDsptr = std::shared_ptr>; template<> inline std::shared_ptr> SparseRow::timesconditionedWithTol(double scaling, double tol) { auto answer = std::make_shared>(this->numberOfElements()); for (auto const& keyValue : *this) { auto val = keyValue.second * scaling; if (std::abs(val) >= tol) (*answer)[keyValue.first] = val; } return answer; } template<> inline std::shared_ptr> SparseRow::conditionedWithTol(double tol) { auto answer = std::make_shared>(this->numberOfElements()); for (auto const& keyValue : *this) { auto val = keyValue.second; if (std::abs(val) >= tol) (*answer)[keyValue.first] = val; } return answer; } template inline void SparseRow::atiplusFullRow(int j, std::shared_ptr> fullRow) { for (int jj = 0; jj < fullRow->size(); jj++) { (*this)[j + jj] += fullRow->at(jj); } } template inline void SparseRow::atiplusFullRowtimes(int j, std::shared_ptr> fullRow, double factor) { for (int jj = 0; jj < fullRow->size(); jj++) { (*this)[j + jj] += fullRow->at(jj) * factor; } } }