#pragma once #include "FullVector.h" //#include "FullColumn.h" namespace MbD { template class FullMatrix; template class FullColumn; template class FullRow : public FullVector { public: FullRow(std::vector vec) : FullVector(vec) {} FullRow(int count) : FullVector(count) {} FullRow(int count, const T& value) : FullVector(count, value) {} FullRow(std::vector::iterator begin, std::vector::iterator end) : FullVector(begin, end) {} FullRow(std::initializer_list list) : FullVector{ list } {} std::shared_ptr> times(double a); std::shared_ptr> negated(); std::shared_ptr> plusFullRow(std::shared_ptr> fullRow); std::shared_ptr> minusFullRow(std::shared_ptr> fullRow); T timesFullColumn(std::shared_ptr> fullCol); std::shared_ptr> timesFullMatrix(std::shared_ptr> fullMat); std::shared_ptr> timesTransposeFullMatrix(std::shared_ptr> fullMat); void equalSelfPlusFullRowTimes(std::shared_ptr> fullRow, double factor); std::shared_ptr> transpose(); std::shared_ptr> copy(); void atiplusFullRow(int j, std::shared_ptr> fullRow); }; template inline std::shared_ptr> FullRow::times(double a) { int n = (int) this->size(); auto answer = std::make_shared(n); for (int i = 0; i < n; i++) { answer->at(i) = this->at(i) * a; } return answer; } template inline std::shared_ptr> FullRow::negated() { return this->times(-1.0); } template inline std::shared_ptr> FullRow::plusFullRow(std::shared_ptr> fullRow) { int n = (int) this->size(); auto answer = std::make_shared>(n); for (int i = 0; i < n; i++) { answer->at(i) = this->at(i) + fullRow->at(i); } return answer; } template inline std::shared_ptr> FullRow::minusFullRow(std::shared_ptr> fullRow) { int n = (int) this->size(); auto answer = std::make_shared>(n); for (int i = 0; i < n; i++) { answer->at(i) = this->at(i) - fullRow->at(i); } return answer; } template inline T FullRow::timesFullColumn(std::shared_ptr> fullCol) { auto answer = this->at(0) * fullCol->at(0); for (int i = 1; i < this->size(); i++) { answer += this->at(i) * fullCol->at(i); } return answer; } template inline std::shared_ptr> FullRow::timesTransposeFullMatrix(std::shared_ptr> fullMat) { //"a*bT = a(1,j)b(k,j)" int ncol = fullMat->nrow(); auto answer = std::make_shared>(ncol); for (int k = 0; k < ncol; k++) { answer->at(k) = this->dot(fullMat->at(k)); } return answer; } template inline void FullRow::equalSelfPlusFullRowTimes(std::shared_ptr> fullRow, double factor) { for (int i = 0; i < this->size(); i++) { this->at(i) += fullRow->at(i) * factor; } } template inline std::shared_ptr> FullRow::transpose() { return std::make_shared>(*this); } template<> inline std::shared_ptr> FullRow::copy() { auto n = (int)this->size(); auto answer = std::make_shared>(n); for (int i = 0; i < n; i++) { answer->at(i) = this->at(i); } return answer; } template inline void FullRow::atiplusFullRow(int j1, std::shared_ptr> fullRow) { for (int jj = 0; jj < fullRow->size(); jj++) { auto j = j1 + jj; this->at(j) += fullRow->at(jj); } } template inline std::shared_ptr> FullRow::timesFullMatrix(std::shared_ptr> fullMat) { std::shared_ptr> answer = fullMat->at(0)->times(this->at(0)); for (int j = 1; j < (int) this->size(); j++) { answer->equalSelfPlusFullRowTimes(fullMat->at(j), this->at(j)); } return answer; //return std::shared_ptr>(); } using ListFRD = std::initializer_list>>; using FRowDsptr = std::shared_ptr>; }