Anasazi Version of the Day
Tsqr_ApplyType.cpp
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                 Anasazi: Block Eigensolvers Package
00005 //                 Copyright (2010) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include <Tsqr_ApplyType.hpp>
00030 #include <stdexcept>
00031 
00034 
00035 namespace TSQR {
00036   ApplyType::ApplyType (const std::string& op) :
00037     type_ (decide_apply_type (op)),
00038     lapackString_ (enumToLapackString (type_))
00039   {}
00040 
00041   ApplyType::ApplyType (const ApplyType& rhs) :
00042     type_ (rhs.type_),
00043     lapackString_ (rhs.lapackString_)
00044   {}
00045 
00046   ApplyType& ApplyType::operator= (const ApplyType& rhs) {
00047     type_ = rhs.type_;
00048     lapackString_ = rhs.lapackString_;
00049     return *this;
00050   }
00051 
00052   const ApplyType ApplyType::NoTranspose = ApplyType ("N");
00053   const ApplyType ApplyType::Transpose = ApplyType ("T");
00054   const ApplyType ApplyType::ConjugateTranspose = ApplyType ("C");
00055 
00056   std::string 
00057   ApplyType::enumToLapackString (const ApplyType::ApplyType_ theType)
00058   {
00059     if (theType == NoTranspose_)
00060       return std::string("N");
00061     else if (theType == Transpose_)
00062       return std::string("T");
00063     else if (theType == ConjugateTranspose_)
00064       return std::string("C");
00065     else
00066       throw std::logic_error("Invalid ApplyType: should never get here");
00067   }
00068 
00069   bool 
00070   ApplyType::decide_transposed (const std::string& op) const 
00071   {
00072     if (op[0] == 'N' || op[0] == 'n')
00073       return false;
00074     else
00075       {
00076   const char validTransposeLetters[] = "TtCcHh";
00077   const int numValidTransposeLetters = 6;
00078 
00079   for (int k = 0; k < numValidTransposeLetters; ++k)
00080     if (op[0] == validTransposeLetters[k])
00081       return true;
00082 
00083   throw std::invalid_argument ("Invalid \"op\" argument \"" + op + "\"");
00084       }
00085   }
00086 
00087   ApplyType::ApplyType_
00088   ApplyType::decide_apply_type (const std::string& op) const 
00089   {
00090     if (op[0] == 'T' || op[0] == 't')
00091       return Transpose_;
00092     else if (op[0] == 'N' || op[0] == 'n')
00093       return NoTranspose_;
00094     else if (op[0] == 'C' || op[0] == 'c' || op[0] == 'H' || op[0] == 'h')
00095       return ConjugateTranspose_;
00096     else
00097       throw std::invalid_argument ("Invalid \"op\" argument \"" + op + "\"");
00098   }
00099 }
00100 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends