new benes code passes tests
parent
37d1857f9c
commit
78f823f31e
|
@ -40,7 +40,7 @@ public class BenesNetwork implements PermutationNetwork
|
|||
*/
|
||||
public static int getOutputIdxInPreviousLayer(int logN, int layer, int inputIdx) {
|
||||
assert (layer >= 0) && (layer < 2*logN - 1);
|
||||
assert (inputIdx >= 0) && (inputIdx < 1 << inputIdx);
|
||||
assert (inputIdx >= 0) && (inputIdx < 1 << logN);
|
||||
|
||||
if ((layer == 0) || (inputIdx & 1) == 0) {
|
||||
// layer 0 inputs and all even inputs
|
||||
|
@ -145,7 +145,7 @@ public class BenesNetwork implements PermutationNetwork
|
|||
/**
|
||||
* Where the set of switches for this level and index actually starts in switchValues
|
||||
*/
|
||||
int blockStart = idx << level;
|
||||
int blockStart = idx << (logN - level - 1);
|
||||
int numSwitches = 1 << (logN - level - 1);
|
||||
|
||||
while (!unmatchedIndices.isEmpty()) {
|
||||
|
@ -189,11 +189,11 @@ public class BenesNetwork implements PermutationNetwork
|
|||
if ((((j & 1) == 0) && (jSwitchNum < numSwitches / 2)) || ((j & 1) == 1) && (jSwitchNum >= numSwitches / 2)) {
|
||||
// Even output in the upper half, or odd output in the lower half
|
||||
// so switch needs to be "straight" to get j to the upper half
|
||||
switchValues[level][blockStart + switchNum] = false;
|
||||
switchValues[level][blockStart + jSwitchNum] = false;
|
||||
jSwitched = j;
|
||||
} else {
|
||||
// Otherwise switch needs to be "crossed" to get j to upper half
|
||||
switchValues[level][blockStart + switchNum] = true;
|
||||
switchValues[level][blockStart + jSwitchNum] = true;
|
||||
jSwitched = j ^ 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import static org.junit.Assert.*;
|
|||
* Tests for Benes Network topology
|
||||
*/
|
||||
public class BenesNetworkTest extends PermutationNetworkTest {
|
||||
final static int logN = 3;
|
||||
final static int logN = 8;
|
||||
|
||||
@Override
|
||||
protected PermutationNetwork getNewNetwork() {
|
||||
|
|
Loading…
Reference in New Issue