#pragma once #include "Array.h" namespace MbD { template class FullVector : public Array { public: FullVector() {} FullVector(std::vector vec) : Array(vec) {} FullVector(int count) : Array(count) {} FullVector(int count, const T& value) : Array(count, value) {} FullVector(std::vector::iterator begin, std::vector::iterator end) : Array(begin, end) {} FullVector(std::initializer_list list) : Array{ list } {} double dot(std::shared_ptr> vec); void atiput(int i, T value); void atiplusNumber(int i, T value); void atiminusNumber(int i, T value); double sumOfSquares() override; int numberOfElements() override; void zeroSelf() override; void atitimes(int i, double factor); void atiplusFullVector(int i, std::shared_ptr fullVec); void atiplusFullVectortimes(int i, std::shared_ptr fullVec, double factor); double maxMagnitude(); }; template inline double FullVector::dot(std::shared_ptr> vec) { int n = (int) this->size(); double answer = 0.0; for (int i = 0; i < n; i++) { answer += this->at(i) * vec->at(i); } return answer; } template inline void FullVector::atiput(int i, T value) { this->at(i) = value; } template inline void FullVector::atiplusNumber(int i, T value) { this->at(i) += value; } template inline void FullVector::atiminusNumber(int i, T value) { this->at(i) -= value; } template<> inline double FullVector::sumOfSquares() { double sum = 0.0; for (int i = 0; i < this->size(); i++) { double element = this->at(i); sum += element * element; } return sum; } template inline double FullVector::sumOfSquares() { assert(false); return 0.0; } template inline int FullVector::numberOfElements() { return (int) this->size(); } template<> inline void FullVector::zeroSelf() { for (int i = 0; i < this->size(); i++) { this->at(i) = 0.0; } } template inline void FullVector::zeroSelf() { assert(false); } template inline void FullVector::atitimes(int i, double factor) { this->at(i) *= factor; } template inline void FullVector::atiplusFullVector(int i1, std::shared_ptr fullVec) { for (int ii = 0; ii < fullVec->size(); ii++) { auto i = i1 + ii; this->at(i) += fullVec->at(ii); } } template inline void FullVector::atiplusFullVectortimes(int i1, std::shared_ptr fullVec, double factor) { for (int ii = 0; ii < fullVec->size(); ii++) { auto i = i1 + ii; this->at(i) += fullVec->at(ii) * factor; } } template<> inline double FullVector::maxMagnitude() { auto answer = 0.0; for (int i = 0; i < this->size(); i++) { auto mag = std::abs(this->at(i)); if (answer < mag) answer = mag; } return answer; } }