Kokkos Node API and Local Linear Algebra Kernels Version of the Day
CrsMatrix_UnitTests.cpp
00001 // ************************************************************************
00002 // 
00003 //          Kokkos: A Fast Kernel Package
00004 //              Copyright (2004) Sandia Corporation
00005 // 
00006 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00007 // license for use of this work by or on behalf of the U.S. Government.
00008 // 
00009 // This library is free software; you can redistribute it and/or modify
00010 // it under the terms of the GNU Lesser General Public License as
00011 // published by the Free Software Foundation; either version 2.1 of the
00012 // License, or (at your option) any later version.
00013 //  
00014 // This library is distributed in the hope that it will be useful, but
00015 // WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 //  
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // USA
00022 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00023 // 
00024 // ************************************************************************
00025 //@HEADER
00026 
00027 #include <Teuchos_UnitTestHarness.hpp>
00028 
00029 #include "Kokkos_ConfigDefs.hpp"
00030 #include "Kokkos_DefaultNode.hpp"
00031 #include "Kokkos_DefaultKernels.hpp"
00032 #include "Kokkos_CrsMatrix.hpp"
00033 #include "Kokkos_CrsGraph.hpp"
00034 #include "Kokkos_Version.hpp"
00035 
00036 namespace {
00037 
00038   // static graph * matrix-owned graph
00039   // 1D * 2D
00040   // OptimizeStorage * none
00041 
00042   // empty
00043 
00044   // CrsGraph exception throwing
00045 
00046   // graph/matrix mismatch throwing
00047 
00048   using Kokkos::DefaultNode;
00049   using Kokkos::CrsMatrix;
00050   using Kokkos::CrsGraph;
00051   using Teuchos::ArrayRCP;
00052   using Teuchos::RCP;
00053   using Teuchos::null;
00054   using Teuchos::arcp;
00055 
00056   typedef Kokkos::DefaultNode::DefaultNodeType Node;
00057 
00058   int N = 100;
00059 
00060   TEUCHOS_STATIC_SETUP()
00061   {
00062     Teuchos::CommandLineProcessor &clp = Teuchos::UnitTestRepository::getCLP();
00063     clp.addOutputSetupOptions(true);
00064     clp.setOption("test-size",&N,"Vector length for tests.");
00065   }
00066 
00067   //
00068   // UNIT TESTS
00069   // 
00070 
00071   // intialize using static graph
00072   TEUCHOS_UNIT_TEST( CrsGraph, RuntimeExceptions )
00073   {
00074     typedef Kokkos::DefaultKernels<double,int,Node>::SparseOps SparseOps;
00075     typedef CrsGraph<int,Node,SparseOps>                       Graph;
00076     const size_t N = 10;
00077     RCP<Node> node = Kokkos::DefaultNode::getDefaultNode();
00078     Graph G(N,node);
00079     // set1DStructure array sizes
00080     {
00081       ArrayRCP<size_t>  b_tooSmall(N), b_justRight(N+1), b_tooBig(N+2);
00082       ArrayRCP<size_t>  e_tooSmall(N-1), e_justRight(N), e_tooBig(N+1);
00083       ArrayRCP<int>     inds;
00084       TEST_THROW( G.set1DStructure(inds,b_tooSmall, e_tooSmall),  std::runtime_error );
00085       TEST_THROW( G.set1DStructure(inds,b_tooSmall, e_justRight), std::runtime_error );
00086       TEST_THROW( G.set1DStructure(inds,b_tooSmall, e_tooBig),    std::runtime_error );
00087       TEST_THROW( G.set1DStructure(inds,b_justRight,e_tooSmall), std::runtime_error );
00088       TEST_THROW( G.set1DStructure(inds,b_justRight,e_tooBig),   std::runtime_error );
00089       TEST_THROW( G.set1DStructure(inds,b_tooBig,   e_tooSmall),    std::runtime_error );
00090       TEST_THROW( G.set1DStructure(inds,b_tooBig,   e_justRight),   std::runtime_error );
00091       TEST_THROW( G.set1DStructure(inds,b_tooBig,   e_tooBig),      std::runtime_error );
00092     }
00093     {
00094       ArrayRCP<size_t> begs(N+1), ends(N);
00095       for (size_t i=0; i<N; ++i) {begs[i] = i; ends[i] = i+1;}
00096       begs[N] = N;
00097       ArrayRCP<int> tooFewInds(N-1);
00098       TEST_THROW( G.set1DStructure(tooFewInds, begs,ends), std::runtime_error );
00099     }
00100     // set2DStructure array sizes
00101     {
00102       ArrayRCP<ArrayRCP<int> > inds(N+1);
00103       ArrayRCP<size_t> numEntries(N+1);
00104       TEST_THROW( G.set2DStructure(inds.persistingView(0,N-1), numEntries.persistingView(0,N)), std::runtime_error );
00105       TEST_THROW( G.set2DStructure(inds.persistingView(0,N+1), numEntries.persistingView(0,N)), std::runtime_error );
00106       TEST_THROW( G.set2DStructure(inds.persistingView(0,N), numEntries.persistingView(0,N+1)), std::runtime_error );
00107       TEST_THROW( G.set2DStructure(inds.persistingView(0,N), numEntries.persistingView(0,N-1)), std::runtime_error );
00108     }
00109   }
00110 
00111   // intialize using static graph
00112   TEUCHOS_UNIT_TEST( CrsGraph, StatusTests )
00113   {
00114     typedef Kokkos::DefaultKernels<double,int,Node>::SparseOps SparseOps;
00115     typedef CrsGraph<int,Node,SparseOps>                       Graph;
00116     const size_t N = 10;
00117     RCP<Node> node = Kokkos::DefaultNode::getDefaultNode();
00118     Graph G(N,node);
00119     G.finalize(false);
00120     TEST_EQUALITY_CONST( G.isEmpty(), true );
00121     TEST_EQUALITY_CONST( G.isOptimized(), false );
00122     TEST_EQUALITY_CONST( G.is1DStructure(), false );
00123     TEST_EQUALITY_CONST( G.is2DStructure(), false );
00124     G.finalize(true);
00125     TEST_EQUALITY_CONST( G.isEmpty(), true );
00126     TEST_EQUALITY_CONST( G.isOptimized(), false );
00127     TEST_EQUALITY_CONST( G.is1DStructure(), false );
00128     TEST_EQUALITY_CONST( G.is2DStructure(), false );
00129   }
00130 
00131   // intialize using static graph
00132   TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( CrsMatrix, StaticGraph, Scalar, Ordinal )
00133   {
00134     typedef typename Kokkos::DefaultKernels<Scalar,Ordinal,Node>::SparseOps SparseOps;
00135     typedef CrsGraph<Ordinal,Node,SparseOps>                                    Graph;
00136     typedef CrsMatrix<Scalar,Ordinal,Node,SparseOps>                           Matrix;
00137     const size_t N = 10;
00138     RCP<Node> node = Kokkos::DefaultNode::getDefaultNode();
00139     {
00140       // static graph must be finalized when passed to matrix (empty is okay for this test)
00141       Graph G(N,node);
00142       const Graph &staticG = G;
00143       TEST_THROW( Matrix M1(staticG), std::runtime_error );
00144       G.finalize(false);  // false, true, doesn't matter here
00145       TEST_NOTHROW( Matrix M2(staticG) );
00146     }
00147     // build a non-empty graph, tridiagonal
00148     const size_t testNumEntries = 3*N-2;
00149     ArrayRCP<Ordinal> inds1D(testNumEntries);
00150     ArrayRCP<Scalar > vals1D(testNumEntries);
00151     ArrayRCP<ArrayRCP<Ordinal> > inds2D(N);
00152     ArrayRCP<ArrayRCP<Scalar > > vals2D(N);
00153     ArrayRCP<size_t> begs(N+1), ends(N), numper(N);
00154     {
00155       std::fill( inds1D.begin(), inds1D.end(), 0 );
00156       std::fill( vals1D.begin(), vals1D.end(), 0 );
00157       size_t curoffset = 0;
00158       for (size_t r=0; r < N; ++r) {
00159         if (r > 0 && r < N-1) numper[r] = 3;
00160         else numper[r] = 2;
00161         begs[r] = curoffset;
00162         ends[r] = begs[r] + numper[r];
00163         inds2D[r] = inds1D.persistingView(begs[r],numper[r]);
00164         vals2D[r] = vals1D.persistingView(begs[r],numper[r]);
00165         curoffset += numper[r];
00166       }
00167       begs[N] = curoffset;
00168     }
00169     Graph G(N,node);
00170     TEST_EQUALITY( G.getNumRows(), N );
00171     TEST_EQUALITY( G.getNode(), node );
00172     for (int t=0; t < 4; ++t)
00173     {
00174       const bool submit1D        = (t && 1);
00175       const bool OptimizeStorage = (t && 2);
00176       if (submit1D) {
00177         G.set1DStructure(inds1D, begs, ends);
00178         TEST_EQUALITY_CONST( G.is1DStructure(), true );
00179         TEST_EQUALITY_CONST( G.is2DStructure(), false );
00180         ArrayRCP<Ordinal> chkInds;
00181         ArrayRCP<size_t> chkBegs, chkEnds;
00182         G.get1DStructure(chkInds, chkBegs, chkEnds);
00183         TEST_EQUALITY( inds1D, chkInds );
00184         TEST_EQUALITY( begs, chkBegs );
00185         TEST_EQUALITY( ends, chkEnds );
00186       }
00187       else {
00188         G.set2DStructure(inds2D, numper);
00189         TEST_EQUALITY_CONST( G.is2DStructure(), true );
00190         TEST_EQUALITY_CONST( G.is1DStructure(), false );
00191         ArrayRCP<ArrayRCP<Ordinal> > chkInds;
00192         ArrayRCP<size_t> chkNumPer;
00193         G.get2DStructure(chkInds, chkNumPer);
00194         TEST_EQUALITY( inds2D, chkInds );
00195         TEST_EQUALITY( numper, chkNumPer );
00196       }
00197       TEST_EQUALITY_CONST( G.isFinalized(), false );
00198       TEST_EQUALITY_CONST( G.isOptimized(), false );
00199       TEST_EQUALITY_CONST( G.getNumEntries(), testNumEntries );
00200       G.finalize(OptimizeStorage);
00201       TEST_EQUALITY_CONST( G.isFinalized(), true );
00202       TEST_EQUALITY_CONST( G.isEmpty(), false );
00203       if (OptimizeStorage) {
00204         TEST_EQUALITY_CONST( G.isOptimized(), true );
00205         TEST_EQUALITY_CONST( G.is1DStructure(), true );
00206         TEST_EQUALITY_CONST( G.is2DStructure(), false );
00207         ArrayRCP<Ordinal> chkInds1D;
00208         ArrayRCP<ArrayRCP<Ordinal> > chkInds2D;
00209         ArrayRCP<size_t> chkBegs, chkEnds, chkNumPer;
00210         G.get1DStructure(chkInds1D, chkBegs, chkEnds);
00211         G.get2DStructure(chkInds2D, chkNumPer);
00212         TEST_EQUALITY_CONST( chkInds1D == Teuchos::null, false );
00213         TEST_EQUALITY_CONST( chkBegs   == Teuchos::null, false );
00214         TEST_EQUALITY_CONST( chkEnds   == Teuchos::null, false );
00215         TEST_EQUALITY_CONST( chkInds2D == Teuchos::null, true );
00216         TEST_EQUALITY_CONST( chkNumPer == Teuchos::null, true );
00217       }
00218       else {
00219         TEST_EQUALITY_CONST( G.isOptimized(), false );
00220         TEST_EQUALITY( G.is1DStructure(),  submit1D );
00221         TEST_EQUALITY( G.is2DStructure(), !submit1D );
00222         ArrayRCP<Ordinal> chkInds1D;
00223         ArrayRCP<ArrayRCP<Ordinal> > chkInds2D;
00224         ArrayRCP<size_t> chkBegs, chkEnds, chkNumPer;
00225         G.get1DStructure(chkInds1D, chkBegs, chkEnds);
00226         G.get2DStructure(chkInds2D, chkNumPer);
00227         TEST_EQUALITY( chkInds1D == Teuchos::null, !submit1D );
00228         TEST_EQUALITY( chkBegs   == Teuchos::null, !submit1D );
00229         TEST_EQUALITY( chkEnds   == Teuchos::null, !submit1D );
00230         TEST_EQUALITY( chkInds2D == Teuchos::null,  submit1D );
00231         TEST_EQUALITY( chkNumPer == Teuchos::null,  submit1D );
00232       }
00233       const Graph &staticG = G;
00234       TEST_EQUALITY( staticG.getNumRows(), N );
00235       TEST_EQUALITY( staticG.getNode(), node );
00236       Matrix M(staticG);
00237       TEST_EQUALITY( M.getNumRows(), G.getNumRows() );
00238       TEST_EQUALITY( M.getNumEntries(), G.getNumEntries() );
00239       if (G.is1DStructure()) {
00240         M.set1DValues(vals1D);
00241         TEST_EQUALITY_CONST( M.is1DStructure(), true );
00242         TEST_EQUALITY_CONST( M.is2DStructure(), false );
00243       }
00244       else {
00245         M.set2DValues(vals2D);
00246         TEST_EQUALITY_CONST( M.is2DStructure(), true );
00247         TEST_EQUALITY_CONST( M.is1DStructure(), false );
00248       }
00249       TEST_EQUALITY_CONST( M.isEmpty(), false );        // can only query this pre-finalize for a static graph
00250       TEST_EQUALITY_CONST( M.isFinalized(), false );
00251       if (G.isOptimized() == false) {
00252         TEST_THROW( M.finalize(true), std::runtime_error );
00253         M.finalize(false);
00254       }
00255       else {
00256         // true or false doesn't matter; switch it up (submit1D alternates w.r.t. OptimizeStorge)
00257         M.finalize( submit1D );
00258       }
00259       TEST_EQUALITY_CONST( M.isEmpty(), false );
00260       TEST_EQUALITY_CONST( M.isFinalized(), true );
00261       TEST_EQUALITY_CONST( M.isOptimized(), G.isOptimized() );
00262       {
00263         // test graph clear
00264         G.clear();
00265         TEST_EQUALITY_CONST( G.isFinalized(), false );
00266         TEST_EQUALITY( G.getNumRows(), N );
00267         TEST_EQUALITY( G.getNumEntries(), 0 );
00268         TEST_EQUALITY_CONST( G.is1DStructure(), false );
00269         TEST_EQUALITY_CONST( G.is2DStructure(), false );
00270         ArrayRCP<Ordinal> chkInds1D;
00271         ArrayRCP<ArrayRCP<Ordinal> > chkInds2D;
00272         ArrayRCP<size_t> chkBegs, chkEnds, chkNumPer;
00273         G.get1DStructure(chkInds1D, chkBegs, chkEnds);
00274         G.get2DStructure(chkInds2D, chkNumPer);
00275         TEST_EQUALITY_CONST( chkInds1D == Teuchos::null, true );
00276         TEST_EQUALITY_CONST( chkBegs   == Teuchos::null, true );
00277         TEST_EQUALITY_CONST( chkEnds   == Teuchos::null, true );
00278         TEST_EQUALITY_CONST( chkInds2D == Teuchos::null, true );
00279         TEST_EQUALITY_CONST( chkNumPer == Teuchos::null, true );
00280       }
00281     }
00282   }
00283 
00284   // intialize using static graph
00285   TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( CrsMatrix, DynamicGraph, Scalar, Ordinal )
00286   {
00287     typedef typename Kokkos::DefaultKernels<Scalar,Ordinal,Node>::SparseOps SparseOps;
00288     typedef CrsGraph<Ordinal,Node,SparseOps>                                   Graph;
00289     typedef CrsMatrix<Scalar,Ordinal,Node,SparseOps>                           Matrix;
00290     const size_t N = 10;
00291     RCP<Node> node = Kokkos::DefaultNode::getDefaultNode();
00292 
00293     // build a non-empty graph, tridiagonal
00294     const size_t testNumEntries = 3*N-2;
00295     ArrayRCP<Ordinal> inds1D(testNumEntries);
00296     ArrayRCP<Scalar > vals1D(testNumEntries);
00297     ArrayRCP<ArrayRCP<Ordinal> > inds2D(N);
00298     ArrayRCP<ArrayRCP<Scalar > > vals2D(N);
00299     ArrayRCP<size_t> begs(N+1), ends(N), numper(N);
00300     {
00301       std::fill( inds1D.begin(), inds1D.end(), 0 );
00302       std::fill( vals1D.begin(), vals1D.end(), 0 );
00303       size_t curoffset = 0;
00304       for (size_t r=0; r < N; ++r) {
00305         if (r > 0 && r < N-1) numper[r] = 3;
00306         else numper[r] = 2;
00307         begs[r] = curoffset;
00308         ends[r] = begs[r] + numper[r];
00309         inds2D[r] = inds1D.persistingView(begs[r],numper[r]);
00310         vals2D[r] = vals1D.persistingView(begs[r],numper[r]);
00311         curoffset += numper[r];
00312       }
00313       begs[N] = curoffset;
00314     }
00315     Graph G(N,node);
00316     Matrix M(G);
00317     for (int t=0; t < 4; ++t) {
00318       const bool submit1D        = (t && 1);
00319       const bool OptimizeStorage = (t && 2);
00320       if (submit1D) {
00321         G.set1DStructure(inds1D, begs, ends);
00322         M.set1DValues(vals1D);
00323         TEST_EQUALITY_CONST( G.is1DStructure(), true );
00324         TEST_EQUALITY_CONST( G.is2DStructure(), false );
00325         TEST_EQUALITY_CONST( M.is1DStructure(), true );
00326         TEST_EQUALITY_CONST( M.is2DStructure(), false );
00327         ArrayRCP<Ordinal> chkInds;
00328         ArrayRCP<size_t> chkBegs, chkEnds;
00329         ArrayRCP<Scalar> chkVals;
00330         G.get1DStructure(chkInds, chkBegs, chkEnds);
00331         M.get1DValues(chkVals);
00332         TEST_EQUALITY( inds1D, chkInds );
00333         TEST_EQUALITY( begs, chkBegs );
00334         TEST_EQUALITY( ends, chkEnds );
00335         TEST_EQUALITY( vals1D, chkVals );
00336       }
00337       else {
00338         G.set2DStructure(inds2D, numper);
00339         M.set2DValues(vals2D);
00340         TEST_EQUALITY_CONST( G.is2DStructure(), true );
00341         TEST_EQUALITY_CONST( G.is1DStructure(), false );
00342         TEST_EQUALITY_CONST( M.is2DStructure(), true );
00343         TEST_EQUALITY_CONST( M.is1DStructure(), false );
00344         ArrayRCP<ArrayRCP<Ordinal> > chkInds;
00345         ArrayRCP<ArrayRCP<Scalar> > chkVals;
00346         ArrayRCP<size_t> chkNumPer;
00347         G.get2DStructure(chkInds, chkNumPer);
00348         M.get2DValues(chkVals);
00349         TEST_EQUALITY( inds2D, chkInds );
00350         TEST_EQUALITY( numper, chkNumPer );
00351         TEST_EQUALITY( vals2D, chkVals );
00352       }
00353       TEST_EQUALITY_CONST( G.isFinalized(), false );
00354       TEST_EQUALITY_CONST( G.isOptimized(), false );
00355       TEST_EQUALITY_CONST( G.getNumEntries(), testNumEntries );
00356       TEST_EQUALITY_CONST( M.isFinalized(), false );
00357       TEST_EQUALITY_CONST( M.isOptimized(), false );
00358       M.finalize(OptimizeStorage);
00359       TEST_EQUALITY_CONST( G.isFinalized(), true );
00360       TEST_EQUALITY_CONST( G.isEmpty(), false );
00361       TEST_EQUALITY_CONST( M.isFinalized(), true );
00362       TEST_EQUALITY_CONST( M.isEmpty(), false );
00363       if (OptimizeStorage) {
00364         TEST_EQUALITY_CONST( G.isOptimized(), true );
00365         TEST_EQUALITY_CONST( G.is1DStructure(), true );
00366         TEST_EQUALITY_CONST( G.is2DStructure(), false );
00367         TEST_EQUALITY_CONST( M.isOptimized(), true );
00368         TEST_EQUALITY_CONST( M.is1DStructure(), true );
00369         TEST_EQUALITY_CONST( M.is2DStructure(), false );
00370         ArrayRCP<Ordinal> chkInds1D;
00371         ArrayRCP<ArrayRCP<Ordinal> > chkInds2D;
00372         ArrayRCP<ArrayRCP<Scalar> >  chkVals2D;
00373         ArrayRCP<size_t> chkBegs, chkEnds, chkNumPer;
00374         ArrayRCP<Scalar> chkVals1D;
00375         G.get1DStructure(chkInds1D, chkBegs, chkEnds);
00376         G.get2DStructure(chkInds2D, chkNumPer);
00377         M.get1DValues(chkVals1D);
00378         M.get2DValues(chkVals2D);
00379         TEST_EQUALITY_CONST( chkInds1D == Teuchos::null, false );
00380         TEST_EQUALITY_CONST( chkVals1D == Teuchos::null, false );
00381         TEST_EQUALITY_CONST( chkBegs   == Teuchos::null, false );
00382         TEST_EQUALITY_CONST( chkEnds   == Teuchos::null, false );
00383         TEST_EQUALITY_CONST( chkInds2D == Teuchos::null, true );
00384         TEST_EQUALITY_CONST( chkVals2D == Teuchos::null, true );
00385         TEST_EQUALITY_CONST( chkNumPer == Teuchos::null, true );
00386       }
00387       else {
00388         TEST_EQUALITY_CONST( G.isOptimized(), false );
00389         TEST_EQUALITY( G.is1DStructure(),  submit1D );
00390         TEST_EQUALITY( G.is2DStructure(), !submit1D );
00391         TEST_EQUALITY_CONST( M.isOptimized(), false );
00392         TEST_EQUALITY( M.is1DStructure(),  submit1D );
00393         TEST_EQUALITY( M.is2DStructure(), !submit1D );
00394         ArrayRCP<Ordinal> chkInds1D;
00395         ArrayRCP<Scalar>  chkVals1D;
00396         ArrayRCP<ArrayRCP<Ordinal> > chkInds2D;
00397         ArrayRCP<ArrayRCP<Scalar> >  chkVals2D;
00398         ArrayRCP<size_t> chkBegs, chkEnds, chkNumPer;
00399         G.get1DStructure(chkInds1D, chkBegs, chkEnds);
00400         G.get2DStructure(chkInds2D, chkNumPer);
00401         M.get1DValues(chkVals1D);
00402         M.get2DValues(chkVals2D);
00403         TEST_EQUALITY( chkInds1D == Teuchos::null, !submit1D );
00404         TEST_EQUALITY( chkVals1D == Teuchos::null, !submit1D );
00405         TEST_EQUALITY( chkBegs   == Teuchos::null, !submit1D );
00406         TEST_EQUALITY( chkEnds   == Teuchos::null, !submit1D );
00407         TEST_EQUALITY( chkInds2D == Teuchos::null,  submit1D );
00408         TEST_EQUALITY( chkVals2D == Teuchos::null,  submit1D );
00409         TEST_EQUALITY( chkNumPer == Teuchos::null,  submit1D );
00410       }
00411       {
00412         // test matrix and graph clear
00413         M.clear();
00414         TEST_EQUALITY( M.getNumRows(), N );
00415         TEST_EQUALITY( G.getNumRows(), N );
00416         TEST_EQUALITY_CONST( G.getNumEntries() != 0, true );
00417         TEST_EQUALITY_CONST( G.is1DStructure() || G.is2DStructure(), true );
00418         TEST_EQUALITY_CONST( M.isFinalized(), false );
00419         TEST_EQUALITY_CONST( G.isFinalized(), true );
00420         G.clear();
00421         TEST_EQUALITY( G.getNumRows(), N );
00422         TEST_EQUALITY_CONST( G.getNumEntries() == 0, true );
00423         TEST_EQUALITY_CONST( G.is1DStructure(), false );
00424         TEST_EQUALITY_CONST( G.is2DStructure(), false );
00425         TEST_EQUALITY_CONST( G.isFinalized(), false );
00426         ArrayRCP<Ordinal> chkInds1D;
00427         ArrayRCP<Scalar>  chkVals1D;
00428         ArrayRCP<ArrayRCP<Ordinal> > chkInds2D;
00429         ArrayRCP<ArrayRCP<Scalar> >  chkVals2D;
00430         ArrayRCP<size_t> chkBegs, chkEnds, chkNumPer;
00431         G.get1DStructure(chkInds1D, chkBegs, chkEnds);
00432         G.get2DStructure(chkInds2D, chkNumPer);
00433         M.get1DValues(chkVals1D);
00434         M.get2DValues(chkVals2D);
00435         TEST_EQUALITY_CONST( chkInds1D == Teuchos::null, true );
00436         TEST_EQUALITY_CONST( chkVals1D == Teuchos::null, true );
00437         TEST_EQUALITY_CONST( chkBegs   == Teuchos::null, true );
00438         TEST_EQUALITY_CONST( chkEnds   == Teuchos::null, true );
00439         TEST_EQUALITY_CONST( chkInds2D == Teuchos::null, true );
00440         TEST_EQUALITY_CONST( chkVals2D == Teuchos::null, true );
00441         TEST_EQUALITY_CONST( chkNumPer == Teuchos::null, true );
00442       }
00443     }
00444   }
00445 
00446   // bad ends
00447   TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( CrsGraph, BadEnds, Ordinal )
00448   {
00449     typedef typename Kokkos::DefaultKernels<float,Ordinal,Node>::SparseOps SparseOps;
00450     typedef CrsGraph<Ordinal,Node,SparseOps>                                   Graph;
00451     const size_t N = 1;
00452     RCP<Node> node = Kokkos::DefaultNode::getDefaultNode();
00453 
00454     // build a null-size graph
00455     Graph G(N,node);
00456     {
00457       ArrayRCP<size_t> begs, ends;
00458       ArrayRCP<Ordinal> inds1D;
00459       begs = arcp<size_t>(N+1);
00460       ends = arcp<size_t>(N);
00461       //
00462 #ifdef HAVE_KOKKOS_DEBUG
00463       begs[0] = 0; begs[1] = 0;
00464       ends[0] = 1;  // ends causes rows to overlap; not consistent
00465       TEST_THROW( G.set1DStructure(inds1D, begs, ends), std::runtime_error );
00466 #endif
00467       //
00468       begs[0] = 0; begs[1] = 2; // begs size is larger than allocation in inds1D
00469       ends[0] = 0;
00470       inds1D = arcp<Ordinal>(1);
00471       TEST_THROW( G.set1DStructure(inds1D, begs, ends), std::runtime_error );
00472       // 
00473       begs[0] = 0; begs[1] = 1;
00474       ends[0] = 0;
00475       // this allocation is allowed to be too large, w.r.t. begs
00476       inds1D = arcp<Ordinal>(2);
00477       G.set1DStructure(inds1D, begs, ends);
00478     }
00479   }
00480 
00481   // no rows
00482   TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( CrsGraph, NoRows, Ordinal )
00483   {
00484     typedef typename Kokkos::DefaultKernels<float,Ordinal,Node>::SparseOps SparseOps;
00485     typedef CrsGraph<Ordinal,Node,SparseOps>                                   Graph;
00486     const size_t N = 0;
00487     RCP<Node> node = Kokkos::DefaultNode::getDefaultNode();
00488 
00489     // build a null-size graph
00490     Graph G(N,node);
00491     {
00492       ArrayRCP<size_t> begs, ends;
00493       ArrayRCP<Ordinal> inds1D;
00494       begs = null;
00495       ends = null;
00496       inds1D = null;
00497       // begs is null; not allowed
00498       TEST_THROW( G.set1DStructure(inds1D, begs, ends), std::runtime_error );
00499       begs = arcp<size_t>(1);
00500       begs[0] = 0;
00501       G.set1DStructure(inds1D, begs, ends);
00502       begs = null;
00503       ends = null;
00504       inds1D = null;
00505       G.get1DStructure(inds1D, begs, ends);
00506       TEST_EQUALITY_CONST( begs == null, false );
00507       TEST_EQUALITY_CONST( ends == null, true );
00508       TEST_EQUALITY_CONST( inds1D == null, true );
00509     }
00510   }
00511 
00512  #define UNIT_TEST_GROUP_ORDINAL_SCALAR( ORDINAL, SCALAR ) \
00513        TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( CrsMatrix, StaticGraph,  SCALAR, ORDINAL ) \
00514        TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( CrsMatrix, DynamicGraph, SCALAR, ORDINAL )
00515 
00516  #define UNIT_TEST_GROUP_ORDINAL( ORDINAL ) \
00517           TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( CrsGraph, NoRows,  ORDINAL ) \
00518           TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( CrsGraph, BadEnds,  ORDINAL ) \
00519           UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, int) \
00520           UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, float)
00521       UNIT_TEST_GROUP_ORDINAL(int)
00522       typedef short int ShortInt; UNIT_TEST_GROUP_ORDINAL(ShortInt)
00523 
00524 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends