/* Example programs from the book Scientific and Engineering Programming in C++: An Introduction with Advanced Techniques and Examples, Addison-Wesley, 1994. (c) COPYRIGHT INTERNATIONAL BUSINESS MACHINES CORPORATION 1994. ALL RIGHTS RESERVED. See README file for further details. */ #ifndef ConcreteBlas2dH #define ConcreteBlas2dH #include "Array/ConcreteFortranArray2d.h" #include "Algebra/LinearSpaceCategory.h" #include "Algebra/MetricSpaceCategory.h" #include "Vector/DistributingLinearSpace.h" #include "Algebra/AlgebraWithUnitCategory.h" #include "Vector/DistributingAbelianGroup.h" #include "LapackWrap/ConcreteBlas1d.h" template class ConstConcreteBlasProjection1d : public ConcreteFortranArray2d::ConstProjectionT { public: ConstConcreteBlasProjection1d(const ConcreteFortranArray2d::ConstProjectionT& underlying_proj) : ConcreteFortranArray2d::ConstProjectionT(underlying_proj) {} ConstConcreteBlasProjection1d(ConcreteFortranArray2d::ConstProjectionT::SubscriptorT s, const T* p) : ConcreteFortranArray2d::ConstProjectionT(s, p) {} friend ConcreteBlas1d operator*(const ConstConcreteBlasProjection1d& lhs, const T& rhs); friend ConcreteBlas1d operator*(const T& lhs, const ConstConcreteBlasProjection1d& rhs); friend ConcreteBlas1d operator/(const ConstConcreteBlasProjection1d& lhs, const T& rhs); double dot(const ConstConcreteBlasProjection1d& rhs) const; private: // Copying a projection would just copy the reference to the underlying array, // not the elements. To avoid confusion, we prohibit copying. ConstConcreteBlasProjection1d(const ConstConcreteBlasProjection1d&); }; template inline ConcreteBlas1d operator*(const T& lhs, const ConstConcreteBlasProjection1d& rhs) { return rhs * lhs; } template class ConcreteBlasProjection1d : public ConcreteFortranArray2d::ProjectionT { public: ConcreteBlasProjection1d(const ConcreteFortranArray2d::ProjectionT& underlying_proj) : ConcreteFortranArray2d::ProjectionT(underlying_proj) {} ConcreteBlasProjection1d(ConcreteFortranArray2d::ProjectionT::SubscriptorT s, T* p) : ConcreteFortranArray2d::ProjectionT(s, p) {} ConcreteBlasProjection1d& operator=(const ConcreteArray1dConstRef rhs); ConcreteBlasProjection1d& operator=(const ConcreteFortranArray2d::ConstProjectionT& rhs); ConcreteBlasProjection1d& operator=(const T& rhs); double dot(const ConcreteBlasProjection1d& rhs) const; ConcreteBlasProjection1d& operator*=(const T& rhs); friend ConcreteBlas1d operator*(const ConcreteBlasProjection1d& lhs, const T& rhs); friend ConcreteBlas1d operator*(const T& lhs, const ConcreteBlasProjection1d& rhs); ConcreteBlasProjection1d& operator/=(const T& rhs); friend ConcreteBlas1d operator/(const ConcreteBlasProjection1d& lhs, const T& rhs); operator ConstConcreteBlasProjection1d() { return ConcreteFortranArray2d::ConstProjectionT(*this); } private: // Copying a projection would just copy the reference to the underlying array, // not the elements. To avoid confusion, we prohibit copying. ConcreteBlasProjection1d(const ConcreteBlasProjection1d&); }; template inline ConcreteBlasProjection1d& ConcreteBlasProjection1d::operator=(const ConcreteArray1dConstRef rhs) { ConcreteFortranArray2d::ProjectionT::operator=(rhs); return *this; } template inline ConcreteBlasProjection1d& ConcreteBlasProjection1d::operator=(const ConcreteFortranArray2d::ConstProjectionT& rhs) { ConcreteFortranArray2d::ProjectionT::operator=(rhs); return *this; } template inline ConcreteBlasProjection1d& ConcreteBlasProjection1d::operator=(const T& rhs) { ConcreteFortranArray2d::ProjectionT::operator=(rhs); return *this; } template inline ConcreteBlas1d operator*(const T& lhs, const ConcreteBlasProjection1d& rhs) { return rhs * lhs; } template class ConcreteBlas2d : public AlgebraWithUnitCategory, T>, public DistributingAbelianGroup, T>, public ConcreteFortranArray2d { public: ConcreteBlas2d(const ConcreteFortranArray2d& a); ConcreteBlas2d(Subscript nrows, Subscript ncols); typedef ConstConcreteBlasProjection1d ConstProjectionT; typedef ConcreteBlasProjection1d ProjectionT; // AlgebraWithUnitCategory ops not implemented by DistributingAbelianGroup. ConcreteBlas2d& operator*=(const T& rhs); ConcreteBlas2d& operator*=(const ConcreteBlas2d& rhs); ConcreteBlas2d& operator/=(const T& rhs); ConcreteBlas2d& setToOne(); ConcreteBlas2d& operator=(const ConcreteBlas2d& rhs); ConcreteBlas2d& operator=(const T& rhs); ConstProjectionT project(Subscript i, Dimension d = 0) const; ProjectionT project(Subscript i, Dimension d = 0); ConstProjectionT operator[](Subscript i) const { return project(i, 0); } ProjectionT operator[](Subscript i) { return project(i, 0); } ConstProjectionT row(Subscript i) const { return project(i, 0); } ProjectionT row(Subscript i) { return project(i, 0); } ConstProjectionT column(Subscript i) const { return project(i, 1); } ProjectionT column(Subscript i) { return project(i, 1); } // Matrix-Vector (Blas Level 2) Operation friend ConcreteBlas1d operator*(const ConcreteBlas2d& m, const ConcreteBlas1d& v); }; template inline ConcreteBlas2d::ConcreteBlas2d(const ConcreteFortranArray2d& a) : ConcreteFortranArray2d(a) {} template inline ConcreteBlas2d::ConcreteBlas2d(Subscript nrows, Subscript ncols) : ConcreteFortranArray2d(nrows, ncols) {} template inline ConcreteBlas2d& ConcreteBlas2d::operator=(const ConcreteBlas2d& rhs){ ConcreteFortranArray2d::operator=(rhs); return *this; } template inline ConcreteBlas2d& ConcreteBlas2d::operator=(const T& rhs){ ConcreteFortranArray2d::operator=(rhs); return *this; } template ostream& operator<<(ostream& os, const ConstConcreteBlasProjection1d& p); #ifdef XLC_QNOTEMPINC #include "LapackWrap/ConcreteBlas2d.c" #endif #endif