Mercurial > hg > jslab
comparison src/samer/units/Stacker.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bf79fb79ee13 |
---|---|
1 /* | |
2 * Copyright (c) 2000, Samer Abdallah, King's College London. | |
3 * All rights reserved. | |
4 * | |
5 * This software is provided AS iS and WITHOUT ANY WARRANTY; | |
6 * without even the implied warranty of MERCHANTABILITY or | |
7 * FITNESS FOR A PARTICULAR PURPOSE. | |
8 */ | |
9 | |
10 package samer.units; | |
11 import samer.core.*; | |
12 import samer.maths.*; | |
13 import samer.tools.*; | |
14 | |
15 /* | |
16 * Takes successive input vectors and stacks them into | |
17 * one big output vector. Requires a task which it will | |
18 * run to obtain each input vector. | |
19 */ | |
20 | |
21 public class Stacker implements Task | |
22 { | |
23 Node node; | |
24 Task nextvec; | |
25 Vec srcvec; | |
26 int size, step; | |
27 VVector target; | |
28 double [] a, b; | |
29 int k0, k1, k2; | |
30 | |
31 public Stacker(Vec v, Task t, int size, int step) { this(v,t,size,step,v.size()); } | |
32 public Stacker(Vec v, Task t, int size, int step, int height) | |
33 { | |
34 node = new Node("stacker"); | |
35 | |
36 Shell.push(node); | |
37 srcvec=v; nextvec=t; | |
38 this.size = size; | |
39 this.step = step; | |
40 | |
41 k0=height; | |
42 k1=step*k0; | |
43 k2=(size-step)*k0; | |
44 | |
45 target = new VVector("output",k0*size); | |
46 a = target.array(); | |
47 b = srcvec.array(); | |
48 Mathx.zero(a); | |
49 | |
50 Shell.pop(); | |
51 } | |
52 | |
53 public void dispose() { | |
54 nextvec.dispose(); | |
55 target.dispose(); | |
56 a=b=null; | |
57 } | |
58 | |
59 public VVector output() { return target; } | |
60 | |
61 public void starting() { nextvec.starting(); } | |
62 public void stopping() { nextvec.stopping(); } | |
63 public void run() throws Exception | |
64 { | |
65 // make some room in packed matrix | |
66 System.arraycopy(a,k1,a,0,k2); | |
67 | |
68 for (int i=0, j=k2; i<step; i++) { | |
69 nextvec.run(); | |
70 // copy vec into packed matrix | |
71 System.arraycopy(b,0,a,j,k0); | |
72 j+=k0; | |
73 } | |
74 target.changed(); | |
75 } | |
76 } |