From 78f823f31e74323f10d5fc6a0618e42d1d2d04d7 Mon Sep 17 00:00:00 2001 From: Tal Moran Date: Thu, 19 Jan 2017 01:18:21 +0200 Subject: [PATCH] new benes code passes tests --- .../src/main/java/meerkat/mixer/mixing/BenesNetwork.java | 8 ++++---- .../test/java/meerkat/mixer/mixing/BenesNetworkTest.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mixer/src/main/java/meerkat/mixer/mixing/BenesNetwork.java b/mixer/src/main/java/meerkat/mixer/mixing/BenesNetwork.java index 10cc45e..fc0e37a 100644 --- a/mixer/src/main/java/meerkat/mixer/mixing/BenesNetwork.java +++ b/mixer/src/main/java/meerkat/mixer/mixing/BenesNetwork.java @@ -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; } diff --git a/mixer/src/test/java/meerkat/mixer/mixing/BenesNetworkTest.java b/mixer/src/test/java/meerkat/mixer/mixing/BenesNetworkTest.java index 7a64f58..3114e9e 100644 --- a/mixer/src/test/java/meerkat/mixer/mixing/BenesNetworkTest.java +++ b/mixer/src/test/java/meerkat/mixer/mixing/BenesNetworkTest.java @@ -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() {