| [0b990d] | 1 | //
 | 
|---|
 | 2 | // dim.h
 | 
|---|
 | 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 interface
 | 
|---|
 | 30 | #endif
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | #ifndef _math_scmat_dim_h
 | 
|---|
 | 33 | #define _math_scmat_dim_h
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | #include <util/keyval/keyval.h>
 | 
|---|
 | 36 | #include <util/state/state.h>
 | 
|---|
 | 37 | 
 | 
|---|
 | 38 | namespace sc {
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 | class RefSCDimension;
 | 
|---|
 | 41 | /** SCBlockInfo contains blocking information for the SCDimension class.
 | 
|---|
 | 42 |     There are really two ways that it can contain blocking information.  In
 | 
|---|
 | 43 |     the first way, a vector of block offsets and block sizes is stored.
 | 
|---|
 | 44 |     The second method is only used by those specializations created by the
 | 
|---|
 | 45 |     BlockedSCMatrixKit class.  In this method the blocking information is
 | 
|---|
 | 46 |     stored as subdimensions of type SCDimension.  If both methods are used,
 | 
|---|
 | 47 |     they must be used consistently.  That is, the number, sizes, and order
 | 
|---|
 | 48 |     of the blocks must match the number, sizes, and order of the
 | 
|---|
 | 49 |     SCDimension objects.  */
 | 
|---|
 | 50 | class SCBlockInfo: public SavableState {
 | 
|---|
 | 51 |   protected:
 | 
|---|
 | 52 |     int n_;
 | 
|---|
 | 53 |     int nblocks_;
 | 
|---|
 | 54 |     int *start_;
 | 
|---|
 | 55 |     int *size_;
 | 
|---|
 | 56 |     RefSCDimension *subdims_;
 | 
|---|
 | 57 |     void init_start();
 | 
|---|
 | 58 |   public:
 | 
|---|
 | 59 |     /// Create a SCBlockInfo object.
 | 
|---|
 | 60 |     SCBlockInfo(int n, int nblocks = 0, const int *blocksizes = 0);
 | 
|---|
 | 61 |     SCBlockInfo(StateIn&);
 | 
|---|
 | 62 |     /** The KeyVal constructor.
 | 
|---|
 | 63 |         <dl>
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 |         <dt><tt>sizes</tt><dd> This is a vector giving the size of each
 | 
|---|
 | 66 |         subblock.  There is no default.
 | 
|---|
 | 67 | 
 | 
|---|
 | 68 |         <dt><tt>subdims</tt><dd> If this vector is given there is must be
 | 
|---|
 | 69 |         entry for each entry in the sizes vector.  Each entry is an
 | 
|---|
 | 70 |         SCDimension object.  The default is to not store subdimension
 | 
|---|
 | 71 |         information.
 | 
|---|
 | 72 | 
 | 
|---|
 | 73 |         </dl> */
 | 
|---|
 | 74 |     SCBlockInfo(const Ref<KeyVal>& keyval);
 | 
|---|
 | 75 | 
 | 
|---|
 | 76 |     ~SCBlockInfo();
 | 
|---|
 | 77 |     void save_data_state(StateOut&);
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 |     /// Return nonzero if this is equivalent to bi.
 | 
|---|
 | 80 |     int equiv(SCBlockInfo *bi);
 | 
|---|
 | 81 |     /// Return the total number of elements.
 | 
|---|
 | 82 |     int nelem() const { return n_; }
 | 
|---|
 | 83 |     /// Return the number of blocks.
 | 
|---|
 | 84 |     int nblock() const { return nblocks_; }
 | 
|---|
 | 85 |     /// Return the starting index for block i.
 | 
|---|
 | 86 |     int start(int i) const { return start_[i]; }
 | 
|---|
 | 87 |     /// Return the size of block i.
 | 
|---|
 | 88 |     int size(int i) const { return size_[i]; }
 | 
|---|
 | 89 |     ///  Return the last index + 1 for block i.
 | 
|---|
 | 90 |     int fence(int i) const { return start_[i] + size_[i]; }
 | 
|---|
 | 91 | 
 | 
|---|
 | 92 |     void elem_to_block(int i, int &block, int &offset);
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 |     /// Retreive subdimension information.
 | 
|---|
 | 95 |     RefSCDimension subdim(int i);
 | 
|---|
 | 96 |     /** Set subdimension information.  The dimension dim and index i must
 | 
|---|
 | 97 |         be consistent with the nblocks and blocksizes information given to
 | 
|---|
 | 98 |         the constructor. */
 | 
|---|
 | 99 |     void set_subdim(int i, const RefSCDimension &dim);
 | 
|---|
 | 100 | 
 | 
|---|
 | 101 |     /// Print the object to the stream o.
 | 
|---|
 | 102 |     void print(std::ostream&o=ExEnv::out0()) const;
 | 
|---|
 | 103 | };
 | 
|---|
 | 104 | 
 | 
|---|
 | 105 | 
 | 
|---|
 | 106 | /** The SCDimension class is used to determine the size and blocking of
 | 
|---|
 | 107 |     matrices.  The blocking information is stored by an object of class
 | 
|---|
 | 108 |     SCBlockInfo.  */
 | 
|---|
 | 109 | class SCDimension: public SavableState {
 | 
|---|
 | 110 |   protected:
 | 
|---|
 | 111 |     char *name_;
 | 
|---|
 | 112 |     int n_;
 | 
|---|
 | 113 |     Ref<SCBlockInfo> blocks_;
 | 
|---|
 | 114 |     SCDimension(const char* name = 0);
 | 
|---|
 | 115 |   public:
 | 
|---|
 | 116 |     /** Create a dimension with an optional name.  The name is a copy of
 | 
|---|
 | 117 |         the '0' terminated string name. */
 | 
|---|
 | 118 |     SCDimension(int n, const char* name = 0);
 | 
|---|
 | 119 |     SCDimension(const Ref<SCBlockInfo>&, const char *name = 0);
 | 
|---|
 | 120 |     SCDimension(int n, int nblocks, const int *blocksizes = 0,
 | 
|---|
 | 121 |                 const char* name = 0);
 | 
|---|
 | 122 |     /** The KeyVal constructor.
 | 
|---|
 | 123 |         <dl>
 | 
|---|
 | 124 | 
 | 
|---|
 | 125 |         <dt><tt>n</tt><dd> This gives size of the dimension.  One of n or
 | 
|---|
 | 126 |         blocks is required.
 | 
|---|
 | 127 | 
 | 
|---|
 | 128 |         <dt><tt>blocks</tt><dd> The block information for the dimension can
 | 
|---|
 | 129 |         be given as a SCBlockInfo object.  One of n or blocks is required.
 | 
|---|
 | 130 | 
 | 
|---|
 | 131 |         </dl> */
 | 
|---|
 | 132 |     SCDimension(const Ref<KeyVal>&);
 | 
|---|
 | 133 |     SCDimension(StateIn&s);
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 |     ~SCDimension();
 | 
|---|
 | 136 |     void save_data_state(StateOut&);
 | 
|---|
 | 137 | 
 | 
|---|
 | 138 |     /// Test to see if two dimensions are equivalent.
 | 
|---|
 | 139 |     int equiv(const SCDimension*) const;
 | 
|---|
 | 140 |     
 | 
|---|
 | 141 |     /// Return the dimension.
 | 
|---|
 | 142 |     int n() const { return n_; }
 | 
|---|
 | 143 |     /** Return the name of the dimension.  If no name was given to the
 | 
|---|
 | 144 |         constructor, then return 0. */
 | 
|---|
 | 145 |     const char* name() const { return name_; }
 | 
|---|
 | 146 | 
 | 
|---|
 | 147 |     /// Return the blocking information for this dimension.
 | 
|---|
 | 148 |     Ref<SCBlockInfo> blocks() { return blocks_; }
 | 
|---|
 | 149 | 
 | 
|---|
 | 150 |     /// Print information about this dimension to o.
 | 
|---|
 | 151 |     void print(std::ostream&o=ExEnv::out0()) const;
 | 
|---|
 | 152 | };
 | 
|---|
 | 153 | 
 | 
|---|
 | 154 | /** The RefSCDimension class is a smart pointer to an SCDimension
 | 
|---|
 | 155 |     specialization. */
 | 
|---|
 | 156 | class RefSCDimension: public Ref<SCDimension> {
 | 
|---|
 | 157 |     // standard overrides
 | 
|---|
 | 158 |   public:
 | 
|---|
 | 159 |     /** Initializes the dimension pointer to 0.  The
 | 
|---|
 | 160 |         reference must be initialized before it is used. */
 | 
|---|
 | 161 |     RefSCDimension();
 | 
|---|
 | 162 |     /// Make this and d refer to the same SCDimension.
 | 
|---|
 | 163 |     RefSCDimension(const RefSCDimension& d);
 | 
|---|
 | 164 |     /// Make this refer to d.
 | 
|---|
 | 165 |     RefSCDimension(SCDimension *d);
 | 
|---|
 | 166 | 
 | 
|---|
 | 167 |     ~RefSCDimension();
 | 
|---|
 | 168 |     /// Make this refer to d.
 | 
|---|
 | 169 |     RefSCDimension& operator=(SCDimension* d);
 | 
|---|
 | 170 | 
 | 
|---|
 | 171 |     RefSCDimension& operator<<(RefCount*);
 | 
|---|
 | 172 |     RefSCDimension& operator<<(const RefBase &);
 | 
|---|
 | 173 |     /// Make this and d refer to the same SCDimension.
 | 
|---|
 | 174 |     RefSCDimension& operator=(const RefSCDimension & d);
 | 
|---|
 | 175 | 
 | 
|---|
 | 176 |     // dimension specific functions
 | 
|---|
 | 177 |   public:
 | 
|---|
 | 178 |     /// Return the dimension.
 | 
|---|
 | 179 |     operator int() const;
 | 
|---|
 | 180 |     int n() const;
 | 
|---|
 | 181 | 
 | 
|---|
 | 182 |     void print(std::ostream&o=ExEnv::out0()) const;
 | 
|---|
 | 183 | };
 | 
|---|
 | 184 | 
 | 
|---|
 | 185 | }
 | 
|---|
 | 186 | 
 | 
|---|
 | 187 | #endif
 | 
|---|
 | 188 | 
 | 
|---|
 | 189 | // Local Variables:
 | 
|---|
 | 190 | // mode: c++
 | 
|---|
 | 191 | // c-file-style: "CLJ"
 | 
|---|
 | 192 | // End:
 | 
|---|