| 1 | // | 
|---|
| 2 | // repl.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 | #ifdef __GNUC__ | 
|---|
| 29 | #pragma implementation | 
|---|
| 30 | #endif | 
|---|
| 31 |  | 
|---|
| 32 | #include <math.h> | 
|---|
| 33 |  | 
|---|
| 34 | #include <util/keyval/keyval.h> | 
|---|
| 35 | #include <math/scmat/repl.h> | 
|---|
| 36 | #include <math/scmat/cmatrix.h> | 
|---|
| 37 | #include <math/scmat/elemop.h> | 
|---|
| 38 |  | 
|---|
| 39 | using namespace sc; | 
|---|
| 40 |  | 
|---|
| 41 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 42 | // ReplSCMatrixKit member functions | 
|---|
| 43 |  | 
|---|
| 44 | static ClassDesc ReplSCMatrixKit_cd( | 
|---|
| 45 | typeid(ReplSCMatrixKit),"ReplSCMatrixKit",1,"public SCMatrixKit", | 
|---|
| 46 | 0, create<ReplSCMatrixKit>, 0); | 
|---|
| 47 |  | 
|---|
| 48 | ReplSCMatrixKit::ReplSCMatrixKit() | 
|---|
| 49 | { | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | ReplSCMatrixKit::ReplSCMatrixKit(const Ref<KeyVal>& keyval): | 
|---|
| 53 | SCMatrixKit(keyval) | 
|---|
| 54 | { | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | ReplSCMatrixKit::~ReplSCMatrixKit() | 
|---|
| 58 | { | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | SCMatrix* | 
|---|
| 62 | ReplSCMatrixKit::matrix(const RefSCDimension&d1, const RefSCDimension&d2) | 
|---|
| 63 | { | 
|---|
| 64 | return new ReplSCMatrix(d1,d2,this); | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | SymmSCMatrix* | 
|---|
| 68 | ReplSCMatrixKit::symmmatrix(const RefSCDimension&d) | 
|---|
| 69 | { | 
|---|
| 70 | return new ReplSymmSCMatrix(d,this); | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | DiagSCMatrix* | 
|---|
| 74 | ReplSCMatrixKit::diagmatrix(const RefSCDimension&d) | 
|---|
| 75 | { | 
|---|
| 76 | return new ReplDiagSCMatrix(d,this); | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | SCVector* | 
|---|
| 80 | ReplSCMatrixKit::vector(const RefSCDimension&d) | 
|---|
| 81 | { | 
|---|
| 82 | return new ReplSCVector(d,this); | 
|---|
| 83 |  | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 87 | // ReplSCMatrixKit member functions | 
|---|
| 88 |  | 
|---|
| 89 | ReplSCMatrixListSubblockIter::ReplSCMatrixListSubblockIter( | 
|---|
| 90 | Access access, | 
|---|
| 91 | const Ref<SCMatrixBlockList> &list, | 
|---|
| 92 | const Ref<MessageGrp> &grp, | 
|---|
| 93 | double *data, | 
|---|
| 94 | int ndata | 
|---|
| 95 | ): | 
|---|
| 96 | SCMatrixListSubblockIter(access, list), | 
|---|
| 97 | grp_(grp), | 
|---|
| 98 | data_(data), | 
|---|
| 99 | ndata_(ndata) | 
|---|
| 100 | { | 
|---|
| 101 | if (access == Write) { | 
|---|
| 102 | for (int i=0; i<ndata; i++) data[i] = 0.0; | 
|---|
| 103 | } | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | ReplSCMatrixListSubblockIter::~ReplSCMatrixListSubblockIter() | 
|---|
| 107 | { | 
|---|
| 108 | if (access() == Write || access() == Accum) { | 
|---|
| 109 | grp_->sum(data_,ndata_); | 
|---|
| 110 | } | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 | /////////////////////////////////////////////////////////////////////// | 
|---|
| 114 | // The static SCMatrixKit members. | 
|---|
| 115 |  | 
|---|
| 116 | static Ref<SCMatrixKit> defaultmatrixkit; | 
|---|
| 117 |  | 
|---|
| 118 | SCMatrixKit* | 
|---|
| 119 | SCMatrixKit::default_matrixkit() | 
|---|
| 120 | { | 
|---|
| 121 | if (defaultmatrixkit.null()) defaultmatrixkit = new ReplSCMatrixKit; | 
|---|
| 122 | return defaultmatrixkit.pointer(); | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|
| 125 | void | 
|---|
| 126 | SCMatrixKit::set_default_matrixkit(const Ref<SCMatrixKit> &k) | 
|---|
| 127 | { | 
|---|
| 128 | defaultmatrixkit = k; | 
|---|
| 129 | } | 
|---|
| 130 |  | 
|---|
| 131 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 132 |  | 
|---|
| 133 | // Local Variables: | 
|---|
| 134 | // mode: c++ | 
|---|
| 135 | // c-file-style: "CLJ" | 
|---|
| 136 | // End: | 
|---|