/* 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. */ #include "SciEng/utils.h" #include "Array/InterfacedArray2d.h" template LapackUnfactored::Unfactored* LapackUnfactored::releaseControl() { checkValidity(); valid = Boolean::false; return ap.releaseControl(); } template LapackFactored LapackUnfactored::factor() { checkValidity(); valid = Boolean::false; Rep::Unfactored* fp = ap.releaseControl(); return LapackFactored(new Rep::Factored(fp)); } template LapackUnfactored::LapackUnfactored(Subscript n1, Subscript n2) : ap(new Rep::Unfactored(n1, n2)), valid(Boolean::true) { } template LapackUnfactored::LapackUnfactored(const LapackUnfactored& a): ap(new Rep::Unfactored(a.rep())), valid(Boolean::true) { } template LapackUnfactored::LapackUnfactored(const ConstArray2d& a): ap(new Rep::Unfactored(a.shape(0), a.shape(1))), valid(Boolean::true) { *this = a; } template LapackUnfactored::LapackUnfactored(const ConcreteFortranArray2d& a): ap(new Rep::Unfactored(a.shape(0), a.shape(1))), valid(Boolean::true) { *this = a; } template Subscript LapackUnfactored::shape(Dimension d) const { checkValidity(); return ap->shape(d); } template Dimension LapackUnfactored::dim() const { checkValidity(); return 2; } template const LapackUnfactored::EltT& LapackUnfactored::operator()(Subscript s0, Subscript s1) const { checkValidity(); return (*ap)(s0, s1); } template LapackUnfactored::EltT& LapackUnfactored::operator()(Subscript s0, Subscript s1) { checkValidity(); return (*ap)(s0, s1); } template LapackUnfactored::ConstProjectionT LapackUnfactored::project(Subscript s, Dimension d) const { return new InterfacedConstArrayProjection1d< Rep::Unfactored >(rep().project(s, d)); } template LapackUnfactored::ProjectionT LapackUnfactored::project(Subscript s, Dimension d) { return new InterfacedArrayProjection1d< Rep::Unfactored >(rep().project(s, d)); } template void LapackUnfactored::checkValidity() const { if (! valid) throw LapackErr::InvalidFactoredMatrixUse(); } template Array2d::EltT>& LapackUnfactored::operator=(const EltT& rhs) { checkValidity(); // Must be unfactored; once factored we do not know the size. *ap = rhs; return *this; } template Array2d::EltT>& LapackUnfactored::operator=(const LapackUnfactored& rhs) { if (!valid) { // then we are loading a new unfactored, allocate for it. ap = new Rep::Unfactored(rhs.rep()); } else { // We are over-writing, use assignment rules of Rep. *ap = rhs.rep(); // rep() checks validity } valid = Boolean::true; return *this; } template Array2d::EltT>& LapackUnfactored::operator=(const ConstArray2d& rhs) { if (!valid) { ap = new Rep::Unfactored(rhs.shape(0), rhs.shape(1)); } Rep::Unfactored& lhs = *ap; if (lhs.shape(0) != rhs.shape(0) || lhs.shape(1) != rhs.shape(1)) throw ArrayErr::Shape(); LapackUnfactored::IteratorType lhs_i(*this); ConstArray2d::BrowserType rhs_i(rhs); for (; lhs_i.more(); lhs_i.advance(), rhs_i.advance()) lhs_i.current() = rhs_i.current(); valid = Boolean::true; return *this; } template Array2d::EltT>& LapackUnfactored::operator=(const ConcreteFortranArray2d& rhs) { if (!valid) { ap = new Rep::Unfactored(rhs.shape(0), rhs.shape(1)); } Rep::Unfactored& lhs = *ap; if (lhs.shape(0) != rhs.shape(0)) throw ArrayErr::Shape(); for (Subscript i = 0; i < lhs.shape(0); i++) concreteCopy(lhs[i], rhs[i]); valid = Boolean::true; return *this; } template LapackFactored::Unknowns1d& LapackFactored::solve(LapackFactored::Unknowns1d& b) { ap->solve(b); return b; } template LapackFactored::Unknowns1d& LapackFactored::solve(LapackFactored::Unknowns1d& x,const LapackFactored::Knowns1d& b) { ap->solve(x,b); return x; } template LapackFactored::Unknowns2d& LapackFactored::solve(LapackFactored::Unknowns2d& b) { ap->solve(b); return b; } template LapackFactored::Unknowns2d& LapackFactored::solve(LapackFactored::Unknowns2d& x,const LapackFactored::Knowns2d& b) { ap->solve(x,b); return x; }