private void DoTestSetTrueCount(AbstractSparseBinaryMatrix sm) { int[][] connectedSynapses = new int[][] { new int[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, new int[] { 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 }, new int[] { 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 }, new int[] { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 }, new int[] { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } }; for (int i = 0; i < sm.GetDimensions()[0]; i++) { for (int j = 0; j < sm.GetDimensions()[1]; j++) { sm.Set(connectedSynapses[i][j], i, j); } } for (int i = 0; i < 5; i++) { for (int j = 0; j < 10; j++) { Assert.AreEqual(connectedSynapses[i][j], sm.GetIntValue(i, j)); } } for (int i = 0; i < 5; i++) { Assert.AreEqual(2, sm.GetTrueCount(i)); } }
private void DoTestBackingStoreAndSliceAccess(AbstractSparseBinaryMatrix sm) { int[][] connectedSynapses = new int[][] { new int[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, new int[] { 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 }, new int[] { 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 }, new int[] { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 }, new int[] { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } }; for (int i = 0; i < sm.GetDimensions()[0]; i++) { for (int j = 0; j < sm.GetDimensions()[1]; j++) { sm.Set(connectedSynapses[i][j], i, j); } } for (int i = 0; i < 5; i++) { for (int j = 0; j < 10; j++) { Assert.AreEqual(connectedSynapses[i][j], sm.GetIntValue(i, j)); } } for (int i = 0; i < connectedSynapses.Length; i++) { for (int j = 0; j < connectedSynapses[i].Length; j++) { Assert.AreEqual(connectedSynapses[i][j], ((SparseByteArray)sm.GetSlice(i))[j], 0); } } //Make sure warning is proper for exact access try { sm.GetSlice(0, 4); Assert.Fail(); } catch (Exception e) { Assert.AreEqual("This method only returns the array holding the specified index: " + Arrays.ToString(new int[] { 0, 4 }), e.Message); } }
private void DoTestRightVecSumAtNzFast(AbstractSparseBinaryMatrix sm) { int[] dimensions = new int[] { 5, 10 }; int[][] connectedSynapses = new int[][] { new int[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, new int[] { 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 }, new int[] { 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 }, new int[] { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 }, new int[] { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } }; for (int i = 0; i < sm.GetDimensions()[0]; i++) { for (int j = 0; j < sm.GetDimensions()[1]; j++) { sm.Set(connectedSynapses[i][j], i, j); } } for (int i = 0; i < 5; i++) { for (int j = 0; j < 10; j++) { Assert.AreEqual(connectedSynapses[i][j], sm.GetIntValue(i, j)); } } int[] inputVector = new int[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }; int[] results = new int[5]; int[] trueResults = new int[] { 1, 1, 1, 1, 1 }; sm.RightVecSumAtNZ(inputVector, results); for (int i = 0; i < results.Length; i++) { Assert.AreEqual(trueResults[i], results[i]); } /////////////////////// connectedSynapses = new int[][] { new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, new int[] { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 }, new int[] { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 }, new int[] { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 }, new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 } }; sm = new SparseBinaryMatrix(dimensions); for (int i = 0; i < sm.GetDimensions()[0]; i++) { for (int j = 0; j < sm.GetDimensions()[1]; j++) { sm.Set(connectedSynapses[i][j], i, j); } } for (int i = 0; i < 5; i++) { for (int j = 0; j < 10; j++) { Assert.AreEqual(connectedSynapses[i][j], sm.GetIntValue(i, j)); } } inputVector = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; results = new int[5]; trueResults = new int[] { 10, 8, 6, 4, 2 }; sm.RightVecSumAtNZ(inputVector, results); for (int i = 0; i < results.Length; i++) { Assert.AreEqual(trueResults[i], results[i]); } }