| [658] | 1 | /***************************************************************************
 | 
|---|
 | 2 |  * blitz/array/interlace.cc
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  * $Id: interlace.cc,v 1.1.1.1 1999-11-26 16:37:07 ansari Exp $
 | 
|---|
 | 5 |  *
 | 
|---|
 | 6 |  * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
 | 
|---|
 | 7 |  *
 | 
|---|
 | 8 |  * This program is free software; you can redistribute it and/or
 | 
|---|
 | 9 |  * modify it under the terms of the GNU General Public License
 | 
|---|
 | 10 |  * as published by the Free Software Foundation; either version 2
 | 
|---|
 | 11 |  * of the License, or (at your option) any later version.
 | 
|---|
 | 12 |  *
 | 
|---|
 | 13 |  * This program is distributed in the hope that it will be useful,
 | 
|---|
 | 14 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 15 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 16 |  * GNU General Public License for more details.
 | 
|---|
 | 17 |  *
 | 
|---|
 | 18 |  * Suggestions:          blitz-suggest@cybervision.com
 | 
|---|
 | 19 |  * Bugs:                 blitz-bugs@cybervision.com
 | 
|---|
 | 20 |  *
 | 
|---|
 | 21 |  * For more information, please see the Blitz++ Home Page:
 | 
|---|
 | 22 |  *    http://seurat.uwaterloo.ca/blitz/
 | 
|---|
 | 23 |  *
 | 
|---|
 | 24 |  ***************************************************************************
 | 
|---|
 | 25 |  * $Log: not supported by cvs2svn $
 | 
|---|
 | 26 | // Revision 1.1.1.1  1999/04/09  17:59:03  ansari
 | 
|---|
 | 27 | // Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99
 | 
|---|
 | 28 | //
 | 
|---|
 | 29 |  *
 | 
|---|
 | 30 |  */
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | #ifndef BZ_ARRAYINTERLACE_CC
 | 
|---|
 | 33 | #define BZ_ARRAYINTERLACE_CC
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | #ifndef BZ_ARRAY_H
 | 
|---|
 | 36 |  #error <blitz/array/interlace.cc> must be included via <blitz/array.h>
 | 
|---|
 | 37 | #endif
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 | #ifndef BZ_ARRAYSHAPE_H
 | 
|---|
 | 40 |  #include <blitz/array/shape.h>
 | 
|---|
 | 41 | #endif
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 | BZ_NAMESPACE(blitz)
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 | /*
 | 
|---|
 | 46 |  * This header provides two collections of routines:
 | 
|---|
 | 47 |  *
 | 
|---|
 | 48 |  * interlaceArrays(shape, A1, A2, ...);
 | 
|---|
 | 49 |  * allocateArrays(shape, A1, A2, ...);
 | 
|---|
 | 50 |  *
 | 
|---|
 | 51 |  * interlaceArrays allocates a set of arrays so that their data is
 | 
|---|
 | 52 |  * interlaced.  For example,
 | 
|---|
 | 53 |  *
 | 
|---|
 | 54 |  * Array<int,2> A, B;
 | 
|---|
 | 55 |  * interlaceArrays(shape(10,10), A, B);
 | 
|---|
 | 56 |  *
 | 
|---|
 | 57 |  * sets up the array storage so that A(0,0) is followed by B(0,0) in
 | 
|---|
 | 58 |  * memory; then A(0,1) and B(0,1), and so on.
 | 
|---|
 | 59 |  *
 | 
|---|
 | 60 |  * The allocateArrays() routines may or may not interlace the data,
 | 
|---|
 | 61 |  * depending on whether interlacing is advantageous for the architecture.
 | 
|---|
 | 62 |  * This is controlled by the setting of BZ_INTERLACE_ARRAYS in
 | 
|---|
 | 63 |  * <blitz/tuning.h>.
 | 
|---|
 | 64 |  */
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 | // Warning: Can't instantiate TinyVector<Range,N> because causes
 | 
|---|
 | 67 | // conflict between TinyVector<T,N>::operator=(T) and
 | 
|---|
 | 68 | // TinyVector<T,N>::operator=(Range)
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 | // NEEDS_WORK -- also shape for up to N=11
 | 
|---|
 | 71 | // NEEDS_WORK -- shape(Range r1, Range r2, ...) (return TinyVector<Range,n>)
 | 
|---|
 | 72 | //               maybe use Domain objects
 | 
|---|
 | 73 | // NEEDS_WORK -- doesn't make a lot of sense for user to provide a
 | 
|---|
 | 74 | //               GeneralArrayStorage<N_rank+1>
 | 
|---|
 | 75 | 
 | 
|---|
 | 76 | template<class T_numtype>
 | 
|---|
 | 77 | void makeInterlacedArray(Array<T_numtype,2>& mainArray,
 | 
|---|
 | 78 |     Array<T_numtype,1>& subarray, int slice)
 | 
|---|
 | 79 | {
 | 
|---|
 | 80 |     Array<T_numtype,1> tmp = mainArray(Range::all(), slice);
 | 
|---|
 | 81 |     subarray.reference(tmp);
 | 
|---|
 | 82 | }
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 | template<class T_numtype>
 | 
|---|
 | 85 | void makeInterlacedArray(Array<T_numtype,3>& mainArray,
 | 
|---|
 | 86 |     Array<T_numtype,2>& subarray, int slice)
 | 
|---|
 | 87 | {
 | 
|---|
 | 88 |     Array<T_numtype,2> tmp = mainArray(Range::all(), Range::all(), 
 | 
|---|
 | 89 |         slice);
 | 
|---|
 | 90 |     subarray.reference(tmp);
 | 
|---|
 | 91 | }
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 | template<class T_numtype>
 | 
|---|
 | 94 | void makeInterlacedArray(Array<T_numtype,4>& mainArray,
 | 
|---|
 | 95 |     Array<T_numtype,3>& subarray, int slice)
 | 
|---|
 | 96 | {
 | 
|---|
 | 97 |     Array<T_numtype,3> tmp = mainArray(Range::all(), Range::all(), 
 | 
|---|
 | 98 |         Range::all(), slice);
 | 
|---|
 | 99 |     subarray.reference(tmp);
 | 
|---|
 | 100 | }
 | 
|---|
 | 101 | 
 | 
|---|
 | 102 | // These routines always allocate interlaced arrays
 | 
|---|
 | 103 | template<class T_numtype, int N_rank>
 | 
|---|
 | 104 | void interlaceArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 105 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2)
 | 
|---|
 | 106 | {
 | 
|---|
 | 107 |     GeneralArrayStorage<N_rank+1> storage;
 | 
|---|
 | 108 |     Array<T_numtype, N_rank+1> array(shape, 2, storage);
 | 
|---|
 | 109 |     makeInterlacedArray(array, a1, 0);
 | 
|---|
 | 110 |     makeInterlacedArray(array, a2, 1);
 | 
|---|
 | 111 | }
 | 
|---|
 | 112 | 
 | 
|---|
 | 113 | template<class T_numtype, int N_rank>
 | 
|---|
 | 114 | void interlaceArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 115 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 116 |     Array<T_numtype,N_rank>& a3)
 | 
|---|
 | 117 | {
 | 
|---|
 | 118 |     GeneralArrayStorage<N_rank+1> storage;
 | 
|---|
 | 119 |     Array<T_numtype, N_rank+1> array(shape, 3, storage);
 | 
|---|
 | 120 |     makeInterlacedArray(array, a1, 0);
 | 
|---|
 | 121 |     makeInterlacedArray(array, a2, 1);
 | 
|---|
 | 122 |     makeInterlacedArray(array, a3, 2);
 | 
|---|
 | 123 | }
 | 
|---|
 | 124 | 
 | 
|---|
 | 125 | template<class T_numtype, int N_rank>
 | 
|---|
 | 126 | void interlaceArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 127 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 128 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4)
 | 
|---|
 | 129 | {
 | 
|---|
 | 130 |     GeneralArrayStorage<N_rank+1> storage;
 | 
|---|
 | 131 |     Array<T_numtype, N_rank+1> array(shape, 4, storage);
 | 
|---|
 | 132 |     makeInterlacedArray(array, a1, 0);
 | 
|---|
 | 133 |     makeInterlacedArray(array, a2, 1);
 | 
|---|
 | 134 |     makeInterlacedArray(array, a3, 2);
 | 
|---|
 | 135 |     makeInterlacedArray(array, a4, 3);
 | 
|---|
 | 136 | }
 | 
|---|
 | 137 | 
 | 
|---|
 | 138 | template<class T_numtype, int N_rank>
 | 
|---|
 | 139 | void interlaceArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 140 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 141 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 142 |     Array<T_numtype,N_rank>& a5)
 | 
|---|
 | 143 | {
 | 
|---|
 | 144 |     GeneralArrayStorage<N_rank+1> storage;
 | 
|---|
 | 145 |     Array<T_numtype, N_rank+1> array(shape, 5, storage);
 | 
|---|
 | 146 |     makeInterlacedArray(array, a1, 0);
 | 
|---|
 | 147 |     makeInterlacedArray(array, a2, 1);
 | 
|---|
 | 148 |     makeInterlacedArray(array, a3, 2);
 | 
|---|
 | 149 |     makeInterlacedArray(array, a4, 3);
 | 
|---|
 | 150 |     makeInterlacedArray(array, a5, 4);
 | 
|---|
 | 151 | }
 | 
|---|
 | 152 | 
 | 
|---|
 | 153 | template<class T_numtype, int N_rank>
 | 
|---|
 | 154 | void interlaceArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 155 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 156 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 157 |     Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6)
 | 
|---|
 | 158 | {
 | 
|---|
 | 159 |     GeneralArrayStorage<N_rank+1> storage;
 | 
|---|
 | 160 |     Array<T_numtype, N_rank+1> array(shape, 6, storage);
 | 
|---|
 | 161 |     makeInterlacedArray(array, a1, 0);
 | 
|---|
 | 162 |     makeInterlacedArray(array, a2, 1);
 | 
|---|
 | 163 |     makeInterlacedArray(array, a3, 2);
 | 
|---|
 | 164 |     makeInterlacedArray(array, a4, 3);
 | 
|---|
 | 165 |     makeInterlacedArray(array, a5, 4);
 | 
|---|
 | 166 |     makeInterlacedArray(array, a6, 5);
 | 
|---|
 | 167 | }
 | 
|---|
 | 168 | 
 | 
|---|
 | 169 | template<class T_numtype, int N_rank>
 | 
|---|
 | 170 | void interlaceArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 171 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 172 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 173 |     Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
 | 
|---|
 | 174 |     Array<T_numtype,N_rank>& a7)
 | 
|---|
 | 175 | {
 | 
|---|
 | 176 |     GeneralArrayStorage<N_rank+1> storage;
 | 
|---|
 | 177 |     Array<T_numtype, N_rank+1> array(shape, 7, storage);
 | 
|---|
 | 178 |     makeInterlacedArray(array, a1, 0);
 | 
|---|
 | 179 |     makeInterlacedArray(array, a2, 1);
 | 
|---|
 | 180 |     makeInterlacedArray(array, a3, 2);
 | 
|---|
 | 181 |     makeInterlacedArray(array, a4, 3);
 | 
|---|
 | 182 |     makeInterlacedArray(array, a5, 4);
 | 
|---|
 | 183 |     makeInterlacedArray(array, a6, 5);
 | 
|---|
 | 184 |     makeInterlacedArray(array, a7, 6);
 | 
|---|
 | 185 | }
 | 
|---|
 | 186 | 
 | 
|---|
 | 187 | template<class T_numtype, int N_rank>
 | 
|---|
 | 188 | void interlaceArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 189 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 190 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 191 |     Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
 | 
|---|
 | 192 |     Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8)
 | 
|---|
 | 193 | {
 | 
|---|
 | 194 |     GeneralArrayStorage<N_rank+1> storage;
 | 
|---|
 | 195 |     Array<T_numtype, N_rank+1> array(shape, 8, storage);
 | 
|---|
 | 196 |     makeInterlacedArray(array, a1, 0);
 | 
|---|
 | 197 |     makeInterlacedArray(array, a2, 1);
 | 
|---|
 | 198 |     makeInterlacedArray(array, a3, 2);
 | 
|---|
 | 199 |     makeInterlacedArray(array, a4, 3);
 | 
|---|
 | 200 |     makeInterlacedArray(array, a5, 4);
 | 
|---|
 | 201 |     makeInterlacedArray(array, a6, 5);
 | 
|---|
 | 202 |     makeInterlacedArray(array, a7, 6);
 | 
|---|
 | 203 |     makeInterlacedArray(array, a8, 7);
 | 
|---|
 | 204 | }
 | 
|---|
 | 205 | 
 | 
|---|
 | 206 | template<class T_numtype, int N_rank>
 | 
|---|
 | 207 | void interlaceArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 208 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 209 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 210 |     Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
 | 
|---|
 | 211 |     Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8,
 | 
|---|
 | 212 |     Array<T_numtype,N_rank>& a9)
 | 
|---|
 | 213 | {
 | 
|---|
 | 214 |     GeneralArrayStorage<N_rank+1> storage;
 | 
|---|
 | 215 |     Array<T_numtype, N_rank+1> array(shape, 9, storage);
 | 
|---|
 | 216 |     makeInterlacedArray(array, a1, 0);
 | 
|---|
 | 217 |     makeInterlacedArray(array, a2, 1);
 | 
|---|
 | 218 |     makeInterlacedArray(array, a3, 2);
 | 
|---|
 | 219 |     makeInterlacedArray(array, a4, 3);
 | 
|---|
 | 220 |     makeInterlacedArray(array, a5, 4);
 | 
|---|
 | 221 |     makeInterlacedArray(array, a6, 5);
 | 
|---|
 | 222 |     makeInterlacedArray(array, a7, 6);
 | 
|---|
 | 223 |     makeInterlacedArray(array, a8, 7);
 | 
|---|
 | 224 |     makeInterlacedArray(array, a9, 8);
 | 
|---|
 | 225 | }
 | 
|---|
 | 226 | 
 | 
|---|
 | 227 | template<class T_numtype, int N_rank>
 | 
|---|
 | 228 | void interlaceArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 229 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 230 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 231 |     Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
 | 
|---|
 | 232 |     Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8,
 | 
|---|
 | 233 |     Array<T_numtype,N_rank>& a9, Array<T_numtype,N_rank>& a10)
 | 
|---|
 | 234 | {
 | 
|---|
 | 235 |     GeneralArrayStorage<N_rank+1> storage;
 | 
|---|
 | 236 |     Array<T_numtype, N_rank+1> array(shape, 10, storage);
 | 
|---|
 | 237 |     makeInterlacedArray(array, a1, 0);
 | 
|---|
 | 238 |     makeInterlacedArray(array, a2, 1);
 | 
|---|
 | 239 |     makeInterlacedArray(array, a3, 2);
 | 
|---|
 | 240 |     makeInterlacedArray(array, a4, 3);
 | 
|---|
 | 241 |     makeInterlacedArray(array, a5, 4);
 | 
|---|
 | 242 |     makeInterlacedArray(array, a6, 5);
 | 
|---|
 | 243 |     makeInterlacedArray(array, a7, 6);
 | 
|---|
 | 244 |     makeInterlacedArray(array, a8, 7);
 | 
|---|
 | 245 |     makeInterlacedArray(array, a9, 8);
 | 
|---|
 | 246 |     makeInterlacedArray(array, a10, 9);
 | 
|---|
 | 247 | }
 | 
|---|
 | 248 | 
 | 
|---|
 | 249 | template<class T_numtype, int N_rank>
 | 
|---|
 | 250 | void interlaceArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 251 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 252 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 253 |     Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
 | 
|---|
 | 254 |     Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8,
 | 
|---|
 | 255 |     Array<T_numtype,N_rank>& a9, Array<T_numtype,N_rank>& a10,
 | 
|---|
 | 256 |     Array<T_numtype,N_rank>& a11)
 | 
|---|
 | 257 | {
 | 
|---|
 | 258 |     GeneralArrayStorage<N_rank+1> storage;
 | 
|---|
 | 259 |     Array<T_numtype, N_rank+1> array(shape, 11, storage);
 | 
|---|
 | 260 |     makeInterlacedArray(array, a1, 0);
 | 
|---|
 | 261 |     makeInterlacedArray(array, a2, 1);
 | 
|---|
 | 262 |     makeInterlacedArray(array, a3, 2);
 | 
|---|
 | 263 |     makeInterlacedArray(array, a4, 3);
 | 
|---|
 | 264 |     makeInterlacedArray(array, a5, 4);
 | 
|---|
 | 265 |     makeInterlacedArray(array, a6, 5);
 | 
|---|
 | 266 |     makeInterlacedArray(array, a7, 6);
 | 
|---|
 | 267 |     makeInterlacedArray(array, a8, 7);
 | 
|---|
 | 268 |     makeInterlacedArray(array, a9, 8);
 | 
|---|
 | 269 |     makeInterlacedArray(array, a10, 9);
 | 
|---|
 | 270 |     makeInterlacedArray(array, a11, 10);
 | 
|---|
 | 271 | }
 | 
|---|
 | 272 | 
 | 
|---|
 | 273 | // NEEDS_WORK -- make `storage' a parameter in these routines
 | 
|---|
 | 274 | //  Will be tricky: have to convert GeneralArrayStorage<N_rank> to
 | 
|---|
 | 275 | //  GeneralArrayStorage<N_rank+1>
 | 
|---|
 | 276 | 
 | 
|---|
 | 277 | // These routines may or may not interlace arrays, depending on
 | 
|---|
 | 278 | // whether it is advantageous for this platform.
 | 
|---|
 | 279 | 
 | 
|---|
 | 280 | template<class T_numtype, int N_rank>
 | 
|---|
 | 281 | void allocateArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 282 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2)
 | 
|---|
 | 283 | {
 | 
|---|
 | 284 | #ifdef BZ_INTERLACE_ARRAYS
 | 
|---|
 | 285 |     interlaceArrays(shape, a1, a2);
 | 
|---|
 | 286 | #else
 | 
|---|
 | 287 |     a1.resize(shape);
 | 
|---|
 | 288 |     a2.resize(shape);
 | 
|---|
 | 289 | #endif
 | 
|---|
 | 290 | }
 | 
|---|
 | 291 | 
 | 
|---|
 | 292 | template<class T_numtype, int N_rank>
 | 
|---|
 | 293 | void allocateArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 294 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 295 |     Array<T_numtype,N_rank>& a3)
 | 
|---|
 | 296 | {
 | 
|---|
 | 297 | #ifdef BZ_INTERLACE_ARRAYS
 | 
|---|
 | 298 |     interlaceArrays(shape, a1, a2, a3);
 | 
|---|
 | 299 | #else
 | 
|---|
 | 300 |     a1.resize(shape);
 | 
|---|
 | 301 |     a2.resize(shape);
 | 
|---|
 | 302 |     a3.resize(shape);
 | 
|---|
 | 303 | #endif
 | 
|---|
 | 304 | }
 | 
|---|
 | 305 | 
 | 
|---|
 | 306 | template<class T_numtype, int N_rank>
 | 
|---|
 | 307 | void allocateArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 308 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 309 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4)
 | 
|---|
 | 310 | {
 | 
|---|
 | 311 | #ifdef BZ_INTERLACE_ARRAYS
 | 
|---|
 | 312 |     interlaceArrays(shape, a1, a2, a3, a4);
 | 
|---|
 | 313 | #else
 | 
|---|
 | 314 |     a1.resize(shape);
 | 
|---|
 | 315 |     a2.resize(shape);
 | 
|---|
 | 316 |     a3.resize(shape);
 | 
|---|
 | 317 |     a4.resize(shape);
 | 
|---|
 | 318 | #endif
 | 
|---|
 | 319 | }
 | 
|---|
 | 320 | 
 | 
|---|
 | 321 | template<class T_numtype, int N_rank>
 | 
|---|
 | 322 | void allocateArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 323 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 324 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 325 |     Array<T_numtype,N_rank>& a5)
 | 
|---|
 | 326 | {
 | 
|---|
 | 327 | #ifdef BZ_INTERLACE_ARRAYS
 | 
|---|
 | 328 |     interlaceArrays(shape, a1, a2, a3, a4, a5);
 | 
|---|
 | 329 | #else
 | 
|---|
 | 330 |     a1.resize(shape);
 | 
|---|
 | 331 |     a2.resize(shape);
 | 
|---|
 | 332 |     a3.resize(shape);
 | 
|---|
 | 333 |     a4.resize(shape);
 | 
|---|
 | 334 |     a5.resize(shape);
 | 
|---|
 | 335 | #endif
 | 
|---|
 | 336 | }
 | 
|---|
 | 337 | 
 | 
|---|
 | 338 | template<class T_numtype, int N_rank>
 | 
|---|
 | 339 | void allocateArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 340 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 341 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 342 |     Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6)
 | 
|---|
 | 343 | {
 | 
|---|
 | 344 | #ifdef BZ_INTERLACE_ARRAYS
 | 
|---|
 | 345 |     interlaceArrays(shape, a1, a2, a3, a4, a5, a6);
 | 
|---|
 | 346 | #else
 | 
|---|
 | 347 |     a1.resize(shape);
 | 
|---|
 | 348 |     a2.resize(shape);
 | 
|---|
 | 349 |     a3.resize(shape);
 | 
|---|
 | 350 |     a4.resize(shape);
 | 
|---|
 | 351 |     a5.resize(shape);
 | 
|---|
 | 352 |     a6.resize(shape);
 | 
|---|
 | 353 | #endif
 | 
|---|
 | 354 | }
 | 
|---|
 | 355 | 
 | 
|---|
 | 356 | template<class T_numtype, int N_rank>
 | 
|---|
 | 357 | void allocateArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 358 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 359 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 360 |     Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
 | 
|---|
 | 361 |     Array<T_numtype,N_rank>& a7)
 | 
|---|
 | 362 | {
 | 
|---|
 | 363 | #ifdef BZ_INTERLACE_ARRAYS
 | 
|---|
 | 364 |     interlaceArrays(shape, a1, a2, a3, a4, a5, a6, a7);
 | 
|---|
 | 365 | #else
 | 
|---|
 | 366 |     a1.resize(shape);
 | 
|---|
 | 367 |     a2.resize(shape);
 | 
|---|
 | 368 |     a3.resize(shape);
 | 
|---|
 | 369 |     a4.resize(shape);
 | 
|---|
 | 370 |     a5.resize(shape);
 | 
|---|
 | 371 |     a6.resize(shape);
 | 
|---|
 | 372 |     a7.resize(shape);
 | 
|---|
 | 373 | #endif
 | 
|---|
 | 374 | }
 | 
|---|
 | 375 | 
 | 
|---|
 | 376 | template<class T_numtype, int N_rank>
 | 
|---|
 | 377 | void allocateArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 378 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 379 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 380 |     Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
 | 
|---|
 | 381 |     Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8)
 | 
|---|
 | 382 | {
 | 
|---|
 | 383 | #ifdef BZ_INTERLACE_ARRAYS
 | 
|---|
 | 384 |     interlaceArrays(shape, a1, a2, a3, a4, a5, a6, a7, a8);
 | 
|---|
 | 385 | #else
 | 
|---|
 | 386 |     a1.resize(shape);
 | 
|---|
 | 387 |     a2.resize(shape);
 | 
|---|
 | 388 |     a3.resize(shape);
 | 
|---|
 | 389 |     a4.resize(shape);
 | 
|---|
 | 390 |     a5.resize(shape);
 | 
|---|
 | 391 |     a6.resize(shape);
 | 
|---|
 | 392 |     a7.resize(shape);
 | 
|---|
 | 393 |     a8.resize(shape);
 | 
|---|
 | 394 | #endif
 | 
|---|
 | 395 | }
 | 
|---|
 | 396 | 
 | 
|---|
 | 397 | template<class T_numtype, int N_rank>
 | 
|---|
 | 398 | void allocateArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 399 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 400 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 401 |     Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
 | 
|---|
 | 402 |     Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8,
 | 
|---|
 | 403 |     Array<T_numtype,N_rank>& a9)
 | 
|---|
 | 404 | {
 | 
|---|
 | 405 | #ifdef BZ_INTERLACE_ARRAYS
 | 
|---|
 | 406 |     interlaceArrays(shape, a1, a2, a3, a4, a5, a6, a7, a8, a9);
 | 
|---|
 | 407 | #else
 | 
|---|
 | 408 |     a1.resize(shape);
 | 
|---|
 | 409 |     a2.resize(shape);
 | 
|---|
 | 410 |     a3.resize(shape);
 | 
|---|
 | 411 |     a4.resize(shape);
 | 
|---|
 | 412 |     a5.resize(shape);
 | 
|---|
 | 413 |     a6.resize(shape);
 | 
|---|
 | 414 |     a7.resize(shape);
 | 
|---|
 | 415 |     a8.resize(shape);
 | 
|---|
 | 416 |     a9.resize(shape);
 | 
|---|
 | 417 | #endif
 | 
|---|
 | 418 | }
 | 
|---|
 | 419 | 
 | 
|---|
 | 420 | template<class T_numtype, int N_rank>
 | 
|---|
 | 421 | void allocateArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 422 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 423 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 424 |     Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
 | 
|---|
 | 425 |     Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8,
 | 
|---|
 | 426 |     Array<T_numtype,N_rank>& a9, Array<T_numtype,N_rank>& a10)
 | 
|---|
 | 427 | {
 | 
|---|
 | 428 | #ifdef BZ_INTERLACE_ARRAYS
 | 
|---|
 | 429 |     interlaceArrays(shape, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
 | 
|---|
 | 430 | #else
 | 
|---|
 | 431 |     a1.resize(shape);
 | 
|---|
 | 432 |     a2.resize(shape);
 | 
|---|
 | 433 |     a3.resize(shape);
 | 
|---|
 | 434 |     a4.resize(shape);
 | 
|---|
 | 435 |     a5.resize(shape);
 | 
|---|
 | 436 |     a6.resize(shape);
 | 
|---|
 | 437 |     a7.resize(shape);
 | 
|---|
 | 438 |     a8.resize(shape);
 | 
|---|
 | 439 |     a9.resize(shape);
 | 
|---|
 | 440 |     a10.resize(shape);
 | 
|---|
 | 441 | #endif
 | 
|---|
 | 442 | }
 | 
|---|
 | 443 | 
 | 
|---|
 | 444 | template<class T_numtype, int N_rank>
 | 
|---|
 | 445 | void allocateArrays(const TinyVector<int,N_rank>& shape,
 | 
|---|
 | 446 |     Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
 | 
|---|
 | 447 |     Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
 | 
|---|
 | 448 |     Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
 | 
|---|
 | 449 |     Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8,
 | 
|---|
 | 450 |     Array<T_numtype,N_rank>& a9, Array<T_numtype,N_rank>& a10,
 | 
|---|
 | 451 |     Array<T_numtype,N_rank>& a11)
 | 
|---|
 | 452 | {
 | 
|---|
 | 453 | #ifdef BZ_INTERLACE_ARRAYS
 | 
|---|
 | 454 |     interlaceArrays(shape, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
 | 
|---|
 | 455 | #else
 | 
|---|
 | 456 |     a1.resize(shape);
 | 
|---|
 | 457 |     a2.resize(shape);
 | 
|---|
 | 458 |     a3.resize(shape);
 | 
|---|
 | 459 |     a4.resize(shape);
 | 
|---|
 | 460 |     a5.resize(shape);
 | 
|---|
 | 461 |     a6.resize(shape);
 | 
|---|
 | 462 |     a7.resize(shape);
 | 
|---|
 | 463 |     a8.resize(shape);
 | 
|---|
 | 464 |     a9.resize(shape);
 | 
|---|
 | 465 |     a10.resize(shape);
 | 
|---|
 | 466 |     a11.resize(shape);
 | 
|---|
 | 467 | #endif
 | 
|---|
 | 468 | }
 | 
|---|
 | 469 | 
 | 
|---|
 | 470 | // NEEDS_WORK -- allocateArrays for TinyVector<Range,N_rank>
 | 
|---|
 | 471 | 
 | 
|---|
 | 472 | // This constructor is used to create interlaced arrays.
 | 
|---|
 | 473 | template<class T_numtype, int N_rank>
 | 
|---|
 | 474 | Array<T_numtype,N_rank>::Array(const TinyVector<int,N_rank-1>& shape,
 | 
|---|
 | 475 |     int lastExtent, const GeneralArrayStorage<N_rank>& storage)
 | 
|---|
 | 476 |     : storage_(storage)
 | 
|---|
 | 477 | {
 | 
|---|
 | 478 |     // Create an array with the given shape, plus an extra dimension
 | 
|---|
 | 479 |     // for the number of arrays being allocated.  This extra dimension
 | 
|---|
 | 480 |     // must have minor storage order.
 | 
|---|
 | 481 | 
 | 
|---|
 | 482 |     if (ordering(0) == 0)
 | 
|---|
 | 483 |     {
 | 
|---|
 | 484 |         // Column major storage order (or something like it)
 | 
|---|
 | 485 |         length_[0] = lastExtent;
 | 
|---|
 | 486 |         storage_.setBase(0,0);
 | 
|---|
 | 487 |         for (int i=1; i < N_rank; ++i)
 | 
|---|
 | 488 |             length_[i] = shape[i-1];
 | 
|---|
 | 489 |     }
 | 
|---|
 | 490 |     else if (ordering(0) == N_rank-1)
 | 
|---|
 | 491 |     {
 | 
|---|
 | 492 |         // Row major storage order (or something like it)
 | 
|---|
 | 493 |         for (int i=0; i < N_rank-1; ++i)
 | 
|---|
 | 494 |             length_[i] = shape[i];
 | 
|---|
 | 495 |         length_[N_rank-1] = lastExtent;
 | 
|---|
 | 496 |         storage_.setBase(N_rank-1, 0);
 | 
|---|
 | 497 |     }
 | 
|---|
 | 498 |     else {
 | 
|---|
 | 499 |         BZPRECHECK(0, "Used allocateArrays() with a peculiar storage format");
 | 
|---|
 | 500 |     }
 | 
|---|
 | 501 | 
 | 
|---|
 | 502 |     setupStorage(N_rank-1);
 | 
|---|
 | 503 | }
 | 
|---|
 | 504 | 
 | 
|---|
 | 505 | // NEEDS_WORK -- see note about TinyVector<Range,N> in <blitz/arrayshape.h>
 | 
|---|
 | 506 | #if 0
 | 
|---|
 | 507 | template<class T_numtype, int N_rank>
 | 
|---|
 | 508 | Array<T_numtype,N_rank>::Array(const TinyVector<Range,N_rank-1>& shape,
 | 
|---|
 | 509 |     int lastExtent, const GeneralArrayStorage<N_rank>& storage)
 | 
|---|
 | 510 |     : storage_(storage)
 | 
|---|
 | 511 | {
 | 
|---|
 | 512 | #ifdef BZ_DEBUG
 | 
|---|
 | 513 |     for (int i=0; i < N_rank; ++i)
 | 
|---|
 | 514 |       BZPRECHECK(shape[i].isAscendingContiguous(),
 | 
|---|
 | 515 |         "In call to allocateArrays(), a Range object is not ascending" << endl
 | 
|---|
 | 516 |         << "contiguous: " << shape[i] << endl);
 | 
|---|
 | 517 | #endif
 | 
|---|
 | 518 | 
 | 
|---|
 | 519 |     if (ordering(0) == 0)
 | 
|---|
 | 520 |     {
 | 
|---|
 | 521 |         // Column major storage order (or something like it)
 | 
|---|
 | 522 |         length_[0] = lastExtent;
 | 
|---|
 | 523 |         storage_.setBase(0,0);
 | 
|---|
 | 524 |         for (int i=1; i < N_rank; ++i)
 | 
|---|
 | 525 |         {
 | 
|---|
 | 526 |             length_[i] = shape[i-1].length();
 | 
|---|
 | 527 |             storage_.setBase(i, shape[i-1].first());
 | 
|---|
 | 528 |         }
 | 
|---|
 | 529 |     }
 | 
|---|
 | 530 |     else if (ordering(0) == N_rank-1)
 | 
|---|
 | 531 |     {
 | 
|---|
 | 532 |         // Row major storage order (or something like it)
 | 
|---|
 | 533 |         for (int i=0; i < N_rank-1; ++i)
 | 
|---|
 | 534 |         {
 | 
|---|
 | 535 |             length_[i] = shape[i];
 | 
|---|
 | 536 |             storage_.setBase(i, shape[i].first());
 | 
|---|
 | 537 |         }
 | 
|---|
 | 538 |         length_[N_rank-1] = lastExtent;
 | 
|---|
 | 539 |         storage_.setBase(N_rank-1, 0);
 | 
|---|
 | 540 |     }
 | 
|---|
 | 541 |     else {
 | 
|---|
 | 542 |         BZPRECHECK(0, "Used allocateArrays() with a peculiar storage format");
 | 
|---|
 | 543 |     }
 | 
|---|
 | 544 | 
 | 
|---|
 | 545 |     setupStorage(N_rank-1);
 | 
|---|
 | 546 | }
 | 
|---|
 | 547 | #endif
 | 
|---|
 | 548 | 
 | 
|---|
 | 549 | BZ_NAMESPACE_END
 | 
|---|
 | 550 | 
 | 
|---|
 | 551 | #endif // BZ_ARRAYINTER_CC
 | 
|---|
 | 552 | 
 | 
|---|