Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Tsqr_ApplyType.cpp
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //          Kokkos: Node API and Parallel Node Kernels
00005 //              Copyright (2009) 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 
00032 
00033 namespace TSQR {
00034   ApplyType::ApplyType (const std::string& op) :
00035     type_ (decide_apply_type (op)),
00036     lapackString_ (enumToLapackString (type_))
00037   {}
00038 
00039   ApplyType::ApplyType (const ApplyType& rhs) :
00040     type_ (rhs.type_),
00041     lapackString_ (rhs.lapackString_)
00042   {}
00043 
00044   ApplyType& ApplyType::operator= (const ApplyType& rhs) {
00045     type_ = rhs.type_;
00046     lapackString_ = rhs.lapackString_;
00047     return *this;
00048   }
00049 
00050   const ApplyType ApplyType::NoTranspose = ApplyType ("N");
00051   const ApplyType ApplyType::Transpose = ApplyType ("T");
00052   const ApplyType ApplyType::ConjugateTranspose = ApplyType ("C");
00053 
00054   std::string 
00055   ApplyType::enumToLapackString (const ApplyType::ApplyType_ theType)
00056   {
00057     if (theType == NoTranspose_)
00058       return std::string("N");
00059     else if (theType == Transpose_)
00060       return std::string("T");
00061     else if (theType == ConjugateTranspose_)
00062       return std::string("C");
00063     else
00064       throw std::logic_error("Invalid ApplyType: should never get here");
00065   }
00066 
00067   bool 
00068   ApplyType::decide_transposed (const std::string& op) const 
00069   {
00070     if (op[0] == 'N' || op[0] == 'n')
00071       return false;
00072     else
00073       {
00074   const char validTransposeLetters[] = "TtCcHh";
00075   const int numValidTransposeLetters = 6;
00076 
00077   for (int k = 0; k < numValidTransposeLetters; ++k)
00078     if (op[0] == validTransposeLetters[k])
00079       return true;
00080 
00081   throw std::invalid_argument ("Invalid \"op\" argument \"" + op + "\"");
00082       }
00083   }
00084 
00085   ApplyType::ApplyType_
00086   ApplyType::decide_apply_type (const std::string& op) const 
00087   {
00088     if (op[0] == 'T' || op[0] == 't')
00089       return Transpose_;
00090     else if (op[0] == 'N' || op[0] == 'n')
00091       return NoTranspose_;
00092     else if (op[0] == 'C' || op[0] == 'c' || op[0] == 'H' || op[0] == 'h')
00093       return ConjugateTranspose_;
00094     else
00095       throw std::invalid_argument ("Invalid \"op\" argument \"" + op + "\"");
00096   }
00097 }
00098 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends