| [0b990d] | 1 | // | 
|---|
|  | 2 | // localtest.cc | 
|---|
|  | 3 | // | 
|---|
|  | 4 | // Copyright (C) 1996 Limit Point Systems, Inc. | 
|---|
|  | 5 | // | 
|---|
|  | 6 | // Author: Curtis Janssen <cljanss@limitpt.com> | 
|---|
|  | 7 | // Maintainer: LPS | 
|---|
|  | 8 | // | 
|---|
|  | 9 | // This file is part of the SC Toolkit. | 
|---|
|  | 10 | // | 
|---|
|  | 11 | // The SC Toolkit is free software; you can redistribute it and/or modify | 
|---|
|  | 12 | // it under the terms of the GNU Library General Public License as published by | 
|---|
|  | 13 | // the Free Software Foundation; either version 2, or (at your option) | 
|---|
|  | 14 | // any later version. | 
|---|
|  | 15 | // | 
|---|
|  | 16 | // The SC Toolkit is distributed in the hope that it will be useful, | 
|---|
|  | 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 19 | // GNU Library General Public License for more details. | 
|---|
|  | 20 | // | 
|---|
|  | 21 | // You should have received a copy of the GNU Library General Public License | 
|---|
|  | 22 | // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to | 
|---|
|  | 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 
|---|
|  | 24 | // | 
|---|
|  | 25 | // The U.S. Government is granted a limited license as per AL 91-7. | 
|---|
|  | 26 | // | 
|---|
|  | 27 |  | 
|---|
|  | 28 | #include <util/misc/formio.h> | 
|---|
|  | 29 | #include <util/group/pregtime.h> | 
|---|
|  | 30 | #include <util/keyval/keyval.h> | 
|---|
|  | 31 | #include <math/scmat/local.h> | 
|---|
|  | 32 |  | 
|---|
|  | 33 | using namespace sc; | 
|---|
|  | 34 |  | 
|---|
|  | 35 | void matrixtest(Ref<SCMatrixKit> kit, Ref<KeyVal> keyval, | 
|---|
|  | 36 | RefSCDimension d1,RefSCDimension d2,RefSCDimension d3, | 
|---|
|  | 37 | bool have_svd); | 
|---|
|  | 38 |  | 
|---|
|  | 39 | main(int argc, char *argv[]) | 
|---|
|  | 40 | { | 
|---|
|  | 41 | char *infile = SRCDIR "/matrixtest.in"; | 
|---|
|  | 42 |  | 
|---|
|  | 43 | if (argc > 1) | 
|---|
|  | 44 | infile = argv[1]; | 
|---|
|  | 45 |  | 
|---|
|  | 46 | Ref<KeyVal> keyval = new ParsedKeyVal(infile); | 
|---|
|  | 47 |  | 
|---|
|  | 48 | Ref<MessageGrp> msg = MessageGrp::initial_messagegrp(argc, argv); | 
|---|
|  | 49 |  | 
|---|
|  | 50 | if (msg.null()) { | 
|---|
|  | 51 | msg << keyval->describedclassvalue("messagegrp"); | 
|---|
|  | 52 |  | 
|---|
|  | 53 | if (msg.null()) { | 
|---|
|  | 54 | std::cerr << indent << "Couldn't initialize MessageGrp\n"; | 
|---|
|  | 55 | abort(); | 
|---|
|  | 56 | } | 
|---|
|  | 57 | } | 
|---|
|  | 58 |  | 
|---|
|  | 59 | MessageGrp::set_default_messagegrp(msg); | 
|---|
|  | 60 |  | 
|---|
|  | 61 | Ref<RegionTimer> tim = new ParallelRegionTimer(msg,"matrixtest",1,1); | 
|---|
|  | 62 | RegionTimer::set_default_regiontimer(tim); | 
|---|
|  | 63 |  | 
|---|
|  | 64 | SCFormIO::set_printnode(0); | 
|---|
|  | 65 |  | 
|---|
|  | 66 | Ref<SCMatrixKit> kit = new LocalSCMatrixKit; | 
|---|
|  | 67 | RefSCDimension d1; d1 << keyval->describedclassvalue("d1"); | 
|---|
|  | 68 | RefSCDimension d2; d2 << keyval->describedclassvalue("d2"); | 
|---|
|  | 69 | RefSCDimension d3; d3 << keyval->describedclassvalue("d3"); | 
|---|
|  | 70 |  | 
|---|
|  | 71 | matrixtest(kit,keyval,d1,d2,d3,true); | 
|---|
|  | 72 |  | 
|---|
|  | 73 | #if 0 | 
|---|
|  | 74 | RefSCDimension m = d1; | 
|---|
|  | 75 | RefSCDimension n = d2; | 
|---|
|  | 76 | RefSCDimension p = ((m.n() < n.n()) ? m:n); | 
|---|
|  | 77 | RefSCMatrix A(m,n,kit); | 
|---|
|  | 78 | RefSCMatrix U(m,m,kit); | 
|---|
|  | 79 | RefSCMatrix V(n,n,kit); | 
|---|
|  | 80 | RefDiagSCMatrix sigma(p,kit); | 
|---|
|  | 81 |  | 
|---|
|  | 82 | A.randomize(); | 
|---|
|  | 83 | A.svd(U,sigma,V); | 
|---|
|  | 84 |  | 
|---|
|  | 85 | A.print("A"); | 
|---|
|  | 86 | U.print("U"); | 
|---|
|  | 87 | (U*U.t()).print("U*U.t()"); | 
|---|
|  | 88 | (U.t()*U).print("U.t()*U"); | 
|---|
|  | 89 | sigma.print("sigma"); | 
|---|
|  | 90 | V.print("V"); | 
|---|
|  | 91 | (V*V.t()).print("V*V.t()"); | 
|---|
|  | 92 | (V.t()*V).print("V.t()*V"); | 
|---|
|  | 93 | RefSCMatrix sigmamat(m,n,kit); | 
|---|
|  | 94 | sigmamat.assign(0.0); | 
|---|
|  | 95 | for (i=0; i<p.n(); i++) sigmamat(i,i) = sigma(i); | 
|---|
|  | 96 | (U*sigmamat*V.t()).print("U*sigmamat*V.t()"); | 
|---|
|  | 97 | #endif | 
|---|
|  | 98 |  | 
|---|
|  | 99 | return 0; | 
|---|
|  | 100 | } | 
|---|
|  | 101 |  | 
|---|
|  | 102 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 103 |  | 
|---|
|  | 104 | // Local Variables: | 
|---|
|  | 105 | // mode: c++ | 
|---|
|  | 106 | // c-file-style: "CLJ" | 
|---|
|  | 107 | // End: | 
|---|