From: Paul H. <pph...@gm...> - 2011-08-12 08:23:25
|
Dear all, Right now I have the following code part in my code, which roughly looks like this In the class header : ******* Array2d SendXl, SendXu, SendYl, SendYu, SendYu, .... Array2d SendXl, SendXu, SendYl, SendYu, SendYu, .... ****** In the class definition I need to call resize for all of them SendXl.resize(RxLD, RyLD, RzLD, RvLD, RmLD, RsLD); SendXu.resize(RxLD, RyLD, RzLD, RvLD, RmLD, RsLD); ****** Is there a better way to do that without always writing the whole resize ? I came up with the following function, which looks like template<typename T0,typename T1,typename T2,typename T3,typename T4,typename T5,typename T6,typename T7,typename T8> bool allocate(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, Array<T0,6>& A0,Array<T1,6>& A1,Array<T2,6>& A2,Array<T3,6>& A3,Array<T4,6>& A4,Array<T5,6>& A5,Array<T6,6>& A6,Array<T7,6>& A7,Array<T8,6>& A8, bool setZero=true) { A0.resize(r0,r1,r2,r3,r4,r5); if(setZero) A0=0; A1.resize(r0,r1,r2,r3,r4,r5); if(setZero) A1=0; A2.resize(r0,r1,r2,r3,r4,r5); if(setZero) A2=0; A3.resize(r0,r1,r2,r3,r4,r5); if(setZero) A3=0; A4.resize(r0,r1,r2,r3,r4,r5); if(setZero) A4=0; A5.resize(r0,r1,r2,r3,r4,r5); if(setZero) A5=0; A6.resize(r0,r1,r2,r3,r4,r5); if(setZero) A6=0; A7.resize(r0,r1,r2,r3,r4,r5); if(setZero) A7=0; A8.resize(r0,r1,r2,r3,r4,r5); if(setZero) A8=0; } thus now I can write allocate(RxLD, RyLD, RzLD, RvLD, RmLD, RsLD, SendXl, SendXu, SendYl, SendYu, ....) Image having e.g many 2d arrays with same size as is usual case in numerical simulations, we can now write allocate(RxLD, RyLD, A2, B2, C2, D2, C2 ) and so on. I wrote a python script creating a file called allocate.h with all up to 10 Arrays with up to 7th dimension. The file itself is just 800 lines. I would like to upload this file, header + python script, to the blitz repository (e.g. either as allocate.h or something more appropriate, need to think) in case there is no better alternative as it seems to be pretty handy. Any concerns ? best wishes, Paul |