Epetra Package Browser (Single Doxygen Collection) Development
Epetra_SerialSymDenseMatrix.cpp
Go to the documentation of this file.
00001 
00002 //@HEADER
00003 // ************************************************************************
00004 // 
00005 //               Epetra: Linear Algebra Services Package 
00006 //                 Copyright 2011 Sandia Corporation
00007 // 
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00039 // 
00040 // ************************************************************************
00041 //@HEADER
00042 
00043 #include "Epetra_SerialSymDenseMatrix.h"
00044 //=============================================================================
00045 Epetra_SerialSymDenseMatrix::Epetra_SerialSymDenseMatrix(void)
00046   : Epetra_SerialDenseMatrix(),
00047     Upper_(false),
00048     UPLO_('L')
00049 
00050 {
00051 }
00052 //=============================================================================
00053 Epetra_SerialSymDenseMatrix::Epetra_SerialSymDenseMatrix(Epetra_DataAccess CV_in, double *A_in, int LDA_in, int NumRowsCols)
00054   : Epetra_SerialDenseMatrix(CV_in, A_in, LDA_in, NumRowsCols, NumRowsCols),
00055     Upper_(false),
00056     UPLO_('L')
00057 
00058 {
00059 }
00060 //=============================================================================
00061 Epetra_SerialSymDenseMatrix::Epetra_SerialSymDenseMatrix(const Epetra_SerialSymDenseMatrix& Source)
00062   : Epetra_SerialDenseMatrix(Source),  
00063     Upper_(Source.Upper_),
00064     UPLO_(Source.UPLO_)
00065 {
00066 }
00067 //=============================================================================
00068 Epetra_SerialSymDenseMatrix::~Epetra_SerialSymDenseMatrix()
00069 {
00070 }
00071 //=============================================================================
00072 void Epetra_SerialSymDenseMatrix::CopyUPLOMat(bool Upper_in, double * A_in, int LDA_in, int NumRows) {
00073 
00074   int i, j;
00075   double * ptr1;
00076   double * ptr2;
00077 
00078   if (Upper_in) {
00079     for (j=1; j<NumRows; j++) {
00080       ptr1 = A_in + j;
00081       ptr2 = A_in + j*LDA_in;
00082       for (i=0; i<j; i++) {
00083   *ptr1 = *ptr2++;
00084   ptr1+=LDA_in;
00085       }
00086     }
00087   }
00088   else {
00089     for (i=1; i<NumRows; i++) {
00090       ptr1 = A_in + i;
00091       ptr2 = A_in + i*LDA_in;
00092       for (j=0; j<i; j++) {
00093   *ptr2++ = *ptr1;
00094   ptr1+=LDA_in;
00095       }
00096     }
00097   }
00098 }
00099 //=============================================================================
00100 double Epetra_SerialSymDenseMatrix::NormOne(void) const{
00101 
00102     return(Epetra_SerialSymDenseMatrix::NormInf());
00103 }
00104 //=============================================================================
00105 double Epetra_SerialSymDenseMatrix::NormInf(void) const {
00106 
00107   int i, j;
00108 
00109   double anorm = 0.0;
00110   double * ptr;
00111 
00112   if (!Upper()) {
00113     for (j=0; j<N_; j++) {
00114       double sum = 0.0;
00115       ptr = A_ + j + j*LDA_;
00116       for (i=j; i<N_; i++) sum += std::abs(*ptr++);
00117       ptr = A_ + j;
00118       for (i=0; i<j; i++) {
00119   sum += std::abs(*ptr);
00120   ptr += LDA_;
00121       }
00122       anorm = EPETRA_MAX(anorm, sum);
00123     }
00124   }
00125   else {
00126     for (j=0; j<N_; j++) {
00127       double sum = 0.0;
00128       ptr = A_ + j*LDA_;
00129       for (i=0; i<j; i++) sum += std::abs(*ptr++);
00130       ptr = A_ + j + j*LDA_;
00131       for (i=j; i<N_; i++) {
00132   sum += std::abs(*ptr);
00133   ptr += LDA_;
00134       }
00135       anorm = EPETRA_MAX(anorm, sum);
00136     }
00137   }
00138   UpdateFlops(N_*N_);
00139   return(anorm);
00140 }
00141 
00142 //=============================================================================
00143 int Epetra_SerialSymDenseMatrix::Scale(double ScalarA) {
00144 
00145   int i, j;
00146 
00147   double * ptr;
00148 
00149   if (!Upper()) {
00150     for (j=0; j<N_; j++) {
00151       ptr = A_ + j + j*LDA_;
00152       for (i=j; i<N_; i++) {*ptr = *ptr * ScalarA; ptr++;}
00153     }
00154   }
00155   else {
00156     for (j=0; j<N_; j++) {
00157       ptr = A_ + j*LDA_;
00158       for (i=0; i<j; i++) {*ptr = *ptr * ScalarA; ptr++;}
00159     }
00160   }
00161   UpdateFlops(N_*(N_+1)/2);
00162   return(0);
00163 }
00164 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines