Exemplo n.º 1
0
        public void TestUtilSparseMatrix_Vecsum()
        {
            SparseBinaryMatrix matrix1 = new SparseBinaryMatrix(new[] { 1024, 1024 });

            // fill half the matrix
            for (int i = 0; i < 1024; i++)
            {
                for (int j = 0; j < 512; j += 2)
                {
                    matrix1.Set(1, i, j);
                }
            }

            int[] inputVec = new int[1024]; // all zero
            int[] results  = new int[1024];
            matrix1.RightVecSumAtNZ(inputVec, results, 0);

            inputVec = new int[1024]; // some zero
            for (int j = 0; j < 512; j += 2)
            {
                inputVec[j] = 1;
            }
            results = new int[1024];
            matrix1.RightVecSumAtNZ(inputVec, results, 0);
        }
Exemplo n.º 2
0
        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]);
            }
        }